From e2cba6ed7da30d3b8ab669f2241bd71b350326eb Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 18 Nov 2019 16:33:24 +0200 Subject: [PATCH] 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 --- scripts/package-builder.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/package-builder.js b/scripts/package-builder.js index f7205a993d..b120f4e8b3 100755 --- a/scripts/package-builder.js +++ b/scripts/package-builder.js @@ -12,9 +12,8 @@ // copy the results to the appropriate `dist` location. const {execSync} = require('child_process'); -const {existsSync, statSync} = require('fs'); const {resolve, relative} = require('path'); -const {chmod, cp, mkdir, rm, set} = require('shelljs'); +const {chmod, cp, mkdir, rm, set, test} = require('shelljs'); set('-e'); @@ -69,7 +68,7 @@ function buildTargetPackages(destPath, compileMode, description) { // Create the output directory. const absDestPath = `${baseDir}/${destPath}`; - if (!existsSync(absDestPath)) mkdir('-p', absDestPath); + if (!test('-d', absDestPath)) mkdir('-p', absDestPath); targets.forEach(target => { 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 destDir = `${absDestPath}/${pkg}`; - if (existsSync(srcDir) && statSync(srcDir).isDirectory()) { + if (test('-d', srcDir)) { console.log(`# Copy artifacts to ${destDir}`); rm('-rf', destDir); cp('-R', srcDir, destDir);