-
Notifications
You must be signed in to change notification settings - Fork 9
/
compile.js
37 lines (31 loc) · 1004 Bytes
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const ts = require(`typescript`);
const transformer = require(`./transformer`).default;
const fs = require(`fs`);
const TEST_DIR = `test`
/**
* @param {string[]} files - file paths to source files
*/
const compile = files => {
/** @type {ts.CompilerOptions} */
const opts = {
allowJs: true,
module: ts.ModuleKind.CommonJS,
jsx: ts.JsxEmit.React,
lib: [`es6`, `es2016`],
outDir: `${TEST_DIR}/build`,
target: ts.ScriptTarget.ES2015,
allowSyntheticDefaultImports: true,
noEmit: false
};
const host = ts.createCompilerHost(opts);
const prg = ts.createProgram(files, opts, host);
console.log(`compiler options: `, prg.getCompilerOptions());
const { emitSkipped, diagnostics } = prg.emit(undefined, undefined, undefined, false, {
before: [transformer(prg)],
after: []
});
if (emitSkipped) {
throw new Error(diagnostics.map(d => d.messageText).join(`\n`));
}
};
compile(fs.readdirSync(`${TEST_DIR}/src`).map(f => `${TEST_DIR}/src/${f}`));