forked from artasparks/glift-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
156 lines (133 loc) · 4.48 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'use strict';
var gulp = require('gulp'),
qunit = require('gulp-qunit'),
size = require('gulp-size'),
concat = require('gulp-concat'),
chmod = require('gulp-chmod'),
through = require('through2'),
ts = require('gulp-typescript'),
closureCompiler = require('./src/dev/closure-compiler.js'),
updateHtmlFiles = require('./src/dev/updatehtml.js'),
jsSrcGlobGen = require('./src/dev/srcgen.js');
// The source paths, used for generating the glob, for determining sources.
var srcPaths = [
// :Glift Core: //
// Top level source package must go first since it defines the namespace
'src/glift.js',
// Point and enums from util are depended on by everything. Perhaps they
// should go at the top level?
'src/util',
'src'];
// Ignore the test files, dev files
var srcIgnore = ['!src/**/*_test.js', '!src/**/*_test.ts', '!**/dev/*']
// The glob used for determining tests
var testGlob = ['src/**/*_test.js', 'src/**/*_test.ts']
gulp.task('concat', () => {
return gulp.src(jsSrcGlobGen(srcPaths, srcIgnore), {base: '.'})
.pipe(concat('glift-core-concat.js'))
.pipe(size())
.pipe(chmod(0o666))
.pipe(gulp.dest('./compiled/'))
})
// Compile the sources with the JS Compiler
// See https://www.npmjs.com/package/google-closure-compiler
// for more details
gulp.task('compile', () => {
return gulp.src(jsSrcGlobGen(srcPaths, srcIgnore), {base: '.'})
.pipe(closureCompiler('glift-core.js'))
.pipe(size())
.pipe(gulp.dest('./compiled/'))
})
// compile typescript + js
gulp.task('cts', () => {
return gulp.src(jsSrcGlobGen(srcPaths, srcIgnore, true /* ts */), {base: '.'})
.pipe(ts({
noImplicitAny: true,
allowJs: true,
outFile: 'glift-core.ts.js'
}))
.pipe(gulp.dest('./compiled/'));
});
// compile just typescript
gulp.task('cts-o', () => {
return gulp.src('src/**/*.ts')
.pipe(ts({
noImplicitAny: true,
outFile: 'glift-core.only.js'
}))
.pipe(gulp.dest('./compiled/'));
});
// Update the HTML tests with the dev JS source files
gulp.task('update-html-srcs', () => {
return gulp.src(jsSrcGlobGen(srcPaths, srcIgnore), {base: '.'})
.pipe(updateHtmlFiles({
filesGlob: './test/htmltests/*.html',
outDir: './test/htmltests_gen/',
header: '<!-- AUTO-GEN-DEPS -->',
footer: '<!-- END-AUTO-GEN-DEPS -->',
dirHeader: '<!-- %s sources -->',
}))
});
// Update the HTML tests with the test JS files
gulp.task('update-html-tests', () => {
return gulp.src(testGlob)
.pipe(updateHtmlFiles({
filesGlob: './test/htmltests/GCoreTest.html',
outDir: './test/htmltests_gen/',
header: '<!-- AUTO-GEN-TESTS -->',
footer: '<!-- END-AUTO-GEN-TESTS -->',
dirHeader: '<!-- %s tests -->',
}))
})
gulp.task('src-gen', () => {
gulp.src(jsSrcGlobGen(srcPaths, srcIgnore))
.pipe(through.obj(function(file, enc, cb) {
console.log(file.path);
cb()
}, function(cb) {
cb()
}));
});
gulp.task('test-simple', () => {
return gulp.src('./test/htmltests_gen/GCoreTest.html').pipe(qunit())
});
gulp.task('test', gulp.series('update-html-tests', 'update-html-srcs', () => {
return gulp.src('./test/htmltests_gen/GCoreTest.html').pipe(qunit())
}));
// The full build-test cycle. This:
// - Updates all the HTML files
// - Recreates the concat-target
// - Runs all the tests
// - Compiles with JSCompiler + TypeChecking
gulp.task('build-test', gulp.series('concat', 'compile', 'test'))
// A watcher for the the full build-test cycle.
gulp.task('test-watch', () => {
return gulp.watch([
'src/**/*.js',
'src/**/*_test.js'], gulp.series('test'))
});
// A simpler watcher that just updates the
gulp.task('update-html-watch', () => {
return gulp.watch([
'src/**/*.js',
'src/**/*_test.js'], gulp.series('update-html-tests', 'update-html-srcs'))
})
// Update the HTML tests with the compiled glift.
gulp.task('update-html-compiled', gulp.series('compile', () => {
return gulp.src('./compiled/glift-core.js')
.pipe(updateHtmlFiles({
filesGlob: './test/htmltests/*.html',
outDir: './test/htmltests_gen/',
header: '<!-- AUTO-GEN-DEPS -->',
footer: '<!-- END-AUTO-GEN-DEPS -->',
dirHeader: '<!-- %s sources -->',
}))
}));
gulp.task('compile-test', gulp.series('update-html-compiled', () => {
return gulp.src('./test/htmltests_gen/GCoreTest.html').pipe(qunit())
}));
gulp.task('compile-watch', () => {
return gulp.watch([
'src/**/*.js',
'src/**/*_test.js'], gulp.series('update-html-compiled'))
});