-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
460 lines (411 loc) · 13.1 KB
/
Gruntfile.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
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
var spawn = require('child_process').spawn;
module.exports = function(grunt) {
'use strict';
var rubyLibs = [
'haml',
'sass',
'slim'
]
var webpackCallback = function(done) {
return function(err, stats) {
if (err) throw new Error(err)
if (stats.hasErrors()) {
grunt.log.error(
stats.toString({
chunks: false, // Makes the build much quieter
colors: false
}))
}
if (stats.hasWarnings()) {
grunt.log.write(
stats.toString({
chunks: false, // Makes the build much quieter
colors: false
}))
}
done();
}
}
function isRubyLib(lib) {
return rubyLibs.indexOf(lib) > -1
}
function filterGitLog(logs) {
// by default, the prop is gitlog.TARGET.result
// hacky, but only way to get target from existing data
var target = this.prop.split('.')[1];
var result = logs.map(log => {
let tag = log.tag.match(/tag: (v?\d+\.\d+(?:\.\d+)?)($|, )/)
if (tag) {
tag = tag[1]
} else {
return
}
return tag
})
.filter(tag => !!tag)
.reverse()
.forEach(tag => {
grunt.task.run([`build:${target}:${tag}`])
})
}
function opalPath(l) {
return {
'OPAL_LOAD_PATH': () => `${__dirname}/lib/rb/:${__dirname}/lib/${l}/lib/:${
grunt.file.expand([
'./ruby/*/gems/opal*/*',
'./ruby/*/gems/*/lib/',
'./ruby/*/bundler/gems/*/',
'./ruby/*/bundler/gems/*/lib/'
]).join(':')}`
}
}
// load grunt dependencies
require('load-grunt-tasks')(grunt);
grunt.initConfig({
env: {
slim: opalPath('slim'),
sass: opalPath('sass')
},
clean: {
autoprefixer: ['./dist/autoprefixer-*', './lib/autoprefixer/node_modules', './test/autoprefixer-suite.js'],
livescript: ['./dist/livescript-*', './lib/livescript/node_modules'],
stylus: ['./dist/stylus-*', './lib/stylus/node_modules'],
less: ['./dist/less-*', './lib/less/node_modules'],
jade: ['./dist/jade-*', './lib/pug/node_modules'],
pug: ['./dist/pug-*', './lib/pug/node_modules'],
haml: ['./dist/haml-*', './lib/haml/.bundle'],
slim: ['./dist/slim-*', './lib/slim/.bundle'],
sass: ['./dist/sass-*', './lib/sass/.bundle'],
RUBY: ['./Gemfile.lock', './ruby']
},
karma: {
options: {
files: [
{pattern: 'dist/*', included: false},
{pattern: 'lib/**/*', included: false},
'./lib/js/sinon.js',
'./test/currentTag.js',
'./lib/js/semver.min.js',
'./node_modules/expect.js/index.js',
'./node_modules/jquery/dist/jquery.min.js',
'./test/<%= grunt.config.get("lib") %>-suite.js'
]
},
full: {
configFile: 'karma.conf.js',
fullRun: true
},
fast: {
configFile: 'karma.conf.js',
browsers: ['Chrome']
}
},
gitlog: {
options: {
pretty: '{"tag": "%D", "hash": "%H"} --grunt-gitlog-separator--',
callback: filterGitLog
},
jade: {
options: {
cwd: './lib/pug',
to: '3196639',
from: '0.24.0'
},
},
pug: {
options: {
cwd: './lib/pug',
from: '1.11.0',
},
},
haml: {
options: {
cwd: './lib/haml',
from: '0.4.0'
},
},
livescript: {
options: {
cwd: './lib/livescript'
},
},
stylus: {
options: {
cwd: './lib/stylus',
from: '0.44.0^',
to: 'dev',
},
},
autoprefixer: {
options: {
cwd: './lib/autoprefixer'
},
},
slim: {
options: {
tags: true,
noWalk: true,
cwd: './lib/slim'
},
},
sass: {
options: {
cwd: './lib/sass',
from: '3.0.25'
},
},
less: {
options: {
cwd: './lib/less',
to: '3.x',
},
}
},
gitpull: {
autoprefixer: { options: { cwd: './lib/autoprefixer' } },
livescript: { options: { cwd: './lib/livescript' } },
stylus: { options: { cwd: './lib/stylus' } },
haml: { options: { cwd: './lib/haml' } },
less: { options: { cwd: './lib/less' } },
jade: { options: { cwd: './lib/pug', branch: 'master'} },
slim: { options: { cwd: './lib/slim' } },
sass: { options: { cwd: './lib/sass' } },
pug: { options: { cwd: './lib/pug' } }
},
gitcheckout: {
options: { branch: '<%= grunt.config.get("currentTag") %>' },
autoprefixer: { options: { cwd: './lib/autoprefixer' } },
livescript: { options: { cwd: './lib/livescript' } },
stylus: { options: { cwd: './lib/stylus' } },
haml: { options: { cwd: './lib/haml' } },
less: { options: { cwd: './lib/less' } },
jade: { options: { cwd: './lib/pug' } },
slim: { options: { cwd: './lib/slim' } },
sass: { options: { cwd: './lib/sass' } },
pug: { options: { cwd: './lib/pug' } }
},
gitapply: { options: {
patchFiles: '../../diffs/<%= grunt.config.get("lib") %>/<%= grunt.config.get("currentTag") %>.patch',
whitespace: 'fix'
},
slim: { options: { cwd: './lib/slim' } },
sass: { options: { cwd: './lib/sass' } }
},
gitreset: {
options: { mode: 'hard' },
livescript: { options: { cwd: './lib/livescript' } },
stylus: { options: { cwd: './lib/stylus' } },
haml: { options: { cwd: './lib/haml' } },
less: { options: { cwd: './lib/less' } },
jade: { options: { cwd: './lib/pug' } },
sass: { options: { cwd: './lib/sass' } },
slim: { options: { cwd: './lib/slim' } },
pug: { options: { cwd: './lib/pug' } }
},
'npm-command': {
options: {
cwd: './lib/<%= grunt.config.get("libPath") %>',
},
prune: {
options: {
cmd: 'prune'
}
},
update: {
options: {
cmd: 'update',
args: ['--cache-min', '31540000', '--production']
}
}
},
update: {
autoprefixer: { defaultBranch: 'master' },
livescript: { defaultBranch: 'master' },
jade: { defaultBranch: '1.11.0' },
stylus: { defaultBranch: 'dev' },
pug: { defaultBranch: 'master' },
haml: {defaultBranch: 'master'},
sass: {defaultBranch: 'stable'},
slim: {defaultBranch: 'master'},
less: { defaultBranch: '3.x' }
},
webpack: {
livescript: {},
stylus: {},
less: {},
jade: {},
sass: {},
slim: {},
pug: {},
},
testFile: {
jade: [
'./test/**/*.jade',
'./test/**/filters.cdata.jade',
'!./**/auxiliary/*',
'!./**/*extend*.jade',
'!./**/*filter*.jade',
'!./**/*include*.jade',
'!./**/append*/*.jade',
'!./**/mixin-hoist.jade',
'!./**/fixtures/**/*.jade',
'!./**/dependencies/*.jade',
],
pug: [
'./test/**/*.pug',
'!./test/anti-cases/**/*.pug',
'!./test/dependencies/**/*.pug'
],
less: [
'./test/less/**/*.less',
'!./test/less/*Plugin/*',
'!./test/less/debug/**/*',
'!./test/less/nested-*/**/*',
'!./test/**/*import*/**/*.less',
'!./test/less/**/functions.less',
'!./test/**/javascript-error.less',
'!./test/less/**/*Processor*/*.less'
],
sass: [
'./test/sass/**/*.sass',
'!./test/sass/**/_*.sass',
'!./test/sass/**/*bork*.sass',
'!./test/sass/**/*_imported.sass',
'!./test/sass/templates/subdir/**/*.sass',
'!./test/sass/templates/same_name_different_ext*'
],
slim: [],
haml: [],
livescript: [
'./test/*.ls',
'!./test/cli.ls',
'!./test/lib.ls',
'!./test/heredoc.ls',
'!./test/optparse.ls'
],
stylus: [ './test/cases/**/*.styl', './test/converter/**/*.styl' ],
}
});
grunt.registerMultiTask('webpack', 'run our webpack command', function() {
var done = this.async();
var tag = grunt.config.get('currentTag');
var lib = this.target;
var webpackPath = './node_modules/.bin/webpack'
// we do this via spawn instead of the webpack node API because opal-webpack
// checks the enviroment variable for OPAL_LOAD_PATH only at load time. Since
// this changes for us over time, we need to be in a clean state. deleting
// the loader via require.cache caused other errors, so this is the cleanest
// way to accomplish it
var cmd = isRubyLib(lib) ? 'bundler' : webpackPath
var args = [
'--output-path',
`${__dirname}/dist/`,
'--output-filename',
`${lib}-${tag}.min.js`,
'--config',
`${__dirname}/lib/${lib}.webpack.config.js`
]
if (isRubyLib(lib)) {
args = ['exec', webpackPath].concat(args)
}
var wP = spawn(cmd, args)
wP.stdout.on('data', (data) => {
grunt.log.write(data)
});
wP.stderr.on('data', (data) => {
grunt.log.error(data)
});
wP.on('close', done);
});
grunt.registerMultiTask('testFile', function() {
var webpack = require('webpack');
var done = this.async();
var lib = this.target;
// pug is the new name for jade, so they share a repo. So for loading files
// from said repo, we need to use the latest name - pug.
var libPath = (lib === 'jade') ? 'pug' : lib;
grunt.config.set('libPath', libPath);
var rewrite = function(files) {
return files.map(f => f.replace(/(^\.|\.[^.]+$)/g, ''))
.map(f => `/base/lib/${libPath}${f}`)
}
if (lib === 'autoprefixer') {
webpack('./test/autoprefixer-test.webpack.config', webpackCallback(() => {
clearRequire.all()
done();
}));
} else {
var files = rewrite(grunt.file.expand({ cwd: `./lib/${libPath}` }, this.data))
var tag = grunt.config.get('currentTag')
grunt.file.write('./test/currentTag.js', `
window.__testFiles=${JSON.stringify(files)};
window.__libVersion="${tag}";
window.__workerPath="/base/dist/${lib}-${tag}.min.js"
`)
done();
}
})
// ensure that each given project has pulled down all of the latests updates
grunt.registerMultiTask('update', function() {
var tag = this.data.defaultBranch;
grunt.config.set('currentTag', this.data.defaultBranch);
grunt.task.run([`gitreset:${this.target}`]);
grunt.task.run([`gitcheckout:${this.target}`]);
if (tag) {
grunt.task.run([`gitpull:${this.target}`]);
}
})
// update dependencies, and apply changes to the library to ready it for processing
grunt.registerTask('prepareLib', function(lib, tag) {
if (isRubyLib(lib)) {
grunt.task.run([`gitapply:${lib}`, 'clean:RUBY', `bundlerInstall:${lib}`, `env:${lib}`])
} else {
grunt.task.run(['npm-command:update', 'npm-command:prune']);
}
})
grunt.registerTask('bundlerInstall', function(lib) {
var done = this.async()
grunt.util.spawn({
cmd: 'bundler',
args: ['install', '--with', lib, '--without'].concat(rubyLibs.filter( l => l != lib))
}, function(err, result) {
if (err) {
grunt.log.error(result)
}
grunt.log.write(result)
done()
})
})
// delete the old files, update the projects, then get new tags (via log) and
// then trigger then build for each tag, then update again to switch back to
// latest commit to prevent commiting an old sha to our submodule
grunt.registerTask('generate', function(lib, full_run) {
if (full_run === 'undefined') {full_run = undefined};
grunt.config.set('FULL_RUN', !!full_run);
grunt.config.set('lib', lib);
grunt.task.run([`clean:${lib}`, `update:${lib}`, `gitlog:${lib}`, `update:${lib}`])
});
// create an individual build of the library. Called in a loop, with the results
// of the gitlog task
grunt.registerTask('build', function(lib, tag) {
grunt.config.set('lib', lib);
grunt.config.set('currentTag', tag);
var libPath = (lib === 'jade') ? 'pug' : lib;
grunt.config.set('libPath', libPath);
grunt.task.run([`gitreset:${lib}`, `gitcheckout:${lib}:${tag}`, `prepareLib:${lib}:${tag}`, grunt.config.get('FULL_RUN') ? `generateAndTestTag:${lib}:${tag}` : `generateTag:${lib}:${tag}`]);
})
// quickly generate files, by just testing the results in a local build of chrome
grunt.registerTask('generateTag', function(lib) {
grunt.task.run([`webpack:${lib}`, `testFile:${lib}`, 'karma:fast']);
});
// generate files, and test in browsers matched on saucelabs in the karma config
grunt.registerTask('generateAndTestTag', function(lib) {
grunt.task.run([`webpack:${lib}`, `testFile:${lib}`, 'karma:full'])
});
// generate files, and test in browsers matched on saucelabs in the karma config
grunt.registerTask('everything', function(full) {
Object
.keys(grunt.config.data.webpack)
.map(lib => grunt.task.run(`generate:${lib}:${full}`));
});
};