Skip to content

Commit 3c48037

Browse files
gkalpakatscott
authored andcommitted
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
1 parent a623bf4 commit 3c48037

File tree

5 files changed

+66
-37
lines changed

5 files changed

+66
-37
lines changed

scripts/build/angular-in-memory-web-api.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,42 @@
88

99
'use strict';
1010

11-
const {chmod, cp, mkdir, rm} = require('shelljs');
11+
const {resolve} = require('path');
12+
const {chmod, cp, mkdir, rm, test} = require('shelljs');
1213
const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder');
1314

15+
16+
module.exports = {
17+
buildAngularInMemoryWebApiPackage,
18+
};
19+
1420
/**
15-
* Build the `angular-in-memory-web-api` npm package and copy it to `dist/packages-dist/misc`.
21+
* Build the `angular-in-memory-web-api` npm package and copy it to `destDir` for other
22+
* scripts/tests to use.
23+
*
24+
* @param {string} destDir Path to the output directory into which we copy the npm package.
25+
* This path should either be absolute or relative to the project root.
1626
*/
17-
function buildAngularInMemoryWebAPIPackage() {
27+
function buildAngularInMemoryWebApiPackage(destDir) {
1828
console.info('##############################');
1929
console.info(`${scriptPath}:`);
2030
console.info(' Building angular-in-memory-web-api npm package');
2131
console.info('##############################');
2232
exec(`${bazelCmd} build //packages/misc/angular-in-memory-web-api:npm_package`);
2333

34+
// Create the output directory.
35+
const absDestDir = resolve(baseDir, destDir);
36+
if (!test('-d', absDestDir)) {
37+
mkdir('-p', absDestDir);
38+
}
39+
2440
const buildOutputDir = `${bazelBin}/packages/misc/angular-in-memory-web-api/npm_package`;
25-
const distTargetDir = `${baseDir}/dist/packages-dist/misc/angular-in-memory-web-api`;
41+
const distTargetDir = `${absDestDir}/angular-in-memory-web-api`;
2642

2743
console.info(`# Copy artifacts to ${distTargetDir}`);
28-
mkdir('-p', distTargetDir);
2944
rm('-rf', distTargetDir);
3045
cp('-R', buildOutputDir, distTargetDir);
3146
chmod('-R', 'u+w', distTargetDir);
3247

3348
console.info('');
3449
}
35-
36-
module.exports = {buildAngularInMemoryWebAPIPackage};

scripts/build/build-packages-dist.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99

1010
'use strict';
1111

12-
const {buildZoneJsPackage} = require('./zone-js-builder');
12+
const {buildAngularInMemoryWebApiPackage} = require('./angular-in-memory-web-api');
1313
const {buildDevInfraPackage} = require('./dev-infra-builder');
1414
const {buildTargetPackages} = require('./package-builder');
15-
const {buildAngularInMemoryWebAPIPackage} = require('./angular-in-memory-web-api');
15+
const {buildZoneJsPackage} = require('./zone-js-builder');
1616

1717

1818
// Build the legacy (view engine) npm packages into `dist/packages-dist/`.
1919
buildTargetPackages('dist/packages-dist', false, 'Production');
2020

21+
// Build the `angular-dev-infra` npm package into `dist/packages-dist/`.
22+
buildDevInfraPackage('dist/packages-dist');
23+
24+
// Build the `angular-in-memory-web-api` npm package into `dist/packages-dist/misc/`, because it
25+
// might be needed by other scripts/targets.
26+
buildAngularInMemoryWebApiPackage('dist/packages-dist/misc');
27+
2128
// Build the `zone.js` npm package into `dist/zone.js-dist/`, because it might be needed by other
2229
// scripts/tests.
2330
buildZoneJsPackage('dist/zone.js-dist');
24-
25-
// Build the `angular-dev-infra` npm package into `dist/packages-dist/@angular/dev-infra-private`
26-
buildDevInfraPackage();
27-
28-
// Build the `angular-in-memory-web-api` npm package into
29-
// `dist/packages-dist/misc/angular-in-memory-web-api`
30-
buildAngularInMemoryWebAPIPackage();

scripts/build/dev-infra-builder.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,41 @@
88

99
'use strict';
1010

11-
const {chmod, cp, mkdir, rm} = require('shelljs');
11+
const {resolve} = require('path');
12+
const {chmod, cp, mkdir, rm, test} = require('shelljs');
1213
const {baseDir, bazelBin, bazelCmd, exec, scriptPath} = require('./package-builder');
1314

15+
16+
module.exports = {
17+
buildDevInfraPackage,
18+
};
19+
1420
/**
15-
* Build the `@angular/dev-infra-private` npm package and copies it to `dist/packages-dist`.
21+
* Build the `@angular/dev-infra-private` npm package into `destDir`.
22+
*
23+
* @param {string} destDir Path to the output directory into which we copy the npm package.
24+
* This path should either be absolute or relative to the project root.
1625
*/
17-
function buildDevInfraPackage() {
26+
function buildDevInfraPackage(destDir) {
1827
console.info('##############################');
1928
console.info(`${scriptPath}:`);
2029
console.info(' Building @angular/dev-infra-private npm package');
2130
console.info('##############################');
2231
exec(`${bazelCmd} build //dev-infra:npm_package`);
2332

33+
// Create the output directory.
34+
const absDestDir = resolve(baseDir, destDir);
35+
if (!test('-d', absDestDir)) {
36+
mkdir('-p', absDestDir);
37+
}
38+
2439
const buildOutputDir = `${bazelBin}/dev-infra/npm_package`;
25-
const distTargetDir = `${baseDir}/dist/packages-dist/dev-infra-private`;
40+
const distTargetDir = `${absDestDir}/dev-infra-private`;
2641

2742
console.info(`# Copy artifacts to ${distTargetDir}`);
28-
mkdir('-p', distTargetDir);
2943
rm('-rf', distTargetDir);
3044
cp('-R', buildOutputDir, distTargetDir);
3145
chmod('-R', 'u+w', distTargetDir);
3246

3347
console.info('');
3448
}
35-
36-
module.exports = {buildDevInfraPackage};

scripts/build/package-builder.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ module.exports = {
5858
/**
5959
* Build the Angular packages.
6060
*
61-
* @param {string} destPath Path to the output directory into which we copy the npm packages.
61+
* @param {string} destDir Path to the output directory into which we copy the npm packages.
6262
* This path should either be absolute or relative to the project root.
6363
* @param {boolean} enableIvy True, if Ivy should be used.
6464
* @param {string} description Human-readable description of the build.
6565
* @param {boolean?} isRelease True, if the build should be stamped for a release.
6666
* @returns {Array<{name: string, outputPath: string}} A list of packages built.
6767
*/
68-
function buildTargetPackages(destPath, enableIvy, description, isRelease = false) {
68+
function buildTargetPackages(destDir, enableIvy, description, isRelease = false) {
6969
console.info('##################################');
7070
console.info(`${scriptPath}:`);
7171
console.info(' Building @angular/* npm packages');
@@ -87,15 +87,17 @@ function buildTargetPackages(destPath, enableIvy, description, isRelease = false
8787
enableIvy ? 'ivy' : 'view-engine'} ${targets.join(' ')}`);
8888

8989
// Create the output directory.
90-
const absDestPath = resolve(baseDir, destPath);
91-
if (!test('-d', absDestPath)) mkdir('-p', absDestPath);
90+
const absDestDir = resolve(baseDir, destDir);
91+
if (!test('-d', absDestDir)) {
92+
mkdir('-p', absDestDir);
93+
}
9294

9395
targets.forEach(target => {
9496
const pkg = target.replace(/\/\/packages\/(.*):npm_package/, '$1');
9597

9698
// Skip any that don't have an "npm_package" target.
9799
const srcDir = `${bazelBin}/packages/${pkg}/npm_package`;
98-
const destDir = `${absDestPath}/${pkg}`;
100+
const destDir = `${absDestDir}/${pkg}`;
99101

100102
if (test('-d', srcDir)) {
101103
console.info(`# Copy artifacts to ${destDir}`);

scripts/build/zone-js-builder.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,40 +20,42 @@ module.exports = {
2020

2121
/**
2222
* Build the `zone.js` npm package into `dist/bin/packages/zone.js/npm_package/` and copy it to
23-
* `destPath` for other scripts/tests to use.
23+
* `destDir` for other scripts/tests to use.
2424
*
2525
* NOTE: The `zone.js` package is not built as part of `package-builder`'s `buildTargetPackages()`
2626
* nor is it copied into the same directory as the Angular packages (e.g.
2727
* `dist/packages-dist/`) despite its source's being inside `packages/`, because it is not
2828
* published to npm under the `@angular` scope (as happens for the rest of the packages).
2929
*
30-
* @param {string} destPath Path to the output directory into which we copy the npm package.
30+
* @param {string} destDir Path to the output directory into which we copy the npm package.
3131
* This path should either be absolute or relative to the project root.
3232
*/
33-
function buildZoneJsPackage(destPath) {
33+
function buildZoneJsPackage(destDir) {
3434
console.info('##############################');
3535
console.info(`${scriptPath}:`);
3636
console.info(' Building zone.js npm package');
3737
console.info('##############################');
3838
exec(`${bazelCmd} run //packages/zone.js:npm_package.pack`);
3939

4040
// Create the output directory.
41-
const absDestPath = resolve(baseDir, destPath);
42-
if (!test('-d', absDestPath)) mkdir('-p', absDestPath);
41+
const absDestDir = resolve(baseDir, destDir);
42+
if (!test('-d', absDestDir)) {
43+
mkdir('-p', absDestDir);
44+
}
4345

44-
// Copy artifacts to `destPath`, so they can be easier persisted on CI and used by non-bazel
46+
// Copy artifacts to `destDir`, so they can be easier persisted on CI and used by non-bazel
4547
// scripts/tests.
4648
const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`;
47-
const distTargetDir = `${absDestPath}/zone.js`;
49+
const distTargetDir = `${absDestDir}/zone.js`;
4850

4951
console.info(`# Copy npm_package artifacts to ${distTargetDir}`);
5052
rm('-rf', distTargetDir);
5153
cp('-R', buildOutputDir, distTargetDir);
5254
chmod('-R', 'u+w', distTargetDir);
5355

54-
// Copy `zone.js.tgz` to `destPath`, so we can test
56+
// Copy `zone.js.tgz` to `destDir`, so we can test
5557
// the archive generated by the `npm_package.pack` rule.
56-
const distArchiveTargetDir = `${absDestPath}/archive`;
58+
const distArchiveTargetDir = `${absDestDir}/archive`;
5759
console.info(`# Copy npm_package archive file to ${distArchiveTargetDir}`);
5860
rm('-rf', distArchiveTargetDir);
5961
mkdir('-p', distArchiveTargetDir);

0 commit comments

Comments
 (0)