This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbuild.js
69 lines (58 loc) · 1.56 KB
/
build.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
var fs = require('fs')
var cp = require('child_process')
task = process.argv.reduce(function(memo, arg) {
if(memo === false && arg.match(/build/)) {
return null
}
if(memo === null) {
return arg
}
return memo
}, false) || 'default'
if(task === 'build') {
var children = collectTasks()
initTasks(children)
runTasks(children)
} else {
var child = cp.fork('./tasks')
child.send(task)
if (task !== 'serve' && task !== 'watch') {
child.on('message', process.exit)
}
}
function collectTasks() {
var tasks = fs.readdirSync('./app/lib/i18n/translations').map(function(f){
return f.replace('.json', '')
}).map(function(language) {
process.env.LANGUAGE = language
var scripts = cp.fork('./tasks', {env: process.env})
return [scripts, ['scripts', 'loaderNope']]
})
delete process.env.LANGUAGE
var others = cp.fork('./tasks')
tasks.push([others, ['html', 'styles', 'images', 'loaderIndex']])
return tasks;
}
function initTasks(children) {
children.forEach(function(pair) {
var child = pair[0]
child.on('message', maybeDone)
})
var childCount = children.length
function maybeDone() {
childCount--
if(children.length > 0) {
var next = children.splice(0, 1)[0]
next[0].send(next[1])
} else if(childCount === 0){
process.exit()
}
}
}
function runTasks(children) {
var processCount = process.env.PROCESS_COUNT || 4
console.info('Max number of concurrent build processes:', processCount)
children.splice(0, processCount).forEach(function(pair){
pair[0].send(pair[1])
})
}