-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
78 lines (67 loc) · 2.01 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
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const UglifyJS = require('uglify-js');
const babel = require('gulp-babel');
const del = require('del');
const browserify = require('browserify');
const derequire = require('derequire');
const fs = require('fs');
const spawn = require('child_process').spawn;
function minify(src) {
return UglifyJS.minify(src, {fromString: true}).code;
}
function bundleMin(file, standalone, outputFile, done) {
var b = browserify({
entries: file,
standalone: standalone,
debug: false
});
b.bundle(function (err, buf) {
var code = derequire(buf.toString(), '_dereq_', 'require');
fs.writeFileSync(outputFile, minify(code));
done();
});
}
function bundle(file, standalone, outputFile, done) {
var b = browserify({
entries: file,
standalone: standalone,
debug: true
});
b.bundle(function (err, buf) {
var code = derequire(buf.toString(), '_dereq_', 'require');
fs.writeFileSync(outputFile, code);
done();
});
}
gulp.task('clean', function () {
return del('./build/**');
});
gulp.task('eslint', function () {
return gulp.src('./src/**').pipe(eslint());
});
gulp.task('lib', ['clean', 'eslint'], function () {
return gulp.src('./src/**')
.pipe(babel())
.pipe(gulp.dest('./build/modules'));
});
gulp.task('bundle', ['lib'], function (cb) {
bundle('./build/modules/index.js', 'Remember', './build/remember.js', cb);
});
gulp.task('bundle-min', ['lib'], function (cb) {
bundleMin('./build/modules/index.js', 'Remember', './build/remember.min.js', cb);
});
gulp.task('release', ['bundle', 'bundle-min'], function () {
gulp.src([
'./build/modules/**',
'./package.json',
'./README.md',
'./LICENSE'])
.pipe(gulp.dest('./build/package'));
});
gulp.task('publish', function (cb) {
const publish = spawn('npm', ['publish'], {cwd: './build/package', stdio: 'inherit'});
publish.on('close', () => { cb(); });
publish.on('error', (err) => { cb(err) });
});
gulp.task('default', ['bundle', 'bundle-min']);