-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
193 lines (168 loc) · 4.77 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
'use strict';
const
gulp = require('gulp'),
ts = require('gulp-typescript'),
tslint = require('gulp-tslint'),
del = require('del'),
karma = require('karma'),
gulpHtml2js = require('gulp-html2js'),
browserify = require("browserify"),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
gulpCoveralls = require('gulp-coveralls');
const { series, parallel } = require('gulp');
const tsProject = ts.createProject({
// allowSyntheticDefaultImports: true,
// sourceMap: true,
// declaration: false,
module: "commonjs",
moduleResolution: "node",
// emitDecoratorMetadata: true,
// experimentalDecorators: true,
target: "es2015",
// typeRoots: [
// "node_modules/@types"
// ],
// lib: [
// "es2015",
// "dom",
// "esnext.asynciterable"
// ],
// sourceType: "module"
});
const srcDir = './src/';
const tmpDir = './temp/';
const distDir = './dist/';
const staticDir = './dist/static/';
const srcGlob = srcDir + '**/**.ts';
const htmlGlob = srcDir + '*.html';
const cssGlob = srcDir + '**/**.css';
const imgGlob = srcDir + 'img/**/*.*';
// Removes temp and dist directories.
function clean(cb) {
del([tmpDir], function(){
del([distDir], cb);
});
}
exports.clean = clean;
// Runs tslint on the original source TypeScript files.
function lint () {
return gulp.src(srcGlob)
.pipe(tslint({
formatter: "verbose"
}))
.pipe(tslint.report());
}
exports.lint = lint;
// Builds HTML template files into a joulia.templates Angular module at
// temp/joulia.js.
function html2js() {
return gulp.src('src/**/**.tpl.html')
.pipe(gulpHtml2js('templates.js', {
adapter: 'angular',
base: 'src',
name: 'app.templates'
}))
.pipe(gulp.dest(tmpDir));
}
// Compiles TypeScript source files in src/ to temp/js directory.
function tsc() {
return gulp.src(srcGlob)
.pipe(tsProject())
.js.pipe(gulp.dest(tmpDir));
}
function bundleInternalCss() {
return browserify({
debug: true,
transform: ['browserify-css'],
entries: ['./src/css/joulia.js'],
})
.bundle()
.pipe(source('joulia.css.js'))
.pipe(buffer())
.pipe(gulp.dest(staticDir));
}
function bundlePublicCss() {
return browserify({
debug: true,
transform: ['browserify-css'],
entries: ['./src/css/public.js'],
})
.bundle()
.pipe(source('public.css.js'))
.pipe(buffer())
.pipe(gulp.dest(staticDir));
}
exports.bundlePublicCss = bundlePublicCss;
// Build task compiles TypeScript and HTML templates into JS in the temp/js
// directory.
const build = parallel(tsc, html2js);
exports.build = build;
// Browersifies TypeScript compiled files and HTML templates into a single JS
// bundle.js file.
const bundleInternal = series(
parallel(build, bundleInternalCss),
function bundleInternal() {
return browserify({
debug: true,
entries: ['./temp/joulia-webclient.js'],
})
.bundle()
.pipe(source('joulia-webclient.js'))
.pipe(buffer())
.pipe(gulp.dest(staticDir));
}
);
const bundlePublic = series(
parallel(build, bundlePublicCss),
function bundlePublic() {
return browserify({
debug: true,
entries: ['./temp/public.js'],
})
.bundle()
.pipe(source('public.js'))
.pipe(buffer())
.pipe(gulp.dest(staticDir));
}
);
exports.bundlePublic = bundlePublic;
function copyHtml() {
return gulp.src(htmlGlob)
.pipe(gulp.dest(staticDir));
}
function copyCss() {
return gulp.src(cssGlob)
.pipe(gulp.dest(staticDir));
}
function copyImg() {
return gulp.src(imgGlob)
.pipe(gulp.dest(staticDir + 'img/'));
}
const copyApp = parallel(copyHtml, copyCss, copyImg);
const bundle = series(bundleInternal, bundlePublic, copyApp);
exports.bundle = bundle;
// Builds intermediate JS source and passes it to Karma for unit testing.
const test = series(
build,
function test(cb) {
new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, cb).start();
});
exports.test = test;
const coveralls = series(
test, function coveralls() {
gulp.src('coverage/**/lcov.info')
.pipe(gulpCoveralls());
});
const ci = parallel(test, coveralls);
exports.ci = ci;
exports.default = parallel(test, bundle);
exports.watch = series(
exports.default,
function watch() {
gulp.watch(srcDir + '**/*.*', ['test', 'bundle']);
gulp.watch('./karma.conf.js', ['test', 'bundle']);
});