-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathbuildHooks.js
More file actions
94 lines (84 loc) · 2.56 KB
/
buildHooks.js
File metadata and controls
94 lines (84 loc) · 2.56 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
var path = require('path');
var Promise = require('bluebird');
var api = require('../../api');
var DirectoryBuilder = require('../DirectoryBuilder');
var fs = require('fs');
var readDir = Promise.promisify(fs.readdir);
var stat = Promise.promisify(fs.stat);
exports.getDependencies = function (app, config, cb) {
app.reloadModules();
// allows modules to disable other modules
executeHook('getDependencies', app, config)
.nodeify(cb);
};
exports.onBeforeBuild = function (app, config, cb) {
executeHook('onBeforeBuild', app, config)
.nodeify(cb);
};
exports.onAfterBuild = function (app, config, cb) {
executeHook('onAfterBuild', app, config)
.nodeify(cb);
};
exports.getResourceDirectories = function (app, config, cb) {
var builder = new DirectoryBuilder(app.paths.root);
builder.add('resources');
executeHook('getResourceDirectories', app, config)
.map(function (res) {
var module = res.module;
var directories = res.data;
directories.forEach(function (directory) {
var target = path.join('modules', module.name, directory.target);
builder.add(directory.src, target);
});
console.log(res);
})
.then(function () {
// add any localized resource directories
return readDir(app.paths.root);
})
.filter(function (filename) {
if (/^resources-/.test(filename)) {
return stat(path.join(app.paths.root, filename)).then(function (info) {
return info.isDirectory();
}, function onStatFail() {
return false;
});
}
return false;
})
.map(function (filename) {
builder.add(filename);
})
.then(function () {
return builder.getDirectories();
})
.nodeify(cb);
};
function executeHook(buildHook, app, config) {
var modules = app.getModules();
return Promise.resolve(Object.keys(modules))
.map(function (moduleName) {
var module = modules[moduleName];
var buildExtension = module.loadExtension('build');
if (!buildExtension || !buildExtension[buildHook]) {
return;
}
return new Promise(function (resolve, reject) {
var retVal = buildExtension[buildHook](api, app.toJSON(), config, function (err, res) {
if (err) {
reject(err);
} else {
resolve(res);
}
});
if (retVal) { resolve(retVal); }
})
.then(function (data) {
return {
module: module,
data: data
};
});
})
.filter(function (res) { return res; });
}