-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
70 lines (61 loc) · 2.19 KB
/
gulpfile.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
var gulp = require('gulp'),
browserify = require('browserify'),
coffeeify = require('coffeeify'),
source = require('vinyl-source-stream'),
minify = require('gulp-minify'),
buffer = require('vinyl-buffer'),
gutil = require('gulp-util'),
coffee = require('gulp-coffee'),
through = require('through');
function string_src(filename, string) {
var src = require('stream').Readable({ objectMode: true })
src._read = function () {
this.push(new gutil.File({
cwd: "",
base: "",
path: filename,
contents: new Buffer(string)
}))
this.push(null)
}
return src
}
gulp.task('generate-grammar-js', function() {
return gulp.src('./src/compiler/parser/grammar.coffee')
.pipe(coffee({ bare: true }))
.pipe(gulp.dest('./build/'));
});
gulp.task('generate-parser', ['generate-grammar-js'], function() {
var parserCode = require('./build/grammar.js').parser.generate();
return string_src("parser.js", parserCode)
.pipe(gulp.dest('./src/compiler/parser/'))
});
gulp.task('build', ['generate-parser'], function() {
return browserify('./index.coffee', {extensions:['.coffee']})
.transform(function() {
var data = '';
function write(buf) { data += buf; }
function end() {
var newData = data.replace(/(assert[^\n]*\n)/g, "0;#$1\n");
this.queue(newData);
this.queue(null);
}
return through(write, end);
})
.transform(coffeeify)
.bundle()
.pipe(source('index.js')) // gives streaming vinyl file object
.pipe(buffer()) // convert from streaming to buffered vinyl file object
.pipe(minify({ ext: { src: ".js", min: ".min.js" } })) // now gulp-uglify works
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(gulp.dest('./build'))
});
gulp.task('dev', ['generate-parser'], function() {
return browserify('./index.coffee', {extensions:['.coffee']})
.transform(coffeeify)
.bundle()
.pipe(source('index.js'))
.pipe(gulp.dest('./build'))
});
gulp.task('default', ['build'], function() {
});