-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.js
More file actions
103 lines (90 loc) · 2.71 KB
/
Copy pathbuild.js
File metadata and controls
103 lines (90 loc) · 2.71 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const childProcess = require('child_process');
const path = require('path');
const fs = require('fs');
const { promisify } = require('util');
const exec = promisify(childProcess.exec);
const validBundles = [
'node',
'stable',
];
async function run(argv) {
const { bundle, largeFiles, outDir: relativeOutDir, verbose, watch } = argv;
if (validBundles.indexOf(bundle) === -1) {
throw new TypeError(
`Unrecognized bundle '${bundle}'. Did you mean one of "${validBundles.join('", "')}"?`,
);
}
const env = {
NODE_ENV: process.env.NODE_ENV ?? 'development',
BABEL_ENV: bundle,
MUI_BUILD_VERBOSE: verbose,
};
const babelConfigPath = path.resolve(__dirname, '../babel.config.js');
const srcDir = path.resolve('./src');
const pkg = JSON.parse(fs.readFileSync(path.resolve('./package.json'), 'utf-8'));
const extensions = ['.js', '.ts', '.tsx'];
const ignore = [
'**/*.test.js',
'**/*.test.ts',
'**/*.test.tsx',
'**/*.spec.ts',
'**/*.spec.tsx',
'**/*.d.ts',
];
const outDir = path.resolve(
relativeOutDir + (pkg.name.startsWith('@frontegg') ? `/${pkg.name}` : ''),
{
node: './',
stable: './esm',
}[bundle],
);
const babelArgs = [
'--config-file',
babelConfigPath,
'--extensions',
`"${extensions.join(',')}"`,
srcDir,
'--out-dir',
outDir,
];
if (largeFiles) {
babelArgs.push('--compact false');
}
babelArgs.push('--source-maps');
if (watch) {
babelArgs.push('--watch');
babelArgs.push('--skip-initial-build');
}
babelArgs.push('--ignore');
// Need to put these patterns in quotes otherwise they might be evaluated by the used terminal.
babelArgs.push(`"${ignore.join('","')}"`);
const command = ['yarn babel', ...babelArgs].join(' ');
if (verbose) {
// eslint-disable-next-line no-console
console.log(`running '${command}' with ${JSON.stringify(env)}`);
}
try {
const { stderr, stdout } = await exec(command, { env: { ...process.env, ...env } });
// Don't treat Node/babel deprecation warnings or Browserslist data-age
// notices (e.g. "caniuse-lite is N months old") on stderr as failure
if (stderr && !/DeprecationWarning|url\.parse|Browserslist/.test(stderr)) {
throw new Error(`'${command}' failed with \n${stderr}`);
}
if (verbose) {
// eslint-disable-next-line no-console
console.log(stdout);
}
} catch (err) {
if (err.stderr) {
throw new Error(`'${command}' failed with \n${err.stderr}`);
}
throw err;
}
}
run({
largeFiles: false,
outDir: process.argv[3] && process.argv[3] !== `--watch` ? process.argv[3] : `../../dist`,
verbose: false,
bundle: process.argv[2],
watch: process.argv[3] === '--watch',
});