UNPKG

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