angular-cn/scripts/build/angular-in-memory-web-api.js
George Kalpakas 4ae57cabd8 build: correctly publish angular-in-memory-web-api as CI build artifact (#41429)
Previously, the `angular-in-memory-web-api` package was built in
`dist/packages-dist/misc/angular-in-memory-web-api/`. This was different
from other Angular packages, which were placed directly in
`dist/packages-dist/`. This caused the `create-package-archives.sh`
script to create an invalid `misc.tgz` archive (i.e. treating the
`misc/` subdirectory as a package).
See, for example, the artifacts [here][1].

This commit changes the build scripts to have the
`angular-in-memory-web-api` package built in
`dist/angular-in-memory-web-api-dist/`, similar to how the `zone.js`
package is handled. It also updates the CircleCI config to correctly
publish the `angular-in-memory-web-api` package to CI build artifacts.

[1]: https://circleci.com/gh/angular/angular/951491

PR Close #41429
2021-04-06 10:22:54 -07:00

55 lines
1.9 KiB
JavaScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
'use strict';
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 `destDir` for other
* scripts/tests to use.
*
* NOTE: The `angular-in-memory-web-api` 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} 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(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 = `${absDestDir}/angular-in-memory-web-api`;
console.info(`# Copy artifacts to ${distTargetDir}`);
rm('-rf', distTargetDir);
cp('-R', buildOutputDir, distTargetDir);
chmod('-R', 'u+w', distTargetDir);
console.info('');
}