-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.es6
88 lines (77 loc) · 2.5 KB
/
gulpfile.es6
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
'use strict';
var del = require('del');
var gulp = require('gulp');
var seq = require('run-sequence');
var shell = require('gulp-shell');
var mocha = require('gulp-mocha');
var opt = {
bin: './bin',
lib: './lib',
src: './src',
test: './test',
testEspowered: './test-espowered',
npmbin: './node_modules/.bin'
};
var bin = {
tsc: `${opt.npmbin}/tsc`,
babel: `${opt.npmbin}/babel`,
browserify: `${opt.npmbin}/browserify`
};
/* clean */
gulp.task('clean', del.bind(null, [
`${opt.src }/**/*.js`,
`${opt.src }/**/*.js.map`,
`${opt.test}/**/*.js`,
`${opt.test}/**/*.js.map`,
opt.lib,
opt.testEspowered
]));
/* ts */
var tsc = `${bin.tsc} -t es5 -m commonjs --noImplicitAny --noEmitOnError`;
gulp.task('ts:src_', shell.task([`find ${opt.src} -name "*.ts" | xargs ${tsc}`]));
gulp.task('ts:src', (done) => seq('clean', 'ts:src_', done));
gulp.task('ts', (done) => seq('clean', ['ts:src_'], done));
/* babel */
gulp.task('babel:test', shell.task([`${bin.babel} ${opt.test} --plugins babel-plugin-espower --out-dir ${opt.testEspowered}`]));
/* watch */
gulp.task('exec-watch:test', ['test'], () => {
gulp.watch([`${opt.src}/**/*.ts`, `${opt.test}/**/*.es6`], ['test'])
.on('error', (err) => process.exit(1));
});
gulp.task('exec-watch:cli', ['build:src'], () => {
gulp.watch([`${opt.src}/**/*.ts`], ['build:src'])
.on('error', (err) => process.exit(1));
});
function watch(target) {
return () => {
var spawn = () => {
var proc = require('child_process').spawn('gulp', [`exec-watch:${target}`], {stdio: 'inherit'});
proc.on('close', (c) => spawn());
};
spawn();
};
}
gulp.task('watch:test', watch('test'));
gulp.task('watch:cli', watch('cli'));
/* build */
gulp.task('copy:src', () => {
gulp
.src(`${opt.src}/**/*.js`)
.pipe(gulp.dest(opt.lib));
});
gulp.task('copy:dts', () => {
gulp
.src(`./typings/cw-htmlconv/cw-htmlconv.d.ts`)
.pipe(gulp.dest('./'));
});
gulp.task('build:standalone', shell.task([`${bin.browserify} -p licensify --standalone cwHtmlconv ./index.js -o ./cw-htmlconv.js`]));
gulp.task('build:src', (done) => seq('ts:src', ['copy:src', 'copy:dts'], done));
gulp.task('build', (done) => seq('build:src', 'build:standalone', done));
/* test */
gulp.task('mocha', () => {
return gulp
.src(`${opt.testEspowered}/**/*.js`)
.pipe(mocha({reporter: 'spec'}))
.on('error', (err) => process.exit(1));
});
gulp.task('test', (done) => {seq('build:src', 'babel:test', 'mocha', done)});