Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async build({
tree, destPath, cleanDest = false,
buildDependencies = false, includedDependencies = [], excludedDependencies = [],
dev = false, selfContained = false, jsdoc = false,
includedTasks = [], excludedTasks = [], devExcludeProject = []
}) {
const startTime = process.hrtime();
log.info(`Building project ${tree.metadata.name}` + (buildDependencies ? "" : " not") +
" including dependencies..." + (dev ? " [dev mode]" : ""));
log.verbose(`Building to ${destPath}...`);
const selectedTasks = composeTaskList({dev, selfContained, jsdoc, includedTasks, excludedTasks});
const fsTarget = resourceFactory.createAdapter({
fsBasePath: destPath,
virBasePath: "/"
});
const buildContext = new BuildContext();
const cleanupSigHooks = registerCleanupSigHooks(buildContext);
const projects = {}; // Unique project index to prevent building the same project multiple times
const projectWriters = {}; // Collection of memory adapters of already built libraries
function projectFilter(project) {
function projectMatchesAny(deps) {
return deps.some((dep) => dep instanceof RegExp ?
dep.test(project.metadata.name) : dep === project.metadata.name);
}
// if everything is included, this overrules exclude lists
async function writeDependencyApisToDir({dependencies, targetPath}) {
const depApis = await dependencies.byGlob("/test-resources/**/designtime/api.json");
// Clone resources before changing their path
const apis = await Promise.all(depApis.map((resource) => resource.clone()));
for (let i = 0; i < apis.length; i++) {
apis[i].setPath(`/api-${i}.json`);
}
const fsTarget = resourceFactory.createAdapter({
fsBasePath: targetPath,
virBasePath: "/"
});
await Promise.all(apis.map((resource) => fsTarget.write(resource)));
return apis.length;
}
async function writeResourcesToDir({workspace, pattern, targetPath}) {
const fsTarget = resourceFactory.createAdapter({
fsBasePath: targetPath,
virBasePath: "/resources/"
});
let allResources;
if (workspace.byGlobSource) { // API only available on duplex collections
allResources = await workspace.byGlobSource(pattern);
} else {
allResources = await workspace.byGlob(pattern);
}
// write all resources to the tmp folder
await Promise.all(allResources.map((resource) => fsTarget.write(resource)));
return allResources.length;
}