Created
December 17, 2018 11:38
-
-
Save VanDalkvist/4d2af91a4793658d90c263dd00646b11 to your computer and use it in GitHub Desktop.
Run a pipeline of build scripts
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 path = require("path"); | |
const packageJson = require("./package"); | |
const buildConfig = packageJson.build; | |
if (!buildConfig) { | |
throw new Error("There is no configuration for build."); | |
} | |
const pipeline = buildConfig.pipeline; | |
if (!pipeline) { | |
throw new Error("There is no scripts pipeline configuration for build."); | |
} | |
const apps = buildConfig.apps; | |
if (!apps) { | |
throw new Error( | |
"Nothing to build. Check 'apps' section in your package.json file. 'apps' should be an array of app names you want to build" | |
); | |
} | |
console.log(`Running [${pipeline}] scripts for each app from list - [${apps}]`); | |
const tasks = apps.map(appName => _runPipelineForApp(appName, pipeline)); | |
Promise.all(tasks).catch(err => { | |
console.error("An error occurred: ", err); | |
process.exit(-1); | |
}); | |
async function _runPipelineForApp(appName, pipeline) { | |
return pipeline.reduce((res, scriptName) => { | |
return res.then(() => { | |
const scriptPath = path.resolve("build-tools", scriptName); | |
const runScript = require(scriptPath); | |
return runScript(appName); | |
}); | |
}, Promise.resolve()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment