-
Notifications
You must be signed in to change notification settings - Fork 13
/
configure
executable file
·181 lines (149 loc) · 4.82 KB
/
configure
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env node
'use strict'
const fs = require('fs')
const globule = require('globule')
const path = require('path')
const cp = require('child_process')
const ninjaBuildGen = require('ninja-build-gen')
const version = '1.8.7'
const ninja = ninjaBuildGen('1.5.1', 'build/')
ninja.header(`#generated from ${path.basename(module.filename)}`)
const presets = '--presets es2015-script'
const browserify = `browserify -x $exclude --transform [ babelify ${presets} ]`
//- Rules -
ninja.rule('copy').run('cp $in $out')
ninja.rule('babel').run(`babel ${presets} --source-maps false $in -o $out`)
//browserify and put dependency list in $out.d in makefile format using
//relative paths
ninja
.rule('browserify')
.run(
`${browserify} $in --list > $out.d ` +
`&& node ./depfileify.js $out $out.d && ${browserify} $in -o $out`
)
.depfile('$out.d')
.description('browserify $in -o $out')
ninja
.rule('browserify-require')
.run(
"browserify --require='./$in' --list > $out.d" +
"&& node ./depfileify.js $out $out.d && browserify --require='./$in' -o $out"
)
.depfile('$out.d')
.description('browserify $in -o $out')
ninja.rule('sed').run("sed 's$regex' $in > $out")
ninja.rule('remove').run('rm -rf $in')
//- Lists of Files -
const sourceJs = browser =>
globule.find([`src/${browser}/js/**/*.js`, 'src/common/js/*.js'])
const sourceJson = browser =>
globule.find([`src/${browser}/data/*.json`, 'src/common/data/*.json'])
const copyFiles = browser =>
globule.find([
`src/${browser}/html/*`,
`src/${browser}/images/*`,
'src/common/html/*',
'src/common/images/*'
])
//- Edges -
const targets = {chrome: []}
const browserifyEdge = function(target, browser, layer, exclude = '') {
const edge = ninja
.edge(target)
.from(`build/.temp-${browser}/${layer}.js`)
.assign('exclude', exclude)
.after(
sourceJs(browser).map(
f => `build/.temp-${browser}/${path.basename(f)}`
)
)
.using('browserify')
if (browser === 'chrome') {
edge.after(
sourceJson('chrome').map(
f => `build/.temp-chrome/data/${path.basename(f)}`
)
)
}
return targets[browser].push(target)
}
;['main', 'popup', 'options', 'kitspace'].forEach(layer => {
browserifyEdge(`build/chrome/js/${layer}.js`, 'chrome', layer)
})
for (const browser in targets) {
sourceJs(browser).forEach(f => {
const target = `build/.temp-${browser}/${path.basename(f)}`
ninja
.edge(target)
.from(f)
.using('copy')
})
}
sourceJson('chrome').forEach(f => {
const target = `build/.temp-chrome/data/${path.basename(f)}`
ninja
.edge(target)
.from(f)
.using('copy')
})
const qunitSrc = 'build/.temp-chrome/qunit-1.11.0.js'
ninja
.edge('build/chrome/js/qunit.js')
.from(qunitSrc)
.using('browserify-require')
targets.chrome.push('build/chrome/js/qunit.js')
ninja
.edge('build/chrome/js/unit.js')
.from('build/.temp-chrome/unit.js')
.assign('exclude', qunitSrc)
.using('browserify')
targets.chrome.push('build/chrome/js/unit.js')
ninja
.edge('build/chrome/js/functional.js')
.from('build/.temp-chrome/functional.js')
.assign('exclude', qunitSrc)
.using('browserify')
targets.chrome.push('build/chrome/js/functional.js')
copyFiles('chrome').forEach(f => {
const target = f.replace(/src\/.*?\//, 'build/chrome/')
ninja
.edge(target)
.from(f)
.using('copy')
targets.chrome.push(target)
})
for (const browser in targets) {
const list = targets[browser]
ninja.edge(browser).from(list)
}
const manifest = 'build/chrome/manifest.json'
ninja
.edge(manifest)
.from(manifest.replace('build', 'src'))
.assign('regex', `/@version/\"${version}\"/`)
.using('sed')
targets.chrome.push(manifest)
const chrome_package_name = `1clickBOM-v${version}-chrome`
ninja
.rule('package-chrome')
.run(
`cd build/ && cp -r chrome ${chrome_package_name}` +
`&& rm -f ${chrome_package_name}/js/functional.js ` +
`${chrome_package_name}/js/unit.js ${chrome_package_name}/js/qunit.js ` +
`${chrome_package_name}/html/test.html ${chrome_package_name}/html/qunit-1.11.0.css` +
`&& cd ${chrome_package_name} && zip -r ../${chrome_package_name}.zip * ` +
`&& cd .. && rm -rf ${chrome_package_name}`
)
ninja
.edge(`${chrome_package_name}.zip`)
.need('chrome')
.using('package-chrome')
ninja.edge('package-chrome').need(`${chrome_package_name}.zip`)
ninja.edge('all').from(Object.keys(targets))
ninja.byDefault('all')
ninja
.edge('clean')
.from('build/')
.using('remove')
ninja.save('build.ninja')
console.log('generated build.ninja')