build: replace `fs` methods with ShellJS' `test('-d')` (#33895)
This makes the JS script more similar to the original bash script it replaced (see #33854) and will be easier to follow for people that are less familiar with Node.js scripting. Discussed in: https://github.com/angular/angular/pull/33854#discussion_r346949765 PR Close #33895
This commit is contained in:
parent
a48573efe8
commit
e2cba6ed7d
|
@ -12,9 +12,8 @@
|
||||||
// copy the results to the appropriate `dist` location.
|
// copy the results to the appropriate `dist` location.
|
||||||
|
|
||||||
const {execSync} = require('child_process');
|
const {execSync} = require('child_process');
|
||||||
const {existsSync, statSync} = require('fs');
|
|
||||||
const {resolve, relative} = require('path');
|
const {resolve, relative} = require('path');
|
||||||
const {chmod, cp, mkdir, rm, set} = require('shelljs');
|
const {chmod, cp, mkdir, rm, set, test} = require('shelljs');
|
||||||
|
|
||||||
set('-e');
|
set('-e');
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ function buildTargetPackages(destPath, compileMode, description) {
|
||||||
|
|
||||||
// Create the output directory.
|
// Create the output directory.
|
||||||
const absDestPath = `${baseDir}/${destPath}`;
|
const absDestPath = `${baseDir}/${destPath}`;
|
||||||
if (!existsSync(absDestPath)) mkdir('-p', absDestPath);
|
if (!test('-d', absDestPath)) mkdir('-p', absDestPath);
|
||||||
|
|
||||||
targets.forEach(target => {
|
targets.forEach(target => {
|
||||||
const pkg = target.replace(/\/\/packages\/(.*):npm_package/, '$1');
|
const pkg = target.replace(/\/\/packages\/(.*):npm_package/, '$1');
|
||||||
|
@ -78,7 +77,7 @@ function buildTargetPackages(destPath, compileMode, description) {
|
||||||
const srcDir = `${bazelBin}/packages/${pkg}/npm_package`;
|
const srcDir = `${bazelBin}/packages/${pkg}/npm_package`;
|
||||||
const destDir = `${absDestPath}/${pkg}`;
|
const destDir = `${absDestPath}/${pkg}`;
|
||||||
|
|
||||||
if (existsSync(srcDir) && statSync(srcDir).isDirectory()) {
|
if (test('-d', srcDir)) {
|
||||||
console.log(`# Copy artifacts to ${destDir}`);
|
console.log(`# Copy artifacts to ${destDir}`);
|
||||||
rm('-rf', destDir);
|
rm('-rf', destDir);
|
||||||
cp('-R', srcDir, destDir);
|
cp('-R', srcDir, destDir);
|
||||||
|
|
Loading…
Reference in New Issue