forked from criticalmanufacturing/dev-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
110 lines (94 loc) · 3.86 KB
/
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var utils = require('./utils.js');
var __CONSTANTS = require('./context.json');
var pluginUtil = require('gulp-util');
var pluginArgs = require('yargs').argv;
// Override maximum numbers of Event Emitter listeners
require('events').EventEmitter.prototype._maxListeners = 100;
var path = require('path');
var pluginWebServer = require('gulp-webserver');
var pluginExec = require('child_process').exec;
var pluginExecSync = require('child_process').execSync;
module.exports = function (gulp, ctx) {
var gulpWrapper = require('./gulp.wrappers.js')(gulp, ctx);
ctx["__CONSTANTS"] = __CONSTANTS;
// Read some properties
if(!("__verbose" in ctx)) {
ctx["__verbose"] = pluginArgs.d || pluginArgs.debug || pluginArgs.verbose;
}
// Repository root is a context variable almost always unnecessary.
// For that reason is here defined as a getter instead of directly calculating its
if (!("__repositoryRoot" in ctx)) {
Object.defineProperty(ctx, "__repositoryRoot", {
configurable: true,
enumerable: true,
get: function(){
return path.normalize(path.join(__dirname, "../../.."));
}
});
}
// Project name is a context variable costly to calculate but not always necessary.
// For that reason is here defined as a getter instead of always getting the value
Object.defineProperty(ctx, "__projectName", {
configurable: true,
enumerable: true,
get: function(){
var currentProjectPackageFile = utils.fs.tryGetJSONSync(path.normalize(path.join(ctx.__repositoryRoot, "./package.json")));
return currentProjectPackageFile ? currentProjectPackageFile.name : "Custom";
}
});
// Configuration file
if (!ctx.__config) {
// Load the file from the system
var configFilePath = path.join(ctx.__repositoryRoot, '.dev-tasks.json');
try {
ctx.__config = require(configFilePath);
} catch(error) {
pluginUtil.log(pluginUtil.colors.yellow("Unable to find '.dev-tasks'. Continuing..."));
ctx.__config = {};
}
}
Object.defineProperty(ctx.__config, "__npm", {
configurable: true,
enumerable: true,
get: function(){
return ctx.__config.npm ? path.resolve(path.join(ctx.__repositoryRoot, ctx.__config.npm)) : null;
}
});
// Package prefix
if (!ctx.packagePrefix) {
ctx.packagePrefix = ctx.__config.packagePrefix || "cmf";
}
ctx.isCustomized = ctx.packagePrefix !== "cmf.core" && ctx.packagePrefix !== "cmf.mes";
if (gulp == null) {return;}
// Load metadata file
ctx.metadataFileName = ctx.metadataFileName || ".cmf-dev-tasks.cmf";
ctx.metadata = ctx.metadata || utils.fs.tryGetJSONSync(ctx.baseDir + '\\' + ctx.metadataFileName);
// Register all build related tasks
var buildTasksFunction = require('./build.js');
buildTasksFunction(gulpWrapper, ctx);
// Register all tasks related with Package Management
require('./install/package.management.js')(gulpWrapper, ctx);
// Register all tasks related with CI
require('./ci/index.js')(gulpWrapper, ctx);
/**
* List top level tasks
*/
gulpWrapper.gulp.task('tasks', function () { console.log(Object.keys(gulp.tasks).filter(function (item) { return item.indexOf('>') < 0; })); });
return {
gulp: gulpWrapper.gulp,
plugins: {
seq: gulpWrapper.seq,
exec: pluginExec,
build: buildTasksFunction.plugins,
webserver: pluginWebServer,
yargs: require('yargs'),
gulpWrapper: gulpWrapper
},
tasks: {
build: buildTasksFunction,
web: require('./web.main.js')
},
tests: {
}
};
}