-
Notifications
You must be signed in to change notification settings - Fork 28
/
gulpfile.babel.js
83 lines (70 loc) · 2.05 KB
/
gulpfile.babel.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
require('babel-register')();
import gulp from 'gulp';
import {exec} from 'child_process';
import fs from 'fs';
import path from 'path';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserify from 'browserify';
import babelify from 'babelify';
import del from 'del';
import Promise from 'bluebird';
import srcStream from 'vinyl-source-stream';
const $ = gulpLoadPlugins();
const pkg = JSON.parse(fs.readFileSync('./package.json'));
function lint(files, options) {
return () => {
return gulp.src(files)
.pipe($.eslint(options))
.pipe($.eslint.format());
};
}
gulp.task('clean', del.bind(null, ['build', `${pkg.name}-*.tgz`]));
gulp.task('lint', lint(['src/{,*/}*.js{,x}']));
gulp.task('npmpack', ['build'], () => {
return new Promise((resolve, reject) => {
exec('npm pack', (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.toString());
}
});
});
});
gulp.task('demoInstall', ['npmpack'], () => {
return new Promise((resolve, reject) => {
exec(`npm install ../${pkg.name}-${pkg.version}.tgz`, {
cwd: path.join(__dirname, 'example')
}, (err, stdout) => {
if (err) {
reject(err);
} else {
resolve(stdout.toString());
}
});
});
});
gulp.task('demoBuild', ['demoInstall'], () => {
return browserify({
entries: 'example/demo.jsx',
debug: true,
transform: [babelify]
}).bundle()
.pipe(srcStream('demo.bundle.js'))
.pipe(gulp.dest('example'));
});
gulp.task('demo', ['demoBuild', 'watch'], () => {
return $.connect.server({
root: 'example',
livereload: true
});
});
gulp.task('watch', () => {
return gulp.watch(['example/*.html', 'src/{,*/}*.js{,x}', 'example/demo.jsx'], ['demoBuild']);
});
gulp.task('build', ['clean', 'lint'], () => {
return gulp.src('src/{,*/}*.js{,x}')
.pipe($.plumber())
.pipe($.babel())
.pipe(gulp.dest('build/'));
});