build: fix build scripts on macOS (#33854)

In #33823, `scripts/package-builds.sh` (which is used by both
`build-packages-dist.sh` and `build-ivy-npm-packages.sh`) was updated to
use `realpath`. It turns out that `realpath` does not exist on macOS, so
the build scripts do not work there.

In order to fix this (and also reduce the likelihood of introducing
similar issues in the future), this commit changes these bash scripts to
Node.js scripts (using [ShellJS](https://github.com/shelljs/shelljs) for
a cross-platform implementation of Unix shell commands where necessary).

PR Close #33854
This commit is contained in:
George Kalpakas
2019-11-15 02:56:55 +02:00
committed by Alex Rickabaugh
parent e641eaaae0
commit 5bfcd8231a
19 changed files with 203 additions and 134 deletions

40
scripts/build-packages-dist.js Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env node
'use strict';
const {chmod, cp, mkdir, rm} = require('shelljs');
const {
baseDir,
bazelBin,
bazelCmd,
buildTargetPackages,
exec,
scriptPath,
} = require('./package-builder');
// Build the legacy (view engine) npm packages into `dist/packages-dist/`.
buildTargetPackages('dist/packages-dist', 'legacy', 'Production');
// Build the `zone.js` npm package (into `dist/bin/packages/zone.js/npm_package/`), because it might
// be needed by other scripts/tests.
//
// NOTE: The `zone.js` package is not built as part of `buildTargetPackages()` above, nor is it
// copied into the `dist/packages-dist/` directory (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).
console.log('');
console.log('##############################');
console.log(`${scriptPath}:`);
console.log(' Building zone.js npm package');
console.log('##############################');
exec(`${bazelCmd} build //packages/zone.js:npm_package`);
// Copy artifacts to `dist/zone.js-dist/`, so they can be easier persisted on CI.
const buildOutputDir = `${bazelBin}/packages/zone.js/npm_package`;
const distTargetDir = `${baseDir}/dist/zone.js-dist/zone.js`;
console.log(`# Copy artifacts to ${distTargetDir}`);
mkdir('-p', distTargetDir);
rm('-rf', distTargetDir);
cp('-R', buildOutputDir, distTargetDir);
chmod('-R', 'u+w', distTargetDir);