You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
3 years ago
|
"use strict";
|
||
|
|
||
|
const defaultValue = require("default-value");
|
||
|
const mapObj = require("map-obj");
|
||
|
|
||
|
module.exports = function createDependencyMap(configuration) {
|
||
|
let dependencyMap = mapObj(configuration.tasks, (task, definition) => {
|
||
|
return [
|
||
|
task,
|
||
|
defaultValue(definition.dependsOn, []).map((dependencyName) => {
|
||
|
let dependency = configuration.tasks[dependencyName];
|
||
|
|
||
|
if (dependency != null) {
|
||
|
return {
|
||
|
task: dependencyName,
|
||
|
// TODO: Do defaults processing in configuration loading/validation instead
|
||
|
taskVersion: defaultValue(dependency.version, "0")
|
||
|
};
|
||
|
} else {
|
||
|
throw new Error(`Invalid dependency specified, task does not exist: ${dependencyName}`);
|
||
|
}
|
||
|
})
|
||
|
];
|
||
|
});
|
||
|
|
||
|
// NOTE: When inverting the dependencyMap, we totally ignore the taskVersion of dependencies when keying this mapping. While the taskVersion of specific tasks *may* matter to the code that uses these mappings, we don't support more than one version of a task simultaneously existing, and so keying by the task name alone is sufficient.
|
||
|
let dependentMap = {};
|
||
|
|
||
|
for (let [ task, dependencies ] of Object.entries(dependencyMap)) {
|
||
|
let taskDefinition = configuration.tasks[task];
|
||
|
|
||
|
for (let dependency of dependencies) {
|
||
|
if (dependentMap[dependency.task] == null) {
|
||
|
dependentMap[dependency.task] = [];
|
||
|
}
|
||
|
|
||
|
dependentMap[dependency.task].push({
|
||
|
task: task,
|
||
|
taskVersion: defaultValue(taskDefinition.version, "0")
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
dependencyMap,
|
||
|
dependentMap
|
||
|
};
|
||
|
};
|