storybook/scripts/compile-tsc.js
Norbert de Langen d551fb3281 Merge branch 'next' into ts-migration/babel-typescript
# Conflicts:
#	app/angular/src/client/preview/render.js
#	scripts/compile-babel.js
#	yarn.lock
2019-03-19 19:05:58 +01:00

62 lines
1.3 KiB
JavaScript

/* 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', '--listEmittedFiles true'];
if (!process.cwd().includes(path.join('app', 'angular'))) {
args.push('--emitDeclarationOnly');
}
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 = false, 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,
};