microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.34k stars 12.54k forks source link

npm typescript-cli wanted #3439

Closed evil-shrike closed 9 years ago

evil-shrike commented 9 years ago

Hi. I've seen in most examples that typescript npm-package is considered to be installed globally and we can just run tsc. That's nice but I'd like to keep more safe approach and install the typescript package locally (on project level). But in such a case I'll lose tcs command availability. I'd suggest to use Grunt's approach - to have two packages typescript (with compiler and node API) and typescript-cli (with CLI tools). typescript will be installed locally and typescript-cli will be installed globally. typescript-cli would provide tsc command which would look for a local typescript first and run it via its api (require).

Then we could have:

/global/
  /typescript-1.5beta
  /typescipt-cli
/project1/
  /typescript-1.4
/project2/

running tcs in project1 will run ts-1.4 (local), in project2 - ts-1.5b (global).

What do you think?

ivogabe commented 9 years ago

You can use npm scripts for that, it'll use the locally installed version of TypeScript.

evil-shrike commented 9 years ago

@ivogabe thanks! It's a nice article and elegant solution. The only problem that tsc doesn't support globing/wildcards:

  "scripts": {
    "ts": "tsc --module amd --sourceMap src/lib/*.ts"
  },

so I have to collect files on my own:

    "ts": "dir src\\*.ts /b /s > ts-files.txt && tsc --module amd --sourceMap @ts-files.txt"