-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathcompile-ts.js
53 lines (40 loc) · 1.17 KB
/
compile-ts.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
function getCommand(watch) {
const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
const args = ['--outDir ./dist', '-d true', '--listEmittedFiles true'];
if (watch) {
args.push('-w');
}
return `${tsc} ${args.join(' ')}`;
}
function handleExit(code, errorCallback) {
if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
}
shell.exit(code);
}
}
function tscfy(options = {}) {
const { watch = false, silent = true, errorCallback } = options;
const tsConfigFile = 'tsconfig.json';
if (!fs.existsSync(tsConfigFile)) {
if (!silent) console.log(`No ${tsConfigFile}`);
return;
}
const content = fs.readFileSync(tsConfigFile);
const tsConfig = JSON.parse(content);
if (tsConfig && tsConfig.lerna && tsConfig.lerna.disabled === true) {
if (!silent) console.log('Lerna disabled');
return;
}
const command = getCommand(watch);
const { code } = shell.exec(command, { silent });
handleExit(code, errorCallback);
}
module.exports = {
tscfy,
};