|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const shell = require('shelljs'); |
| 4 | +const chalk = require('chalk'); |
| 5 | + |
| 6 | +const PACKAGE = `angular-split`; |
| 7 | +const NPM_DIR = `dist`; |
| 8 | +const ESM2015_DIR = `${NPM_DIR}/esm2015`; |
| 9 | +const ESM5_DIR = `${NPM_DIR}/esm5`; |
| 10 | +const BUNDLES_DIR = `${NPM_DIR}/bundles`; |
| 11 | +const OUT_DIR_ESM5 = `${NPM_DIR}/package/esm5`; |
| 12 | + |
| 13 | +shell.echo(`Start building...`); |
| 14 | + |
| 15 | +shell.rm(`-Rf`, `${NPM_DIR}/*`); |
| 16 | +shell.mkdir(`-p`, `./${ESM2015_DIR}`); |
| 17 | +shell.mkdir(`-p`, `./${ESM5_DIR}`); |
| 18 | +shell.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 |
| 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 | +/* AoT compilation */ |
| 28 | +shell.echo(`Start AoT compilation`); |
| 29 | +if (shell.exec(`ngc -p tsconfig-build.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 | +/* BUNDLING PACKAGE */ |
| 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 ESM5 version`); |
| 44 | +shell.exec(`ngc -p tsconfig-build.json --target es5 -d false --outDir ${OUT_DIR_ESM5} --importHelpers true --sourceMap`); |
| 45 | +if (shell.exec(`rollup -c rollup.es.config.js -i ${OUT_DIR_ESM5}/${PACKAGE}.js -o ${ESM5_DIR}/${PACKAGE}.js`).code !== 0) { |
| 46 | + shell.echo(chalk.red(`Error: ESM5 version failed`)); |
| 47 | + shell.exit(1); |
| 48 | +} |
| 49 | + |
| 50 | +shell.echo(`Run Rollup conversion on package`); |
| 51 | +if (shell.exec(`rollup -c rollup.config.js -i ${ESM5_DIR}/${PACKAGE}.js -o ${BUNDLES_DIR}/${PACKAGE}.umd.js`).code !== 0) { |
| 52 | + shell.echo(chalk.red(`Error: Rollup conversion failed`)); |
| 53 | + shell.exit(1); |
| 54 | +} |
| 55 | + |
| 56 | +shell.echo(`Minifying`); |
| 57 | +shell.cd(`${BUNDLES_DIR}`); |
| 58 | +shell.exec(`uglifyjs ${PACKAGE}.umd.js -c --comments -o ${PACKAGE}.umd.min.js --source-map "filename='${PACKAGE}.umd.min.js.map', includeSources"`); |
| 59 | +shell.cd(`..`); |
| 60 | +shell.cd(`..`); |
| 61 | + |
| 62 | +shell.echo(chalk.green(`Bundling completed`)); |
| 63 | + |
| 64 | +shell.rm(`-Rf`, `${NPM_DIR}/package`); |
| 65 | +shell.rm(`-Rf`, `${NPM_DIR}/node_modules`); |
| 66 | +shell.rm(`-Rf`, `${NPM_DIR}/*.js`); |
| 67 | +shell.rm(`-Rf`, `${NPM_DIR}/*.js.map`); |
| 68 | +shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js`); |
| 69 | +shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js.map`); |
| 70 | + |
| 71 | +shell.cp(`-Rf`, [`package.json`, `LICENSE`, `README.md`], `${NPM_DIR}`); |
| 72 | + |
| 73 | +shell.echo(chalk.green(`End building`)); |
0 commit comments