forked from criticalmanufacturing/dev-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.main.js
80 lines (68 loc) · 3.09 KB
/
root.main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var path = require("path");
var utils = require("./utils");
module.exports = {
/**
* Run operation for Repository
*
* @param rootDir {string} Root directory of the repository
* @param dependencies {Array} Array of dependencies
* @param framework {string} Framework name
* @param packages {Array} Array of packages
* @param apps {Array} Array of application names
* @param operation {string} operation to run
* @param callback {Function} Callback function to call at the end
* @param buildFramework {boolean} Should we included the framework on the operation?
* @param buildApps {boolean} Should we include the apps on the operation?
*/
runOperation: function(rootDir, dependencies, framework, packages, apps, operation, callback, buildFramework = true, buildApps = true) {
var self = this;
var dependencyOperations = self.createOperations(path.join(rootDir, "dependencies"), dependencies, operation);
utils.cmd.runMany(dependencyOperations, function() {
var frameworkOperations = [];
if (buildFramework === true) {
frameworkOperations = self.createOperations(path.join(rootDir, "src"), [framework], operation);
}
var packageOperations = frameworkOperations.concat(self.createOperations(path.join(rootDir, "src", "packages"), packages, operation));
utils.cmd.runMany(packageOperations, function(){
if (buildApps === true) {
var appsOperations = self.createOperations(path.join(rootDir, "apps"), apps, operation);
utils.cmd.runMany(appsOperations, callback);
}else{
callback();
}
}, 4);
});
},
/**
* Create spawn operations
* @param baseDir {string} Base directory
* @param projects {Array} Projects to create the operations for
* @param actions {Array} Actions to call for each project
*/
createOperations: function(baseDir, projects, actions) {
var pluginYargs = require('yargs').argv;
if (!Array.isArray(actions)) { actions = [actions]; }
if (!baseDir) throw new Error("baseDir cannot be null");
if (!projects) throw new Error("Projects cannot be null");
var args = [], operations = [];
if(pluginYargs){
var keys = Object.keys(pluginYargs);
keys = keys.filter(function(key){
return !(key.startsWith("_") || key.startsWith("$") || key === "gulpfile");
});
args = keys.map(function(key){
return "--" + key;
});
}
projects.forEach(function (project) {
actions.forEach(function (action) {
operations.push({
command: '\"' + process.execPath + '\"',
arguments: [path.join(__dirname, "../", "gulp", "bin", "gulp.js"), action].concat(args),
cwd: path.join(baseDir, project)
});
});
});
return operations;
}
};