storybook/scripts/compile-js.js
Kai Röder 8c8775c8f5 Angular now gets compiled by tsc, everything else is compiled by babel-typescript
TODO: need to migrate app/angular/server to TS in order to work with tsc
2019-01-04 14:13:23 +01:00

71 lines
1.4 KiB
JavaScript

/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
function getCommand(watch) {
const babel = path.join(__dirname, '..', 'node_modules', '.bin', 'babel');
const ignore = [
'**/__mocks__/',
'**/tests/',
'**/__tests__/',
'**/*.test.js',
'**/*.test.ts',
'**/stories/',
'**/*.story.js',
'**/*.story.ts',
'**/*.stories.js',
'**/*.stories.ts',
'**/__snapshots__',
'**/*.d.ts',
];
const args = [
'./src',
'--out-dir ./dist',
`--config-file ${path.resolve(__dirname, '../.babelrc.js')}`,
`--extensions ".js,.jsx,.ts,.tsx"`,
`--copy-files`,
`--ignore "${ignore.join('","')}"`,
];
if (watch) {
args.push('-w');
}
return `${babel} ${args.join(' ')}`;
}
function handleExit(code, errorCallback) {
if (code !== 0) {
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
}
shell.exit(code);
}
}
function babelify(options = {}) {
if (process.cwd().includes(path.join('app', 'angular'))) {
return;
}
const { watch = false, silent = false, errorCallback } = options;
if (!fs.existsSync('src')) {
if (!silent) console.log('No src dir');
return;
}
const command = getCommand(watch);
const { code } = shell.exec(command, { silent });
handleExit(code, errorCallback);
}
module.exports = {
babelify,
};