Skip to content

Commit

Permalink
Build: upgrade to Angular v5 building process
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Oct 8, 2017
1 parent 5fc64c7 commit 5648033
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 287 deletions.
36 changes: 21 additions & 15 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ const chalk = require('chalk');

const PACKAGE = `angular-l10n`;
const NPM_DIR = `dist`;
const MODULES_DIR = `${NPM_DIR}/modules`;
const ESM2015_DIR = `${NPM_DIR}/esm2015`;
const ESM5_DIR = `${NPM_DIR}/esm5`;
const BUNDLES_DIR = `${NPM_DIR}/bundles`;
const OUT_DIR_ESM5 = `${NPM_DIR}/package/esm5`;

shell.echo(`Start building...`);

shell.rm(`-Rf`, `${NPM_DIR}/*`);
shell.mkdir(`-p`, `./${MODULES_DIR}`);
shell.mkdir(`-p`, `./${ESM2015_DIR}`);
shell.mkdir(`-p`, `./${ESM5_DIR}`);
shell.mkdir(`-p`, `./${BUNDLES_DIR}`);

/* TSLint with Codelyzer */
Expand All @@ -21,42 +24,45 @@ shell.echo(`Start TSLint`);
shell.exec(`tslint -c tslint.json -t stylish src/**/*.ts`);
shell.echo(chalk.green(`TSLint completed`));

/* AoT compilation: ES2015 sources */
/* AoT compilation */
shell.echo(`Start AoT compilation`);
if (shell.exec(`ngc -p tsconfig-build.json`).code !== 0) {
shell.echo(chalk.red(`Error: AoT compilation failed`));
shell.exit(1);
}
shell.echo(chalk.green(`AoT compilation completed`));

/* Creates bundles: ESM/ES5 and UMD bundles */
/* BUNDLING PACKAGE */
shell.echo(`Start bundling`);
shell.echo(`Rollup package`);
shell.exec(`rollup -f es -i ${NPM_DIR}/${PACKAGE}.js -o ${MODULES_DIR}/${PACKAGE}.js --sourcemap`, { silent: true });
shell.exec(`node scripts/map-sources -f ${MODULES_DIR}/${PACKAGE}.js`);
if (shell.exec(`rollup -c rollup.es.config.js -i ${NPM_DIR}/${PACKAGE}.js -o ${ESM2015_DIR}/${PACKAGE}.js`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup package failed`));
shell.exit(1);
}

shell.echo(`Downleveling ES2015 to ESM/ES5`);
shell.cp(`${MODULES_DIR}/${PACKAGE}.js`, `${MODULES_DIR}/${PACKAGE}.es5.ts`);
shell.exec(`tsc ${MODULES_DIR}/${PACKAGE}.es5.ts --target es5 --module es2015 --noLib --sourceMap`, { silent: true });
shell.exec(`node scripts/map-sources -f ${MODULES_DIR}/${PACKAGE}.es5.js`);
shell.rm(`-f`, `${MODULES_DIR}/${PACKAGE}.es5.ts`);
shell.echo(`Produce ESM5 version`);
shell.exec(`ngc -p tsconfig-build.json --target es5 -d false --outDir ${OUT_DIR_ESM5} --importHelpers true --sourceMap`);
if (shell.exec(`rollup -c rollup.es.config.js -i ${OUT_DIR_ESM5}/${PACKAGE}.js -o ${ESM5_DIR}/${PACKAGE}.js`).code !== 0) {
shell.echo(chalk.red(`Error: ESM5 version failed`));
shell.exit(1);
}

shell.echo(`Run Rollup conversion on package`);
if (shell.exec(`rollup -c rollup.config.js --sourcemap`).code !== 0) {
if (shell.exec(`rollup -c rollup.config.js -i ${ESM5_DIR}/${PACKAGE}.js -o ${BUNDLES_DIR}/${PACKAGE}.umd.js`).code !== 0) {
shell.echo(chalk.red(`Error: Rollup conversion failed`));
shell.exit(1);
}
shell.exec(`node scripts/map-sources -f ${BUNDLES_DIR}/${PACKAGE}.umd.js`);

shell.echo(`Minifying`);
shell.cd(`${BUNDLES_DIR}`);
shell.exec(`uglifyjs -c warnings=false --screw-ie8 --comments -o ${PACKAGE}.umd.min.js --source-map ${PACKAGE}.umd.min.js.map --source-map-include-sources ${PACKAGE}.umd.js`);
shell.exec(`node ../../scripts/map-sources -f ${PACKAGE}.umd.min.js`);
shell.exec(`uglifyjs ${PACKAGE}.umd.js -c --comments -o ${PACKAGE}.umd.min.js --source-map "filename='${PACKAGE}.umd.min.js.map', includeSources"`);
shell.cd(`..`);
shell.cd(`..`);

shell.echo(chalk.green(`Bundling completed`));

shell.rm(`-Rf`, `${NPM_DIR}/package`);
shell.rm(`-Rf`, `${NPM_DIR}/node_modules`);
shell.rm(`-Rf`, `${NPM_DIR}/*.js`);
shell.rm(`-Rf`, `${NPM_DIR}/*.js.map`);
shell.rm(`-Rf`, `${NPM_DIR}/src/**/*.js`);
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It allows, in addition to translation, to localize numbers and dates of your app
---

> Library version: 4.0.0-beta.4 - [Changelog](https://github.com/robisim74/angular-l10n/releases)
> Library version: 4.0.0-rc.0 - [Changelog](https://github.com/robisim74/angular-l10n/releases)
<br>

Expand Down
6 changes: 6 additions & 0 deletions license-banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @license Angular l10n
* Copyright Roberto Simonetti
* MIT license
* https://github.com/robisim74/angular-l10n
*/
Loading

0 comments on commit 5648033

Please sign in to comment.