UNPKG

3.8 kBMarkdownView Raw
1# ts-compiler
2
3> TypeScript compilation via the [typescript-api][].
4
5This version is compatable with TypeScript 0.9.5.
6
7[![Build Status][]](http://travis-ci.org/jedmao/ts-compiler)
8[![Dependency Status][]](https://gemnasium.com/jedmao/ts-compiler)
9[![NPM version][]](http://badge.fury.io/js/ts-compiler)
10[![Views][]](https://sourcegraph.com/github.com/jedmao/ts-compiler)
11
12[![NPM][]](https://nodei.co/npm/ts-compiler/)
13
14
15## TypeScript Usage
16
17```ts
18/// <reference path="node_modules/ts-compiler/ts-compiler.d.ts" />
19import ts = require('ts-compiler');
20
21ts.compile(
22 ['foo.ts', 'bar.ts'],
23 { skipWrite: true },
24 (err: Error, results: ts.OutputFile[]) => {
25
26 var foo = results[0];
27 console.log(foo.text);
28
29 var bar = results[1];
30 console.log(bar.text);
31 });
32```
33
34
35## JavaScript Usage
36
37```js
38var ts = require('ts-compiler');
39
40ts.compile(
41 ['foo.ts', 'bar.ts'],
42 { skipWrite: true },
43 function(err, results) {
44
45 var foo = results[0];
46 console.log(foo.text);
47
48 var bar = results[1];
49 console.log(bar.text);
50});
51```
52
53
54## Module API
55
56
57### ts.compile(files: string[], options?: ICompilerOptions, callback?: Function)
58
59- This is a shorthand way to call `new ts.BatchCompiler.compile(...)`
60- Callback signature is err: Error, results: [ts.OutputFile](#tsoutputfile) Array.
61- The options follow the [ICompilerOptions interface](#tsicompileroptions).
62
63
64### ts.OutputFile
65
66- name: string
67- writeByteOrderMark: boolean
68- text: string
69- fileType: (0: JavaScript, 1: SourceMap, 2: Declaration)
70- sourceMapEntries: SourceMapEntry[]
71
72
73### ts.ICompilerOptions
74
75Though all natively supported TypeScript compiler options will be passed through to the real compiler, it might not always make sense from an API standpoint. Use with common sense.
76
77
78#### options.declaration
79- Type: `Boolean`
80- Default: `false`
81
82Generates corresponding .d.ts file.
83
84#### options.mapRoot
85- Type: `String`
86
87Specifies the location where debugger should locate map files instead of generated locations.
88
89#### options.module
90- Type: `String`
91
92Specify module code generation: `commonjs` or `amd`
93
94#### options.noImplicitAny
95- Type: `Boolean`
96- Default: `false`
97
98Warn on expressions and declarations with an implied `any` type.
99
100#### options.noResolve
101- Type: `Boolean`
102- Default: `false`
103
104Skip resolution and preprocessing.
105
106#### options.out
107- Type: `String`
108
109Concatenate and emit output to single file.
110
111#### options.outDir
112- Type: `String`
113
114Redirect output structure to the directory.
115
116#### options.removeComments
117- Type: `Boolean`
118- Default: `false`
119
120Do not emit comments to output.
121
122#### options.sourcemap
123- Type: `Boolean`
124- Default: `false`
125
126Generates corresponding .map file.
127
128#### options.sourceRoot
129- Type: `String`
130
131Specifies the location where debugger should locate TypeScript files instead of source locations.
132
133#### options.target
134- Type: `String`
135- Default: `ES3`
136
137Specify ECMAScript target version: 'ES3' or 'ES5'
138
139#### options.optionsFile
140- Type: `String`
141
142Insert command line options and files from a file. This is natively supported by the tsc command, but as a different @file key.
143
144#### skipWrite
145- Type: `Boolean`
146- Default: `false`
147
148Skips writing the output files. This flag is unique to ts-compiler.
149
150
151## License
152
153Released under the MIT license.
154
155[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/jedmao/ts-compiler/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
156
157
158[typescript-api]: https://github.com/jedmao/typescript-api
159[Build Status]: https://secure.travis-ci.org/jedmao/ts-compiler.png?branch=master
160[Dependency Status]: https://gemnasium.com/jedmao/ts-compiler.png
161[NPM version]: https://badge.fury.io/js/ts-compiler.png
162[Views]: https://sourcegraph.com/api/repos/github.com/jedmao/ts-compiler/counters/views-24h.png
163[NPM]: https://nodei.co/npm/ts-compiler.png?downloads=true