1 | const ts = require('typescript');
|
2 | const glob = require('glob');
|
3 |
|
4 | function compile(fileNames, options) {
|
5 | const program = ts.createProgram(fileNames, options);
|
6 | program.getSourceFiles().forEach((sourceFile) => {
|
7 | const emitResult = program.emit(sourceFile, (fileName, content) => {
|
8 | if (options.module === ts.ModuleKind.CommonJS) {
|
9 | fileName = fileName.replace(/\.js$/, '.common.js');
|
10 | }
|
11 | ts.sys.writeFile(fileName, content);
|
12 | });
|
13 | if (emitResult.emitSkipped) process.exit(1);
|
14 | });
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | }
|
23 |
|
24 | const componentsGlob = glob.sync('./components/**/index.ts');
|
25 |
|
26 |
|
27 | compile(componentsGlob, {
|
28 | lib: ['es6', 'dom'],
|
29 | module: ts.ModuleKind.ES2015
|
30 | });
|
31 |
|
32 |
|
33 | compile(componentsGlob, {
|
34 | lib: ['es6', 'dom'],
|
35 | module: ts.ModuleKind.CommonJS
|
36 | });
|