-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
105 lines (91 loc) · 3.03 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
98
99
100
101
102
103
104
105
const gulp = require('gulp');
const tslint = require('tslint');
const gtslint = require('gulp-tslint');
const ts = require('gulp-typescript');
const mocha = require('gulp-mocha');
const sourcemaps = require('gulp-sourcemaps');
const plumber = require('gulp-plumber');
const transform = require('gulp-transform');
const rimraf = require('rimraf');
const merge = require('merge2');
const {preprocess: _preprocess} = require('tiny-preprocessor');
const title = 'yreuq.js';
const tsproj = {
commonjs: ts.createProject(`./tsconfig.json`, {declaration: true}),
module: ts.createProject(`./tsconfig.json`, {declaration: true, module: `es2015`}),
tests: ts.createProject(`./tsconfig.json`, {rootDir: `./`, noUnusedLocals: false})
};
const preprocess = buffer => _preprocess(buffer.toString());
function replace(a, b) {
return function(buffer) {
const src = buffer.toString();
return src.replace(a, b);
}
}
function compile() {
const src = gulp.src(`./.build/ts/**/*.ts`)
.pipe(plumber())
.pipe(sourcemaps.init());
const ts_commonjs = src.pipe(tsproj.commonjs());
const ts_module = src.pipe(tsproj.module());
return merge([
ts_commonjs.js
.pipe(sourcemaps.write(`./`))
.pipe(gulp.dest(`./lib/commonjs`)),
ts_module.js
.pipe(sourcemaps.write(`./`))
.pipe(gulp.dest(`./lib/module`)),
ts_module.dts
.pipe(gulp.dest(`./lib/typings`)),
gulp.src(`./.build/tests.ts/**/*.ts`)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(tsproj.tests()).js
.pipe(transform(replace(/\.\.\/ts/g, `../../lib/commonjs`)))
.pipe(sourcemaps.write(`./`))
.pipe(gulp.dest(`./.build/tests`))
]);
}
function runPreprocessor() {
return merge([
gulp.src(`./src/**/*.ts`)
.pipe(plumber())
.pipe(transform(preprocess))
.pipe(gulp.dest(`./.build/ts`)),
gulp.src(`./tests/**/*.ts`)
.pipe(plumber())
.pipe(transform(preprocess))
.pipe(transform(replace(/\.\.\/src/g, `../ts`)))
.pipe(gulp.dest(`./.build/tests.ts`)),
]);
}
function lint() {
return gulp.src([`./src/**/*.ts`, `./tests/**/*.ts`])
.pipe(plumber())
.pipe(gtslint({formatter: "verbose"}))
.pipe(gtslint.report());
}
function runTests() {
require(`source-map-support`).install();
return gulp
.src([`./.build/tests/**/*.js`], {read: false})
.pipe(plumber())
.pipe(mocha({timeout: 10000, ui: `tdd`}));
}
function clean() {
const paths = [`./lib`, `./.build`];
return function(cb) {
const next = (i = 0) => rimraf(paths[i], done(i + 1));
const done = i => err => err ? cb(err) : i === paths.length ? cb() : next(i);
return next();
}
}
gulp.task(`clean`, clean());
gulp.task(`preprocess`, [`lint`], runPreprocessor);
gulp.task(`compile`, [`lint`, `preprocess`], compile);
gulp.task(`watch`, () => gulp.watch([`./src/**/*.ts`, `./tests/**/*.ts`], [`build`]));
gulp.task(`test`, [`compile`], runTests);
gulp.task(`lint`, lint);
gulp.task(`build`, [`preprocess`, `compile`, `test`, `lint`]);
gulp.task(`dev`, [`build`, `watch`]);
gulp.task(`default`, [`build`]);