mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-17 05:02:23 +08:00
60 lines
1.3 KiB
JavaScript
60 lines
1.3 KiB
JavaScript
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 --declaration 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 = 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,
|
|
};
|