-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbabelify.js
47 lines (40 loc) · 1.22 KB
/
babelify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const chalk = require('chalk');
const fs = require('fs-extra');
const path = require('path');
const { run } = require('./run');
function getCommand(watch, dir) {
const args = [
'./src',
`--out-dir=${dir}`,
`--config-file=${path.resolve('.babelrc.js').replace(' ', '\\ ')}`,
'--extensions=.js,.jsx,.ts,.tsx'
];
if (watch) {
args.push('-w');
}
console.log(`npx babel ${args.join(' ')}`);
return `npx babel ${args.join(' ')}`;
}
async function babelify(options = {}) {
const { watch = false, silent = true, errorCallback } = options;
if (!(await fs.pathExists('src'))) {
if (!silent) {
console.warn(`No '${chalk.yellow('src')}' dir`);
}
return;
}
const runners = watch
?
['./lib/cjs', './lib/esm'].map((dir) => {
const command = getCommand(watch, dir);
return run({ watch, dir, silent, command, errorCallback });
})
: ['./lib/cjs', './lib/esm', './lib/modern'].map((dir) => {
const command = getCommand(watch, dir);
return run({ dir, silent, command, errorCallback });
});
await Promise.all(runners);
}
module.exports = {
babelify,
};