-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (64 loc) · 2.56 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
const gulp = require('gulp');
const ts = require('gulp-typescript');
const jasmine = require('gulp-jasmine');
const clean = require('gulp-clean');
const runSequence = require('run-sequence');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const path = require('path');
const fs = require('fs');
const replace = require('gulp-replace');
const tsProject = ts.createProject('tsconfig.json');
gulp.task('build', [], function (cb) {
runSequence('subbuild', 'moveindex', cb);
});
gulp.task('subbuild', function() {
const merge = require('merge2');
var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
let toMerge = [
tsResult.dts.pipe(gulp.dest(tsProject.config.compilerOptions.declarationDir || tsProject.config.compilerOptions.outDir)),
tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest(tsProject.config.compilerOptions.outDir))
];
return merge(toMerge);
});
gulp.task('moveindex', function () {
const outDir = tsProject.config.compilerOptions.outDir;
const rx = /([\'\"])(\.\/src)/g;
return gulp.src([path.join(outDir, 'index.d.ts'), path.join(outDir, 'index.js')])
.pipe(replace(rx, "$1./lib/src"))
.pipe(gulp.dest(path.join(outDir, '../')));
// fs.renameSync(
// path.join(tsProject.config.compilerOptions.outDir, "src/"),
// path.join(tsProject.config.compilerOptions.outDir, tsProject.config.compilerOptions.outDir)
// );
// return gulp.src(tsProject.config.compilerOptions.outDir)
// .pipe(gulp.dest('../'));
// return gulp.src(path.join(tsProject.config.compilerOptions.outDir, "src/"))
// .pipe(rename(path.join(tsProject.config.compilerOptions.outDir, tsProject.config.compilerOptions.outDir)))
// .pipe(gulp.dest(tsProject.config.compilerOptions.outDir));
});
gulp.task('clean', function () {
let folders = [tsProject.config.compilerOptions.outDir];
if (tsProject.config.compilerOptions.declarationDir) {
folders.push(tsProject.config.compilerOptions.declarationDir);
}
return gulp.src(folders, { read: false })
.pipe(clean());
});
gulp.task('test:run', function() {
return gulp.src(path.join(tsProject.config.compilerOptions.outDir, '/spec/**'))
.pipe(jasmine())
});
gulp.task('watch', ['default'], function() {
gulp.watch('src/*.ts', ['default']);
});
gulp.task('test', [], function(cb) {
runSequence('clean', 'build', 'test:run', cb);
});
gulp.task('default', [], function(cb) {
runSequence('clean', 'build', cb);
});