UNPKG

3.32 kBMarkdownView Raw
1typescript-compiler
2===================
3
4Typescript compiler wrapper. Exposes the TypeScript command line compiler to your code.
5
6Usage
7-----------------------
8
9Require the compiler...
10
11 var tsc = require('typescript-compiler');
12
13call it!
14
15 compile(['a.ts', 'b.ts'], ['--out', 'out.js'])
16
17## Module Interface
18
19### libdPath
20
21The path of `lib.d.ts`
22
23### TypeScript
24
25The `TypeScript` class as defined by TypeScript
26
27### IO
28
29The `IO` class as defined by TypeScript
30
31### BatchCompiler
32
33The `BatchCompiler` class as defined by TypeScript
34
35### compile(files, tscArgs, onError)
36
37#### Arguments
38
39##### files
40
41**required** - Type: `array`
42
43A list of files to be compiled.
44
45##### tscArgs
46
47**optional** - Type: `string` or `array` - Default: `[]`
48
49Arguments to be passed to the compiler
50
51- `string`
52 An string containing the arguments as you would use on the terminal but **without the files** to compile.
53 E.g. `"--target ES5"`
54- `array`
55 Each item in the array is a "word" in the command line. Options which receive parameters
56 are split into two elements, i.e., to pass `--target ES5` you need to pass to `compile` an array like this:
57 `['--target', 'ES5']`.
58
59
60Check the options for the current version:
61
62```
63Version 0.9.1.1
64Syntax: tsc [options] [file ..]
65
66Examples: tsc hello.ts
67 tsc --out foo.js foo.ts
68 tsc @args.txt
69
70Options:
71 --allowbool Allow 'bool' as a synonym for 'boolean'.
72 --allowimportmodule Allow 'module(...)' as a synonym for 'require(...)'.
73 -d, --declaration Generates corresponding .d.ts file
74 -h, --help Print this message
75 --mapRoot LOCATION Specifies the location where debugger should locate map files instead of generated locations.
76 -m KIND, --module KIND Specify module code generation: "commonjs" or "amd"
77 --noImplicitAny Warn on expressions and declarations with an implied 'any' type.
78 --noResolve Skip resolution and preprocessing
79 --out FILE Concatenate and emit output to single file.
80 --outDir DIRECTORY Redirect output structure to the directory
81 --removeComments Do not emit comments to output
82 --sourcemap Generates corresponding .map file
83 --sourceRoot LOCATION Specifies the location where debugger should locate TypeScript files instead of source locations.
84 -t VERSION, --target VERSION Specify ECMAScript target version: "ES3" (default), or "ES5"
85 -v, --version Print the compiler's version: 0.9.1.1
86 -w, --watch Watch input files
87 @<file> Insert command line options and files from a file.
88```
89
90##### onError
91
92**optional** - Type: `function(error: string) : bool` - Default: `io.stderr.WriteLine`
93
94A simple callback function which will be called whenever an error is sent through `io.stderr.WriteLine` with the error message which was sent.
95
96Return `false` to prevent the default error callback (`io.stderr.WriteLine`) to writing to the stderr output.
97
98
99
100### Example
101
102 tsc.compile(['a.ts', 'b.ts'], "--out out.js");
103
104
105Credits
106==========
107
108Initial code created by [iano](https://npmjs.org/~iano)
109which was inspired by [typescript-wrapper](https://npmjs.org/package/typescript-wrapper)