Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function builder(version: string, config: BuildSchema): Promise {
// log we are starting the shared build tasks
log(`${colors.bgBlue(" ")} Beginning shared build tasks.`);
try {
// run global tasks
await Promise.all(config.tasks.map(task => task(version, config)));
log(`${colors.bgGreen(" ")} Finished shared build tasks.`);
} catch (e) {
log(`${colors.bgRed(" ")} ${colors.bold(colors.red(`Error in shared build tasks.`))}.`);
log(`${colors.bgRed(" ")} ${colors.bold(colors.red("Error:"))} ${colors.bold(colors.white(typeof e === "string" ? e : JSON.stringify(e)))}`);
throw e;
}
// run the per package tasks
// establish the context that will be passed through all the build pipeline functions
const buildContext: BuildContext = {
assets: pkg.assets || config.assets,
name: pkg.name,
projectFile: projectFile,
projectFolder: projectFolder,
targetFolder: path.join(projectFolder, tsconfigObj.compilerOptions.outDir),
tsconfigObj: tsconfigObj,
version: version,
};
// select the correct build pipeline
const activeBuildPipeline = pkg.buildPipeline || config.buildPipeline;
// log we have added the file
log(`${colors.bgBlue(" ")} Adding ${colors.cyan(buildContext.projectFile)} to the build pipeline.`);
return activeBuildPipeline.reduce((subPipe, func) => subPipe.then(() => func(buildContext)), pipe).then(_ => {
log(`${colors.bgGreen(" ")} Built ${colors.cyan(buildContext.projectFile)}.`);
}).catch(e => {
log(`${colors.bgRed(" ")} ${colors.bold(colors.red(`Error building `))} ${colors.bold(colors.cyan(buildContext.projectFile))}.`);
log(`${colors.bgRed(" ")} ${colors.bold(colors.red("Error:"))} ${colors.bold(colors.white(typeof e === "string" ? e : JSON.stringify(e)))}`);
});
}, Promise.resolve());
}
promises.push(new Promise((resolve, reject) => {
const packagePath = path.resolve(publishRoot, packageFolders[i]);
log(`${colors.bgBlue(" ")} Publishing BETA ${packagePath}`);
exec("npm publish --tag beta --access public",
{
cwd: path.resolve(publishRoot, packageFolders[i]),
}, (error, stdout, stderr) => {
if (error === null) {
log(`${colors.bgGreen(" ")} Published BETA ${packagePath}`);
resolve();
} else {
console.error(error);
reject(stdout);
}
});
}));
}
promises.push(new Promise((resolve, reject) => {
const packagePath = path.resolve(publishRoot, packageFolders[i]);
log(`${colors.bgBlue(" ")} Publishing ${packagePath}`);
exec("npm publish --access public",
{
cwd: path.resolve(publishRoot, packageFolders[i]),
}, (error, stdout, stderr) => {
if (error === null) {
log(`${colors.bgGreen(" ")} Published ${packagePath}`);
resolve();
} else {
console.error(error);
reject(error);
}
});
}));
}
new server(webpack(config), serverSettings).listen(8080, "localhost", (err) => {
if (err) {
return done(new gutil.PluginError("serve", err));
}
log("File will be served from:", colors.bgBlue(colors.white("https://localhost:8080/assets/pnp.js")));
});
});
gulp.task('clean', (done) => {
if (yargs.noclean || yargs.nc) {
log(`${colors.bgWhite(" ")} Skipping clean due to flag.`);
return done();
}
const directories = [
"./dist",
"./serve",
"./site",
];
log(`${colors.bgBlue(" ")} Cleaning directories: ${directories.join(", ")}.`);
del(directories).then(() => {
log(`${colors.bgGreen(" ")} Cleaned directories: ${directories.join(", ")}.`);
done();
}).catch(e => {
log(`${colors.bgRed(" ")} Error cleaning directories: ${directories.join(", ")}.`);
done(e);
});
});
async function runTasks(name: string, version: string, tasks: PackageTask[], config: PackageSchema): Promise {
log(`${colors.bgBlue(" ")} Beginning (${tasks.length}) ${name} tasks.`);
for (let i = 0; i < tasks.length; i++) {
const task = tasks[i];
if (typeof task === "undefined" || task === null) {
continue;
}
if (typeof task === "function") {
await task(version, config);
} else {
await task.task(version, config, task.packages);
}
}
log(`${colors.bgGreen(" ")} Finished ${name} tasks.`);
}
async function runTasks(name: string, version: string, tasks: PublishTask[], config: PublishSchema): Promise {
log(`${colors.bgBlue(" ")} Beginning (${tasks.length}) ${name} tasks.`);
for (let i = 0; i < tasks.length; i++) {
const task = tasks[i];
if (typeof task === "undefined" || task === null) {
continue;
}
if (typeof task === "function") {
await task(version, config);
} else {
await task.task(version, config, task.packages);
}
}
log(`${colors.bgGreen(" ")} Finished ${name} tasks.`);
}