-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
97 lines (82 loc) · 2.44 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
92
93
94
95
96
97
const gulp = require('gulp');
const babel = require('gulp-babel');
const through2 = require('through2');
const watch = require('gulp-watch');
const newer = require('gulp-newer');
const gutil = require('gulp-util');
const rimraf = require('rimraf');
const plumber = require('gulp-plumber');
const cleanEmptyModules = require('./utils/clean-empty-modules');
// for compilation
const source = './packages/*/src/**/*.js';
const dest = './packages';
const srcEx = new RegExp("(packages/[^/]+)/src/");
const libFragment = "$1/lib/";
// for cleaning
const libs = './packages/*/lib';
gulp.task('default', ['build']);
gulp.task('clean', function(cb) {
rimraf.sync(libs, { glob: true });
const out = cleanEmptyModules();
if (out.removed.length > 0)
gutil.log(gutil.colors.cyan('Empty Packages - REMOVED'));
out.removed.forEach(mod => {
gutil.log(gutil.colors.red(mod));
});
if (out.kept.length > 0)
gutil.log(gutil.colors.cyan('Unstaged Empty Packages - NOT REMOVED'));
out.kept.forEach(mod => {
gutil.log(gutil.colors.yellow(mod));
});
cb();
});
gulp.task('build', function() {
return gulp.src(source)
.pipe(plumber())
.pipe(through2.obj(function(file, enc, callback) {
file._path = file.path;
file.path = file.path.replace(srcEx, libFragment);
callback(null, file);
}))
.pipe(newer(dest))
.pipe(through2.obj(function(file, env, callback) {
gutil.log('Compiling', gutil.colors.cyan(file._path));
callback(null, file);
}))
.pipe(babel())
.pipe(gulp.dest(dest));
});
/* eslint-disable no-unused-vars */
gulp.task('watch', ['build'] ,function(callback) {
watch(source, function() {
gulp.start('build');
});
});
/* eslint-enable */
/**
* Build for browser
*/
const browserify = require('browserify');
const babelify = require('babelify');
const vinylSource = require('vinyl-source-stream');
const vinylBuffer = require('vinyl-buffer');
const uglify = require('gulp-uglify');
const copy = require('gulp-copy');
gulp.task('browser', function() {
const bundler = browserify('./utils/browser.js', {
standalone: 'BabelMinify'
}).transform(babelify, {
presets: ['es2015']
});
return bundler.bundle()
.pipe(vinylSource('babel-minify.js'))
.pipe(vinylBuffer())
.pipe(uglify())
.pipe(gulp.dest('./build'));
});
gulp.task('gh-pages', ['browser'], function() {
return gulp.src('build/*')
.pipe(copy('../babel-minify-gh-pages/build', {
prefix: 1
}));
});