|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +const shell = require('shelljs'); |
| 4 | +const chalk = require('chalk'); |
| 5 | + |
| 6 | +const PACKAGE = `ng2-heremaps`; |
| 7 | +const NPM_DIR = `dist`; |
| 8 | +const ESM2015_DIR = `${NPM_DIR}/esm2015`; |
| 9 | +const ESM5_DIR = `${NPM_DIR}/esm5`; |
| 10 | +const FESM2015_DIR = `${NPM_DIR}/fesm2015`; |
| 11 | +const FESM5_DIR = `${NPM_DIR}/fesm5`; |
| 12 | +const BUNDLES_DIR = `${NPM_DIR}/bundles`; |
| 13 | +const OUT_DIR = `${NPM_DIR}/package`; |
| 14 | +const OUT_DIR_ESM5 = `${NPM_DIR}/package/esm5`; |
| 15 | + |
| 16 | +shell.echo(`Start building...`); |
| 17 | + |
| 18 | +shell.rm(`-Rf`, `${NPM_DIR}/*`); |
| 19 | +shell.mkdir(`-p`, `./${ESM2015_DIR}`); |
| 20 | +shell.mkdir(`-p`, `./${ESM5_DIR}`); |
| 21 | +shell.mkdir(`-p`, `./${FESM2015_DIR}`); |
| 22 | +shell.mkdir(`-p`, `./${FESM5_DIR}`); |
| 23 | +shell.mkdir(`-p`, `./${BUNDLES_DIR}`); |
| 24 | +shell.mkdir(`-p`, `./${OUT_DIR}`); |
| 25 | + |
| 26 | +/* TSLint with Codelyzer */ |
| 27 | +// https://github.com/palantir/tslint/blob/master/src/configs/recommended.ts |
| 28 | +// https://github.com/mgechev/codelyzer |
| 29 | +shell.echo(`Start TSLint`); |
| 30 | +shell.exec(`tslint -p tsconfig.json -t stylish src/**/*.ts`); |
| 31 | +shell.echo(chalk.green(`TSLint completed`)); |
| 32 | + |
| 33 | +shell.cp(`-Rf`, [`src`, `*.ts`, `*.json`], `${OUT_DIR}`); |
| 34 | + |
| 35 | +/* Try to process scss files */ |
| 36 | +shell.echo(`Try to process scss files`); |
| 37 | +if (shell.exec(`node-sass -r ${OUT_DIR} -o ${OUT_DIR}`).code === 0) { |
| 38 | + shell.rm(`-Rf`, `${OUT_DIR}/**/*.scss`); |
| 39 | + shell.ls(`${OUT_DIR}/**/*.css`).forEach(function (file) { |
| 40 | + shell.mv(file, file.replace('.css', '.scss')); |
| 41 | + }); |
| 42 | +} |
| 43 | + |
| 44 | +/* AoT compilation */ |
| 45 | +shell.echo(`Start AoT compilation`); |
| 46 | +if (shell.exec(`ngc -p ${OUT_DIR}/tsconfig-build.json`).code !== 0) { |
| 47 | + shell.echo(chalk.red(`Error: AoT compilation failed`)); |
| 48 | + shell.exit(1); |
| 49 | +} |
| 50 | +shell.echo(chalk.green(`AoT compilation completed`)); |
| 51 | + |
| 52 | +shell.echo(`Copy ES2015 for package`); |
| 53 | +shell.cp(`-Rf`, [`${NPM_DIR}/src/`, `${NPM_DIR}/*.js`, `${NPM_DIR}/*.js.map`], `${ESM2015_DIR}`); |
| 54 | + |
| 55 | +/* BUNDLING PACKAGE */ |
| 56 | +shell.echo(`Start bundling`); |
| 57 | +shell.echo(`Rollup package`); |
| 58 | +if (shell.exec(`rollup -c rollup.es.config.js -i ${NPM_DIR}/${PACKAGE}.js -o ${FESM2015_DIR}/${PACKAGE}.js`).code !== 0) { |
| 59 | + shell.echo(chalk.red(`Error: Rollup package failed`)); |
| 60 | + shell.exit(1); |
| 61 | +} |
| 62 | + |
| 63 | +shell.echo(`Produce ESM5/FESM5 versions`); |
| 64 | +shell.exec(`ngc -p ${OUT_DIR}/tsconfig-build.json --target es5 -d false --outDir ${OUT_DIR_ESM5} --sourceMap`); |
| 65 | +shell.cp(`-Rf`, [`${OUT_DIR_ESM5}/src/`, `${OUT_DIR_ESM5}/*.js`, `${OUT_DIR_ESM5}/*.js.map`], `${ESM5_DIR}`); |
| 66 | +if (shell.exec(`rollup -c rollup.es.config.js -i ${OUT_DIR_ESM5}/${PACKAGE}.js -o ${FESM5_DIR}/${PACKAGE}.js`).code !== 0) { |
| 67 | + shell.echo(chalk.red(`Error: FESM5 version failed`)); |
| 68 | + shell.exit(1); |
| 69 | +} |
| 70 | + |
| 71 | +shell.echo(`Run Rollup conversion on package`); |
| 72 | +if (shell.exec(`rollup -c rollup.config.js -i ${FESM5_DIR}/${PACKAGE}.js -o ${BUNDLES_DIR}/${PACKAGE}.umd.js`).code !== 0) { |
| 73 | + shell.echo(chalk.red(`Error: Rollup conversion failed`)); |
| 74 | + shell.exit(1); |
| 75 | +} |
| 76 | + |
| 77 | +shell.echo(`Minifying`); |
| 78 | +shell.cd(`${BUNDLES_DIR}`); |
| 79 | +if (shell.exec(`uglifyjs ${PACKAGE}.umd.js -c --comments -o ${PACKAGE}.umd.min.js --source-map "includeSources=true,filename='${PACKAGE}.umd.min.js.map'"`).code !== 0) { |
| 80 | + shell.echo(chalk.red(`Error: Minifying failed`)); |
| 81 | + shell.exit(1); |
| 82 | +} |
| 83 | +shell.cd(`..`); |
| 84 | +shell.cd(`..`); |
| 85 | + |
| 86 | +shell.echo(chalk.green(`Bundling completed`)); |
| 87 | + |
| 88 | +shell.rm(`-Rf`, `${NPM_DIR}/package`); |
| 89 | +shell.rm(`-Rf`, `${NPM_DIR}/*.js`); |
| 90 | +shell.rm(`-Rf`, `${NPM_DIR}/*.js.map`); |
| 91 | +shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js`); |
| 92 | +shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js.map`); |
| 93 | +shell.rm(`-Rf`, `${ESM2015_DIR}/src/**/*.d.ts`); |
| 94 | + |
| 95 | +shell.cp(`-Rf`, [`package.json`, `LICENSE`, `README.md`], `${NPM_DIR}`); |
| 96 | + |
| 97 | +shell.sed('-i', `"private": true,`, `"private": false,`, `./${NPM_DIR}/package.json`); |
| 98 | + |
| 99 | +shell.echo(chalk.green(`End building`)); |
0 commit comments