2018-01-28 18:35:39 +02:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const shell = require('shelljs');
|
|
|
|
|
2018-01-29 00:57:51 +02:00
|
|
|
function getCommand(watch) {
|
|
|
|
const tsc = path.join(__dirname, '..', 'node_modules', '.bin', 'tsc');
|
2018-01-29 18:45:05 +02:00
|
|
|
|
2018-01-29 19:39:49 +02:00
|
|
|
const args = ['--outDir ./dist', '-d true', '--listEmittedFiles true'];
|
2018-01-29 00:57:51 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 18:35:39 +02:00
|
|
|
function tscfy(options = {}) {
|
2018-01-28 19:09:40 +02:00
|
|
|
const { watch = false, silent = true, errorCallback } = options;
|
2018-01-28 18:35:39 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-29 00:57:51 +02:00
|
|
|
const command = getCommand(watch);
|
2018-01-28 18:35:39 +02:00
|
|
|
const { code } = shell.exec(command, { silent });
|
|
|
|
|
2018-01-29 00:57:51 +02:00
|
|
|
handleExit(code, errorCallback);
|
2018-01-28 18:35:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
tscfy,
|
|
|
|
};
|