forked from emmetio/emmet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
91 lines (81 loc) · 2.22 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var path = require('path');
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var streamify = require('gulp-streamify');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var through = require('through2');
var rename = require('gulp-rename');
var ciu = require('./lib/assets/caniuse');
var DEST = './dist';
function ciuWrapper() {
var buf = new Buffer('');
return through(function(chunk, enc, next) {
buf += chunk;
next();
}, function(next) {
var db = JSON.parse(buf.toString());
this.push(JSON.stringify(ciu.optimize(db)));
next();
});
}
function bundle() {
var files = ['./lib/emmet.js'];
for (var i = 0, il = arguments.length; i < il; i++) {
files.push(arguments[i]);
}
return browserify({
entries: files,
detectGlobals: false,
standalone: 'emmet',
fullPaths: true
})
.transform(function(file) {
if (path.basename(file) === 'caniuse.json') {
return ciuWrapper();
}
return through();
})
.bundle()
.pipe(trimPath(path.join(__dirname, 'lib/')));
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
}
function trimPath(base) {
var buf = new Buffer('');
var reBase = new RegExp(escapeRegExp(base), 'g');
return through(function(chunk, enc, next) {
buf += chunk;
next();
}, function(next) {
this.push(buf.toString().replace(reBase, ''));
next();
});
}
// "App" version of Emmet: does not include snippets.json and caniuse.json,
// assuming that it should be loaded by app controller
gulp.task('app', function() {
return bundle()
.pipe(source('emmet-app.js'))
.pipe(gulp.dest(DEST));
});
// Reduced version of Emmet, contains snippets, no Can I Use database
gulp.task('snippets', function() {
return bundle('./bundles/snippets.js')
.pipe(source('emmet-snippets.js'))
.pipe(gulp.dest(DEST))
.pipe(streamify(uglify()))
.pipe(rename('emmet-snippets-min.js'))
.pipe(gulp.dest(DEST));
});
// Full version of Emmet
gulp.task('full', function() {
return bundle('./bundles/snippets.js', './bundles/caniuse.js')
.pipe(source('emmet.js'))
.pipe(gulp.dest(DEST))
.pipe(streamify(uglify()))
.pipe(rename('emmet-min.js'))
.pipe(gulp.dest(DEST));
});
gulp.task('default', ['app', 'snippets', 'full']);