in make.js [148:312]
target.build = function() {
target.clean();
ensureTool('tsc', '--version', 'Version 2.3.4');
ensureTool('npm', '--version', function (output) {
if (semver.lt(output, '5.6.0')) {
fail('Expected 5.6.0 or higher. To fix, run: npm install -g npm');
}
});
taskList.forEach(function(taskName) {
banner('Building: ' + taskName);
var taskPath = path.join(__dirname, 'Tasks', taskName);
ensureExists(taskPath);
// load the task.json
var outDir;
var shouldBuildNode = test('-f', path.join(taskPath, 'tsconfig.json'));
var taskJsonPath = path.join(taskPath, 'task.json');
if (test('-f', taskJsonPath)) {
var taskDef = fileToJson(taskJsonPath);
validateTask(taskDef);
// fixup the outDir (required for relative pathing in legacy L0 tests)
outDir = path.join(buildPath, taskName);
// create loc files
createTaskLocJson(taskPath);
createResjson(taskDef, taskPath);
// determine the type of task
shouldBuildNode = shouldBuildNode || supportedNodeTargets.some(node => taskDef.execution.hasOwnProperty(node));
}
else {
outDir = path.join(buildPath, path.basename(taskPath));
}
mkdir('-p', outDir);
// get externals
var taskMakePath = path.join(taskPath, 'make.json');
var taskMake = test('-f', taskMakePath) ? fileToJson(taskMakePath) : {};
if (taskMake.hasOwnProperty('externals')) {
console.log('');
console.log('> getting task externals');
getExternals(taskMake.externals, outDir);
}
//--------------------------------
// Common: build, copy, install
//--------------------------------
var commonPacks = [];
if (taskMake.hasOwnProperty('common')) {
var common = taskMake['common'];
common.forEach(function(mod) {
var modPath = path.join(taskPath, mod['module']);
var modName = path.basename(modPath);
var modOutDir = path.join(commonPath, modName);
if (!test('-d', modOutDir)) {
banner('Building module ' + modPath, true);
mkdir('-p', modOutDir);
// create loc files
var modJsonPath = path.join(modPath, 'module.json');
if (test('-f', modJsonPath)) {
createResjson(fileToJson(modJsonPath), modPath);
}
// npm install and compile
if ((mod.type === 'node' && mod.compile == true) || test('-f', path.join(modPath, 'tsconfig.json'))) {
buildNodeTask(modPath, modOutDir);
}
// copy default resources and any additional resources defined in the module's make.json
console.log();
console.log('> copying module resources');
var modMakePath = path.join(modPath, 'make.json');
var modMake = test('-f', modMakePath) ? fileToJson(modMakePath) : {};
copyTaskResources(modMake, modPath, modOutDir);
// get externals
if (modMake.hasOwnProperty('externals')) {
console.log('');
console.log('> getting module externals');
getExternals(modMake.externals, modOutDir);
}
if (mod.type === 'node' && mod.compile == true || test('-f', path.join(modPath, 'package.json'))) {
var commonPack = util.getCommonPackInfo(modOutDir);
// assert the pack file does not already exist (name should be unique)
if (test('-f', commonPack.packFilePath)) {
fail(`Pack file already exists: ${commonPack.packFilePath}`);
}
// pack the Node module. a pack file is required for dedupe.
// installing from a folder creates a symlink, and does not dedupe.
cd(path.dirname(modOutDir));
run(`npm pack ./${path.basename(modOutDir)}`);
}
}
// store the npm pack file info
if (mod.type === 'node' && mod.compile == true) {
commonPacks.push(util.getCommonPackInfo(modOutDir));
}
// copy ps module resources to the task output dir
else if (mod.type === 'ps') {
console.log();
console.log('> copying ps module to task');
var dest;
if (mod.hasOwnProperty('dest')) {
dest = path.join(outDir, mod.dest, modName);
}
else {
dest = path.join(outDir, 'ps_modules', modName);
}
matchCopy('!Tests', modOutDir, dest, { noRecurse: true, matchBase: true });
}
});
// npm install the common modules to the task dir
if (commonPacks.length) {
cd(taskPath);
var installPaths = commonPacks.map(function (commonPack) {
return `file:${path.relative(taskPath, commonPack.packFilePath)}`;
});
run(`npm install --save-exact ${installPaths.join(' ')}`);
}
}
// build Node task
if (shouldBuildNode) {
buildNodeTask(taskPath, outDir);
}
// remove the hashes for the common packages, they change every build
if (commonPacks.length) {
var lockFilePath = path.join(taskPath, 'package-lock.json');
if (!test('-f', lockFilePath)) {
lockFilePath = path.join(taskPath, 'npm-shrinkwrap.json');
}
var packageLock = fileToJson(lockFilePath);
Object.keys(packageLock.dependencies).forEach(function (dependencyName) {
commonPacks.forEach(function (commonPack) {
if (dependencyName == commonPack.packageName) {
delete packageLock.dependencies[dependencyName].integrity;
}
});
});
fs.writeFileSync(lockFilePath, JSON.stringify(packageLock, null, ' '));
}
// copy default resources and any additional resources defined in the task's make.json
console.log();
console.log('> copying task resources');
copyTaskResources(taskMake, taskPath, outDir);
});
banner('Build successful', true);
}