forked from kitspace/kitspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·312 lines (263 loc) · 8.19 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#!/usr/bin/env node
let config, uglifyjs
const ninjaBuildGen = require('ninja-build-gen')
const globule = require('globule')
const path = require('path')
if (process.argv[2] === 'production') {
config = 'production'
} else {
config = 'dev'
}
const ninja = ninjaBuildGen('1.5.1', 'build/')
ninja.header(`#generated from ${path.basename(module.filename)} \
with '${config}' config`)
// - Rules - #
ninja
.rule('copy')
.run('cp $in $out')
.description('$command')
ninja
.rule('remove')
.run('rm -rf $in')
.description('$command')
let browserify = `browserify --extension='.jsx' --transform [ babelify \
--presets [ react es2015 ] ]`
if (config === 'dev') {
browserify += ' --debug'
} else {
browserify += ' -g uglifyify'
}
const dependencies = Object.keys(require('./package.json').dependencies).filter(
name => name !== 'semantic-ui-css'
)
const excludes = `-x ${dependencies.join(' -x ')}`
const requires = `-r ${dependencies.join(' -r ')}`
let rule = ninja.rule('node-task')
if (config === 'production') {
rule.run(`node -- $in -- ${config} $out`)
} else {
//write to $out.d depfile in makefile format for ninja to keep track of deps
rule
.run(
`browserify --list $taskFile > $out.d \
&& if [ '$jsMain' != '' ]; then ${browserify} --list $jsMain >> $out.d; fi \
&& ./scripts/depfileify $out $out.d \
&& node -- $in -- ${config} $targetFiles`
)
.depfile('$out.d')
.description(`node -- $in -- ${config} $targetFiles`)
}
rule = ninja.rule('browserify')
if (config === 'production') {
let compress_opts = {
sequences: true, //join consecutive statements with the “comma operator”
properties: true, // optimize property access: a["foo"] → a.foo
dead_code: true, // discard unreachable code
drop_debugger: true, // discard “debugger” statements
unsafe: false, // some unsafe optimizations (see below)
conditionals: true, // optimize if-s and conditional expressions
comparisons: true, // optimize comparisons
evaluate: true, // evaluate constant expressions
booleans: true, // optimize boolean expressions
loops: true, // optimize loops
unused: false, // drop unused variables/functions
hoist_funs: true, // hoist function declarations
hoist_vars: false, // hoist variable declarations
if_return: true, // optimize if-s followed by return/continue
join_vars: true, // join var declarations
cascade: true, // try to cascade `right` into `left` in sequences
side_effects: true, // drop side-effect-free statements
warnings: true
}
compress_opts = Object.keys(compress_opts).map(key => {
return `${key}=${compress_opts[key]}`
})
uglifyjs = `uglifyjs --mangle --reserved '${dependencies}' \
--compress '${compress_opts}'`
rule.run(`${browserify} ${excludes} $in | ${uglifyjs} > $out`)
} else {
rule
.run(
`${browserify} ${excludes} --list $in > $out.d \
&& ./scripts/depfileify $out $out.d \
&& ${browserify} ${excludes} $in -o $out`
)
.depfile('$out.d')
.description(`browserify ${excludes} $in -o $out`)
}
rule = ninja.rule('browserify-require')
if (config === 'production') {
rule.run(`${browserify} ${requires} $in | ${uglifyjs} > $out`)
} else {
rule.run(`${browserify} ${requires} $in -o $out`)
}
ninja.rule('sass').run('node-sass --sourcemap=none --load-path $path $in $out')
ninja.rule('autoprefix')
.run(`postcss --use autoprefixer --autoprefixer.browsers \
"last 2 versions, > 1%, Safari >= 8, iOS >= 8, Firefox ESR, Opera 12.1"\
$in -o $out`)
// - Edges - #
ninja.edge('build/vendor.js').using('browserify-require')
const images = globule.find('src/images/**/*', {filter: 'isFile'})
for (var f of images) {
ninja
.edge(f.replace('src', 'build'))
.from(f)
.using('copy')
}
const boardFolders = globule.find('boards/*/*/*', {filter: 'isDirectory'})
const jsSrc = globule.find(['src/**/*.js', 'src/**/*.jsx'])
const jsMainTargets = jsSrc.map(function(f) {
const temp = f.replace('src', 'build/.temp')
ninja
.edge(temp)
.from(f)
.using('copy')
return temp
})
const jsPageTargets = {}
for (var folder of boardFolders) {
jsPageTargets[folder] = []
jsSrc.map(function(f) {
const temp = f.replace('src', `build/.temp/${folder}`)
jsPageTargets[folder].push(temp)
return ninja
.edge(temp)
.from(f)
.using('copy')
})
}
const sassSrc = globule.find('src/**/*.scss')
ninja
.edge('build/.temp/index.css')
.from('src/index/index.scss')
.need(sassSrc)
.assign('path', 'src/')
.using('sass')
ninja
.edge('build/.temp/page.css')
.from('src/page/page.scss')
.need(sassSrc)
.assign('path', 'src/')
.using('sass')
ninja
.edge('build/.temp/submit.css')
.from('src/submit/submit.scss')
.need(sassSrc)
.assign('path', 'src/')
.using('sass')
ninja
.edge('build/index.css')
.from('build/.temp/index.css')
.using('autoprefix')
ninja
.edge('build/page.css')
.from('build/.temp/page.css')
.using('autoprefix')
ninja
.edge('build/submit.css')
.from('build/.temp/submit.css')
.using('autoprefix')
ninja
.edge('build/app.js')
.from('build/.temp/index/render_index.jsx')
.need(jsMainTargets)
.need('build/.temp/boards.json')
.using('browserify')
ninja
.edge('build/submit/app.js')
.from('build/.temp/submit/render_submit.jsx')
.need(jsMainTargets)
.using('browserify')
for (folder of boardFolders) {
ninja
.edge(`build/${folder}/app.js`)
.need(`build/.temp/${folder}/info.json`)
.need(`build/.temp/${folder}/zip-info.json`)
.need(`build/.temp/${folder}/readme.jsx`)
.need(jsPageTargets[folder])
.from(`build/.temp/${folder}/page/render_page.jsx`)
.using('browserify')
}
function addEdge(taskFile, task) {
if (config === 'production') {
return ninja
.edge(task.targets.map(ninjaBuildGen.escape))
.from([taskFile].concat(task.deps).map(ninjaBuildGen.escape))
.using('node-task')
} else {
const edge = ninja
.edge(ninjaBuildGen.escape(task.targets[0]))
.from([taskFile].concat(task.deps).map(ninjaBuildGen.escape))
.assign('taskFile', taskFile)
.assign('targetFiles', task.targets.join(' '))
.using('node-task')
if (task.moduleDep) {
edge.assign('jsMain', task.deps[0])
}
task.targets
.slice(1)
.map(target => ninja.edge(target).from(task.targets[0]))
}
}
globule.find('tasks/*.js').forEach(taskFile => {
const task = require(`./${path.dirname(taskFile)}/${path.basename(taskFile)}`)
addEdge(taskFile, task(config))
})
globule.find('tasks/page/*.js').forEach(taskFile => {
const task = require(`./${path.dirname(taskFile)}/${path.basename(taskFile)}`)
boardFolders.forEach(folder => addEdge(taskFile, task(config, folder)))
})
if (config === 'production') {
const presentation_folders = globule.find(
path.join(__dirname, 'presentations/*'),
{filter: 'isDirectory'}
)
presentation_folders.forEach(folder => {
globule.find(path.join(folder, '**/*'), {filter: 'isFile'}).forEach(f => {
ninja
.edge(path.join('build', path.relative('presentations', f)))
.from(f)
.using('copy')
})
})
ninja
.edge('build/_redirects')
.from('src/_redirects')
.using('copy')
ninja
.edge('build/_headers')
.from('src/_headers')
.using('copy')
}
ninja
.rule('sed')
.run("sed -e 's/themes\\/default\\/assets\\/images\\/flags\\.png/\\/images\\/flags.png/' $in > $out")
.description('$command')
ninja
.edge('build/semantic.min.css')
.from('node_modules/semantic-ui-css/semantic.min.css')
.using('sed')
globule
.find('node_modules/semantic-ui-css/themes/default/assets/fonts/*')
.forEach(file => {
ninja
.edge(file.replace('node_modules/semantic-ui-css', 'build'))
.from(file)
.using('copy')
})
ninja
.edge('build/images/flags.png')
.from('node_modules/semantic-ui-css/themes/default/assets/images/flags.png')
.using('copy')
ninja
.edge('clean')
.from('build/')
.using('remove')
const all = ninja.edges
.filter(c => !c.targets.includes('clean'))
.reduce((prev, c) => prev.concat(c.targets), [])
ninja.edge('all').from(all)
ninja.byDefault('all')
ninja.save('build.ninja')
console.log(`generated ./build.ninja with '${config}' config`)