From 3c48037d244df2531480e480f44c11abb1f00e12 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 5 Apr 2021 19:05:54 +0300 Subject: [PATCH] build: make the build scripts for the various packages consistent (#41429) This commit makes the build scripts for the various packages (framework, `@angular/dev-infra-private`, `angular-in-memory-web-api`, `zone.js`) consistent. This makes it easier to maintain them (e.g. make similar changes across all build scripts). PR Close #41429 --- scripts/build/angular-in-memory-web-api.js | 27 ++++++++++++++++------ scripts/build/build-packages-dist.js | 18 +++++++-------- scripts/build/dev-infra-builder.js | 26 +++++++++++++++------ scripts/build/package-builder.js | 12 ++++++---- scripts/build/zone-js-builder.js | 20 ++++++++-------- 5 files changed, 66 insertions(+), 37 deletions(-) diff --git a/scripts/build/angular-in-memory-web-api.js b/scripts/build/angular-in-memory-web-api.js index db0b247217..fadf9248b5 100644 --- a/scripts/build/angular-in-memory-web-api.js +++ b/scripts/build/angular-in-memory-web-api.js @@ -8,29 +8,42 @@ 'use strict'; -const {chmod, cp, mkdir, rm} = require('shelljs'); +const {resolve} = require('path'); +const {chmod, cp, mkdir, rm, test} = require('shelljs'); const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder'); + +module.exports = { + buildAngularInMemoryWebApiPackage, +}; + /** - * Build the `angular-in-memory-web-api` npm package and copy it to `dist/packages-dist/misc`. + * Build the `angular-in-memory-web-api` npm package and copy it to `destDir` for other + * scripts/tests to use. + * + * @param {string} destDir Path to the output directory into which we copy the npm package. + * This path should either be absolute or relative to the project root. */ -function buildAngularInMemoryWebAPIPackage() { +function buildAngularInMemoryWebApiPackage(destDir) { console.info('##############################'); console.info(`${scriptPath}:`); console.info(' Building angular-in-memory-web-api npm package'); console.info('##############################'); exec(`${bazelCmd} build //packages/misc/angular-in-memory-web-api:npm_package`); + // Create the output directory. + const absDestDir = resolve(baseDir, destDir); + if (!test('-d', absDestDir)) { + mkdir('-p', absDestDir); + } + const buildOutputDir = `${bazelBin}/packages/misc/angular-in-memory-web-api/npm_package`; - const distTargetDir = `${baseDir}/dist/packages-dist/misc/angular-in-memory-web-api`; + const distTargetDir = `${absDestDir}/angular-in-memory-web-api`; console.info(`# Copy artifacts to ${distTargetDir}`); - mkdir('-p', distTargetDir); rm('-rf', distTargetDir); cp('-R', buildOutputDir, distTargetDir); chmod('-R', 'u+w', distTargetDir); console.info(''); } - -module.exports = {buildAngularInMemoryWebAPIPackage}; diff --git a/scripts/build/build-packages-dist.js b/scripts/build/build-packages-dist.js index 8ecda36989..517050abd5 100644 --- a/scripts/build/build-packages-dist.js +++ b/scripts/build/build-packages-dist.js @@ -9,22 +9,22 @@ 'use strict'; -const {buildZoneJsPackage} = require('./zone-js-builder'); +const {buildAngularInMemoryWebApiPackage} = require('./angular-in-memory-web-api'); const {buildDevInfraPackage} = require('./dev-infra-builder'); const {buildTargetPackages} = require('./package-builder'); -const {buildAngularInMemoryWebAPIPackage} = require('./angular-in-memory-web-api'); +const {buildZoneJsPackage} = require('./zone-js-builder'); // Build the legacy (view engine) npm packages into `dist/packages-dist/`. buildTargetPackages('dist/packages-dist', false, 'Production'); +// Build the `angular-dev-infra` npm package into `dist/packages-dist/`. +buildDevInfraPackage('dist/packages-dist'); + +// Build the `angular-in-memory-web-api` npm package into `dist/packages-dist/misc/`, because it +// might be needed by other scripts/targets. +buildAngularInMemoryWebApiPackage('dist/packages-dist/misc'); + // Build the `zone.js` npm package into `dist/zone.js-dist/`, because it might be needed by other // scripts/tests. buildZoneJsPackage('dist/zone.js-dist'); - -// Build the `angular-dev-infra` npm package into `dist/packages-dist/@angular/dev-infra-private` -buildDevInfraPackage(); - -// Build the `angular-in-memory-web-api` npm package into -// `dist/packages-dist/misc/angular-in-memory-web-api` -buildAngularInMemoryWebAPIPackage(); diff --git a/scripts/build/dev-infra-builder.js b/scripts/build/dev-infra-builder.js index 625f8aaacf..b83877dcf8 100644 --- a/scripts/build/dev-infra-builder.js +++ b/scripts/build/dev-infra-builder.js @@ -8,29 +8,41 @@ 'use strict'; -const {chmod, cp, mkdir, rm} = require('shelljs'); +const {resolve} = require('path'); +const {chmod, cp, mkdir, rm, test} = require('shelljs'); const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder'); + +module.exports = { + buildDevInfraPackage, +}; + /** - * Build the `@angular/dev-infra-private` npm package and copies it to `dist/packages-dist`. + * Build the `@angular/dev-infra-private` npm package into `destDir`. + * + * @param {string} destDir Path to the output directory into which we copy the npm package. + * This path should either be absolute or relative to the project root. */ -function buildDevInfraPackage() { +function buildDevInfraPackage(destDir) { console.info('##############################'); console.info(`${scriptPath}:`); console.info(' Building @angular/dev-infra-private npm package'); console.info('##############################'); exec(`${bazelCmd} build //dev-infra:npm_package`); + // Create the output directory. + const absDestDir = resolve(baseDir, destDir); + if (!test('-d', absDestDir)) { + mkdir('-p', absDestDir); + } + const buildOutputDir = `${bazelBin}/dev-infra/npm_package`; - const distTargetDir = `${baseDir}/dist/packages-dist/dev-infra-private`; + const distTargetDir = `${absDestDir}/dev-infra-private`; console.info(`# Copy artifacts to ${distTargetDir}`); - mkdir('-p', distTargetDir); rm('-rf', distTargetDir); cp('-R', buildOutputDir, distTargetDir); chmod('-R', 'u+w', distTargetDir); console.info(''); } - -module.exports = {buildDevInfraPackage}; diff --git a/scripts/build/package-builder.js b/scripts/build/package-builder.js index 530a286f67..6c735a3cf0 100644 --- a/scripts/build/package-builder.js +++ b/scripts/build/package-builder.js @@ -58,14 +58,14 @@ module.exports = { /** * Build the Angular packages. * - * @param {string} destPath Path to the output directory into which we copy the npm packages. + * @param {string} destDir Path to the output directory into which we copy the npm packages. * This path should either be absolute or relative to the project root. * @param {boolean} enableIvy True, if Ivy should be used. * @param {string} description Human-readable description of the build. * @param {boolean?} isRelease True, if the build should be stamped for a release. * @returns {Array<{name: string, outputPath: string}} A list of packages built. */ -function buildTargetPackages(destPath, enableIvy, description, isRelease = false) { +function buildTargetPackages(destDir, enableIvy, description, isRelease = false) { console.info('##################################'); console.info(`${scriptPath}:`); console.info(' Building @angular/* npm packages'); @@ -87,15 +87,17 @@ function buildTargetPackages(destPath, enableIvy, description, isRelease = false enableIvy ? 'ivy' : 'view-engine'} ${targets.join(' ')}`); // Create the output directory. - const absDestPath = resolve(baseDir, destPath); - if (!test('-d', absDestPath)) mkdir('-p', absDestPath); + const absDestDir = resolve(baseDir, destDir); + if (!test('-d', absDestDir)) { + mkdir('-p', absDestDir); + } targets.forEach(target => { const pkg = target.replace(/\/\/packages\/(.*):npm_package/, '$1'); // Skip any that don't have an "npm_package" target. const srcDir = `${bazelBin}/packages/${pkg}/npm_package`; - const destDir = `${absDestPath}/${pkg}`; + const destDir = `${absDestDir}/${pkg}`; if (test('-d', srcDir)) { console.info(`# Copy artifacts to ${destDir}`); diff --git a/scripts/build/zone-js-builder.js b/scripts/build/zone-js-builder.js index 41108f7088..604b2eb7b0 100644 --- a/scripts/build/zone-js-builder.js +++ b/scripts/build/zone-js-builder.js @@ -20,17 +20,17 @@ module.exports = { /** * Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to - * `destPath` for other scripts/tests to use. + * `destDir` for other scripts/tests to use. * * NOTE: The `zone.js` package is not built as part of `package-builder`'s `buildTargetPackages()` * nor is it copied into the same directory as the Angular packages (e.g. * `dist/packages-dist/`) despite its source's being inside `packages/`, because it is not * published to npm under the `@angular` scope (as happens for the rest of the packages). * - * @param {string} destPath Path to the output directory into which we copy the npm package. + * @param {string} destDir Path to the output directory into which we copy the npm package. * This path should either be absolute or relative to the project root. */ -function buildZoneJsPackage(destPath) { +function buildZoneJsPackage(destDir) { console.info('##############################'); console.info(`${scriptPath}:`); console.info(' Building zone.js npm package'); @@ -38,22 +38,24 @@ function buildZoneJsPackage(destPath) { exec(`${bazelCmd} run //packages/zone.js:npm_package.pack`); // Create the output directory. - const absDestPath = resolve(baseDir, destPath); - if (!test('-d', absDestPath)) mkdir('-p', absDestPath); + const absDestDir = resolve(baseDir, destDir); + if (!test('-d', absDestDir)) { + mkdir('-p', absDestDir); + } - // Copy artifacts to `destPath`, so they can be easier persisted on CI and used by non-bazel + // Copy artifacts to `destDir`, so they can be easier persisted on CI and used by non-bazel // scripts/tests. const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`; - const distTargetDir = `${absDestPath}/zone.js`; + const distTargetDir = `${absDestDir}/zone.js`; console.info(`# Copy npm_package artifacts to ${distTargetDir}`); rm('-rf', distTargetDir); cp('-R', buildOutputDir, distTargetDir); chmod('-R', 'u+w', distTargetDir); - // Copy `zone.js.tgz` to `destPath`, so we can test + // Copy `zone.js.tgz` to `destDir`, so we can test // the archive generated by the `npm_package.pack` rule. - const distArchiveTargetDir = `${absDestPath}/archive`; + const distArchiveTargetDir = `${absDestDir}/archive`; console.info(`# Copy npm_package archive file to ${distArchiveTargetDir}`); rm('-rf', distArchiveTargetDir); mkdir('-p', distArchiveTargetDir);