This repository has been archived by the owner on May 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
101 lines (85 loc) · 2.68 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
/* global __dirname */
var gulp = require('gulp');
var path = require('path');
var mocha = require('gulp-mocha');
var del = require('del');
var runSequence = require('run-sequence');
var tsb = require('./lib');
var compilation = tsb.create('./tsconfig.json', /*verbose*/ true);
var sources = [
'src/**/*.ts',
'node_modules/@types/**/*.ts'
];
var latest = [
'out/**/*.js',
'out/**/*.js.map',
'out/**/*.d.ts'
];
// build latest using LKG version
gulp.task('pre-build', function() {
return gulp.src(sources)
.pipe(compilation())
.pipe(gulp.dest('tmp'));
})
// re-build latest using built version
gulp.task('build', ['pre-build'], function () {
var tsb = reload('./tmp');
var compilation = tsb.create('./tsconfig.json', /*verbose*/ true);
return gulp.src(sources)
.pipe(compilation())
.pipe(gulp.dest('out'));
});
// clean built versions
gulp.task('clean', function () {
return del(['tmp', 'out']);
});
// clean the lkg
gulp.task('lkg:clean', function () {
return del(['lib']);
});
// copy files for 'lkg' task
gulp.task('lkg:copy', ['lkg:clean'], function () {
return gulp.src(latest).pipe(gulp.dest('lib'));
});
// deploy lkg
gulp.task('lkg', function () {
return runSequence('clean', 'test', 'lkg:copy');
});
gulp.task('test', ['build'], function () {
return gulp.src(["out/tests/**/*.js"], { read: false })
.pipe(mocha({ timeout: 3000 }));
});
gulp.task('dev', ['test'], function () {
return gulp.watch(sources, ['test']);
});
gulp.task('default', ['dev']);
// reload a node module and any children beneath the same folder
function reload(moduleName) {
var id = require.resolve(moduleName);
var mod = require.cache[id];
if (mod) {
var base = path.dirname(mod.filename);
// expunge each module cache entry beneath this folder
var stack = [mod];
while (stack.length) {
var mod = stack.pop();
if (beneathBase(mod.filename)) {
delete require.cache[mod.id];
}
stack.push.apply(stack, mod.children);
}
}
// expunge each path cache entry beneath the folder
for (var cacheKey in module.constructor._pathCache) {
if (cacheKey.indexOf(moduleName) > 0 && beneathBase(cacheKey)) {
delete module.constructor._pathCache[cacheKey];
}
}
// re-require the module
return require(moduleName);
function beneathBase(file) {
return base === undefined
|| (file.length > base.length
&& file.substr(0, base.length + 1) === base + path.sep);
}
}