1
0
mirror of https://github.com/storybookjs/storybook.git synced 2025-03-17 05:02:23 +08:00

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-01-28 19:17:13 +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 babel = path.join(__dirname, '..', 'node_modules', '.bin', 'babel');
2018-01-29 00:57:51 +02:00
const args = [
2018-07-05 21:22:42 +03:00
'--ignore **/__mocks__/,**/tests/*,**/__tests__/,**/**.test.js,**/stories/,**/**.story.js,**/**.stories.js,**/__snapshots__',
'./src --out-dir ./dist',
2018-07-05 21:22:42 +03:00
'--copy-files',
`--config-file ${path.resolve(__dirname, '../.babelrc.js')}`,
];
if (watch) {
args.push('-w');
}
2018-01-29 00:57:51 +02:00
return `${babel} ${args.join(' ')}`;
}
2018-01-29 00:57:51 +02:00
function handleExit(code, errorCallback) {
if (code !== 0) {
2018-01-28 19:09:40 +02:00
if (errorCallback && typeof errorCallback === 'function') {
errorCallback();
}
shell.exit(code);
}
}
2018-01-29 00:57:51 +02:00
function babelify(options = {}) {
const { watch = false, silent = true, 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,
};