Created
November 29, 2018 12:44
-
-
Save dannyockilson/b25ae96d7563c7eb3689d813e56d58ce to your computer and use it in GitHub Desktop.
Quick node script to build multiple angular libraries (zero deps, tested on node 8 LTS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn } = require('child_process'); | |
const fileName = './angular.json'; | |
let file; | |
try { | |
file = require(fileName); | |
} catch(e) { | |
console.error(e); | |
process.exit(1); | |
} | |
if(!file.projects) { | |
console.error('No projects found in angular.json file'); | |
process.exit(1); | |
} | |
const libraries = Object.keys(file.projects).filter((name) => file.projects[name].projectType == "library"); | |
if(!libraries || libraries.length == 0) { | |
console.warn('No libraries found in current angular project, nothing to build'); | |
// throw exit code 0 cause technically everything that "should" be built was... | |
process.exit(0); | |
} | |
async function buildLibrary(name) { | |
const build = spawn('npx', ['ng', 'build', name]); | |
build.stdout.on('data', data => console.log(data.toString())); | |
build.stdout.on('end', _ => console.log(`Finished building ${name} library`)); | |
build.on('exit', code => { | |
if(code != 0) { | |
throw `Failed to build library ${name}`; | |
} | |
return; | |
}) | |
} | |
async function buildAllLibraries(libraries) { | |
for(let i = 0; i < libraries.length; i++) { | |
await buildLibrary(libraries[i]); | |
} | |
} | |
try { | |
buildAllLibraries(libraries); | |
} catch(e) { | |
console.error(e); | |
process.exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment