-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathindex.js
More file actions
128 lines (117 loc) · 3.6 KB
/
index.js
File metadata and controls
128 lines (117 loc) · 3.6 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var ff = require('ff');
var chalk = require('chalk');
var logger = require('../util/logging').get('build');
var apps = require('../apps');
exports.build = function (appPath, argv, cb) {
var startTime = Date.now();
logger.log(chalk.cyan("starting build at", new Date()));
var config;
var elapsed = 0;
function onFinish(err, res) {
cb(err, merge({
elapsed: elapsed,
config: config
}, res));
}
var onlyGetConfig = argv['get-config'];
var app;
var _hasLock = false;
var f = ff(function () {
apps.has(appPath, f());
}, function (appLoaded) {
var next = f.wait();
apps.get(appPath, function (err, res) {
if (err && !argv.help) {
if (err.code == 'ENOENT') {
logger.error('the current directory is not a devkit app');
} else {
logger.error(err);
}
next(err);
} else {
app = res;
// ensure the manifest is up-to-date
try {
if (appLoaded) { app.reloadSync(); }
} catch (e) {
return next(e);
}
next();
}
});
}, function () {
// app.acquireLock(f());
}, function () {
// _hasLock = true;
require('./steps/getConfig').getConfig(app, argv, f());
}, function (res) {
config = res;
require('./steps/createDirectories').createDirectories(app, config, f());
}, function () {
require('./steps/buildHooks').getDependencies(app, config, f());
}, function (res) {
var modules = res.reduce(function (modules, res) {
var toRemove = Object.keys(res.data)
.filter(function (name) {
return res.data[name] === false;
});
if (toRemove.length) {
logger.log('module', res.module.name, 'getDependencies:');
toRemove.forEach(function (module) {
logger.log(' removing module', module);
});
}
return modules.concat(toRemove);
}, []);
app.removeModules(modules);
}, function () {
require('./steps/addDebugCode')(app, config, f());
}, function () {
require('./steps/moduleConfig').getConfig(app, config, f());
}, function () {
require('./steps/buildHooks').getResourceDirectories(app, config, f());
}, function (directories) {
config.directories = directories;
}, function () {
require('./steps/buildHooks').onBeforeBuild(app, config, f());
}, function () {
// Skip to success
if (onlyGetConfig) {
// ONLY print config to stdout
process.stdout.write(JSON.stringify(merge({title: app.manifest.title}, config)));
process.exit(0);
}
require('./steps/logConfig').log(app, config, f());
}, function () {
require('./steps/executeTargetBuild').build(app, config, f());
}, function () {
require('./steps/buildHooks').onAfterBuild(app, config, f());
})
.error(function (err) {
if (err.code == 'EEXIST' && !_hasLock) {
return logger.error('another build is already in progress');
}
logger.log(err, chalk.red('\nbuild failed'));
process.exit(1);
})
.success(function () {
logger.log("build succeeded");
})
.cb(function () {
if (_hasLock) {
app.releaseLock(function (err) {
if (err) {
logger.error(err);
}
});
}
elapsed = (Date.now() - startTime) / 1000;
var minutes = Math.floor(elapsed / 60);
var seconds = (elapsed % 60).toFixed(2);
logger.log((minutes ? minutes + ' minutes, ' : '') + seconds + ' seconds elapsed');
})
.cb(onFinish);
};
exports.showHelp = function (app, /* optional */ target) {
require('./steps/executeTargetBuild').showHelp(app, target);
};