forked from MrWolfZ/ngrx-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
121 lines (95 loc) · 4.17 KB
/
build.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
"use strict";
const shell = require('shelljs');
const chalk = require('chalk');
const DIST_DIR = `dist`;
const MODULES_DIR = `${DIST_DIR}/ngrx`;
const BUNDLES_DIR = `${DIST_DIR}/bundles`;
const PACKAGES = [
{
name: 'core',
dir: '.',
modulesDir: '.',
bundleFileName: 'forms',
moduleFileName: 'forms',
},
{
name: 'validation',
dir: './validation',
modulesDir: 'forms',
bundleFileName: 'forms-validation',
moduleFileName: 'validation',
},
];
shell.echo(`Cleaning output directory...`);
shell.rm(`-Rf`, `${DIST_DIR}/*`);
shell.mkdir(`-p`, `./${MODULES_DIR}`);
shell.mkdir(`-p`, `./${BUNDLES_DIR}`);
for (var pkg of PACKAGES) {
shell.echo(`Building package '${pkg.name}'...`);
shell.echo(`Starting TSLint...`);
if (shell.exec(`tslint -c tslint.json -t stylish --type-check --project . ${pkg.dir}/src/**/*.ts`).code !== 0) {
shell.echo(chalk.red(`Error: TSLint failed`));
shell.exit(1);
}
shell.echo(chalk.green(`TSLint completed!`));
shell.echo(`Starting AoT compilation...`);
if (shell.exec(`ngc -p ${pkg.dir}/tsconfig-build.json`).code !== 0) {
shell.echo(chalk.red(`Error: AoT compilation failed!`));
shell.exit(1);
}
shell.echo(chalk.green(`AoT compilation completed!`));
shell.echo(`Starting bundling...`);
if (shell.exec(`rollup -i ${DIST_DIR}/${pkg.dir}/${pkg.bundleFileName}.js -o ${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.js --sourcemap`, { silent: true }).code !== 0) {
shell.echo(chalk.red(`Error: Bundling failed!`));
shell.exit(1);
}
if (shell.exec(`node scripts/map-sources -f ${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.js`).code !== 0) {
shell.echo(chalk.red(`Error: Bundling failed!`));
shell.exit(1);
}
shell.echo(`Downleveling ES2015 to ESM/ES5...`);
shell.cp(`${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.js`, `${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.es5.ts`);
// 2 indicates failure with output still being generated (this command will usually fail because of the --noLib flag)
if (![0, 2].includes(shell.exec(`tsc ${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.es5.ts --target es5 --module es2015 --noLib --sourceMap`, { silent: true }).code)) {
shell.echo(chalk.red(`Error: Downleveling failed!`));
shell.exit(1);
}
if (shell.exec(`node scripts/map-sources -f ${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.es5.js`).code !== 0) {
shell.echo(chalk.red(`Error: Downleveling failed!`));
shell.exit(1);
}
shell.rm(`-f`, `${MODULES_DIR}/${pkg.modulesDir}/${pkg.moduleFileName}.es5.ts`);
shell.echo(`Running rollup conversion...`);
if (shell.exec(`rollup -c ${pkg.dir}/rollup.config.js --sourcemap`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup conversion failed!`));
shell.exit(1);
}
if (shell.exec(`node scripts/map-sources -f ${BUNDLES_DIR}/${pkg.bundleFileName}.umd.js`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup conversion failed!`));
shell.exit(1);
}
shell.echo(`Minifying...`);
const pwd = shell.pwd();
shell.pushd(BUNDLES_DIR);
if (shell.exec(`${pwd}/node_modules/.bin/uglifyjs -c warnings=false --screw-ie8 --comments -o ${pkg.bundleFileName}.umd.min.js --source-map ${pkg.bundleFileName}.umd.min.js.map --source-map-include-sources ${pkg.bundleFileName}.umd.js`).code !== 0) {
shell.echo(chalk.red(`Error: Minifying failed!`));
shell.exit(1);
}
if (shell.exec(`node ${pwd}/scripts/map-sources -f ${pkg.bundleFileName}.umd.min.js`).code !== 0) {
shell.echo(chalk.red(`Error: Minifying failed!`));
shell.exit(1);
}
shell.popd();
shell.echo(chalk.green(`Bundling completed!`));
shell.rm(`-Rf`, `${DIST_DIR}/${pkg.dir}/*.js`);
shell.rm(`-Rf`, `${DIST_DIR}/${pkg.dir}/*.js.map`);
shell.rm(`-Rf`, `${DIST_DIR}/${pkg.dir}/src/**/*.js`);
shell.rm(`-Rf`, `${DIST_DIR}/${pkg.dir}/src/**/*.js.map`);
shell.cp(`-Rf`, [`${pkg.dir}/package.json`], `${DIST_DIR}/${pkg.dir}`);
if (pkg.name !== 'core') {
shell.cp(`-Rf`, [`${pkg.dir}/${pkg.name}.d.ts`], DIST_DIR);
}
shell.echo(chalk.green(`Finished building package '${pkg.name}'!`));
}
shell.cp(`-Rf`, [`LICENSE`, `README.md`], `${DIST_DIR}`);
shell.echo(chalk.green(`Finished building!`));