1 | "use strict";
|
2 |
|
3 | const shell = require('shelljs');
|
4 | const chalk = require('chalk');
|
5 |
|
6 | const PACKAGE = `ca-components`;
|
7 | const NPM_DIR = `dist/src/library`;
|
8 | const ESM2015_DIR = `${NPM_DIR}/esm2015`;
|
9 | const ESM6_DIR = `${NPM_DIR}/esm6`;
|
10 | const BUNDLES_DIR = `bundles`;
|
11 | const OUT_DIR_ESM6 = `${NPM_DIR}/package/esm6`;
|
12 |
|
13 | shell.echo(`Start building...`);
|
14 |
|
15 | shell.rm(`-Rf`, `${NPM_DIR}/*`);
|
16 | shell.mkdir(`-p`, `./${ESM2015_DIR}`);
|
17 | shell.mkdir(`-p`, `./${ESM6_DIR}`);
|
18 | shell.mkdir(`-p`, `./${BUNDLES_DIR}`);
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | shell.echo(`Start TSLint`);
|
24 | shell.exec(`tslint -c tslint.json -t stylish src/**/*.ts`);
|
25 | shell.echo(chalk.green(`TSLint completed`));
|
26 |
|
27 |
|
28 | shell.echo(`Start AoT compilation`);
|
29 | if (shell.exec(`ngc -p tsconfig.json`).code !== 0) {
|
30 | shell.echo(chalk.red(`Error: AoT compilation failed`));
|
31 | shell.exit(1);
|
32 | }
|
33 | shell.echo(chalk.green(`AoT compilation completed`));
|
34 |
|
35 |
|
36 | shell.echo(`Start bundling`);
|
37 | shell.echo(`Rollup package`);
|
38 | if (shell.exec(`rollup -c rollup.es.config.js -i ${NPM_DIR}/${PACKAGE}.js -o ${ESM2015_DIR}/${PACKAGE}.js`).code !== 0) {
|
39 | shell.echo(chalk.red(`Error: Rollup package failed`));
|
40 | shell.exit(1);
|
41 | }
|
42 |
|
43 | shell.echo(`Produce ESM6 version`);
|
44 | shell.exec(`ngc -p tsconfig.json --target es6 -d false --outDir ${OUT_DIR_ESM6} --importHelpers true --sourceMap`);
|
45 | if (shell.exec(`rollup -c rollup.es.config.js -i ${OUT_DIR_ESM6}/${PACKAGE}.js -o ${ESM6_DIR}/${PACKAGE}.js`).code !== 0) {
|
46 | shell.echo(chalk.red(`Error: ESM6 version failed`));
|
47 | shell.exit(1);
|
48 | }
|
49 |
|
50 | shell.echo(`Run Rollup conversion on package`);
|
51 | shell.exec('find ./src -name "*.html" -type f -exec cp {} '+NPM_DIR+'/esm6 \\;');
|
52 | shell.exec('find ./src -name "*.css" -type f -exec cp {} '+NPM_DIR+'/esm6 \\;');
|
53 | if (shell.exec(`rollup -c rollup.config.js -i ${ESM6_DIR}/${PACKAGE}.js -o ${BUNDLES_DIR}/${PACKAGE}.umd.js`).code !== 0) {
|
54 | shell.echo(chalk.red(`Error: Rollup conversion failed`));
|
55 | shell.exit(1);
|
56 | }
|
57 |
|
58 | shell.echo(`Minifying`);
|
59 | shell.cd(`${BUNDLES_DIR}`);
|
60 | shell.exec(`uglifyjs ${PACKAGE}.umd.js -c --comments -o ${PACKAGE}.umd.min.js --source-map "filename='${PACKAGE}.umd.min.js.map', includeSources"`);
|
61 | shell.cd(`..`);
|
62 | shell.cd(`..`);
|
63 |
|
64 | shell.echo(chalk.green(`Bundling completed`));
|
65 |
|
66 | shell.rm(`-Rf`, `${NPM_DIR}/package`);
|
67 | shell.rm(`-Rf`, `${NPM_DIR}/node_modules`);
|
68 | shell.rm(`-Rf`, `${NPM_DIR}/*.js`);
|
69 | shell.rm(`-Rf`, `${NPM_DIR}/*.js.map`);
|
70 | shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js`);
|
71 | shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js.map`);
|
72 |
|
73 | shell.cp(`-Rf`, [`package.json`, `LICENSE`, `README.md`], `${NPM_DIR}`);
|
74 |
|
75 | shell.echo(chalk.green(`End building`));
|