-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgulpfile.js
More file actions
113 lines (93 loc) · 3.09 KB
/
Copy pathgulpfile.js
File metadata and controls
113 lines (93 loc) · 3.09 KB
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
const gulp = require('gulp');
const HubRegistry = require('gulp-hub');
const fs = require('fs-extra');
// const browserSync = require('browser-sync');
const conf = require('./conf/gulp.conf');
const log = require('./gulp/log');
const browserSync = require('browser-sync');
// Load some files into the registry
let hub = new HubRegistry([conf.path.tasks('*.js')]);
const taskListing = require('./gulp/listing');
const cache = require('./gulp/cache');
// Tell gulp to use the tasks just loaded
// gulp.registry(hub);
// no need to register ? but hub is needed anyway. Avoid jshint warning
hub = hub;
gulp.task('help', taskListing);
gulp.task('default', gulp.series('help'));
// watch
gulp.task('watch', watch);
// build
gulp.task(`build`, gulp.series('clean:dist', 'clean', 'partials', 'resources', 'scripts', 'styles', 'vet', 'build'));
for (let flavor of flavorList()) {
gulp.task(`build:${flavor}`, gulp.series(cb => setEnv(cb, flavor), 'build'));
}
// text
gulp.task('test', gulp.series(cb => setEnv(cb, 'test'), 'clean', 'scripts', 'partials', 'karma:single-run'));
// test auto
gulp.task('test:auto', gulp.series(cb => setEnv(cb, 'test'),
'clean', 'scripts', 'partials', 'watch', 'karma:auto-run'));
// serve
gulp.task('serve', gulp.series('clean', cb => setEnv(cb, 'dev'), 'scripts', 'styles', 'resources:i18n',
'watch', 'browsersync'));
gulp.task('serve:dist', gulp.series('browsersync:dist'));
function reloadBrowserSync(cb) {
log.debug('reload...');
browserSync.reload();
cb();
}
function watch(done) {
// watch all html => BS
gulp.watch([
conf.path.app('**/*.html'),
conf.path.resources('**'),
`!${conf.path.app('index.html')}`
],
reloadBrowserSync);
// watch index.html => build
gulp.watch(conf.path.app('index.html'), gulp.series('clean', 'scripts', 'styles', 'resources:i18n'),
reloadBrowserSync);
// watch d.ts => typings
gulp.watch([
conf.path.app('**/*.d.ts'),
conf.path.typings('**/*.d.ts'),
`!${conf.path.typings('**/*.d.ts')}`
], gulp.series('typings'));
// watch scss => styles
gulp.watch([
conf.path.app('**/*.{scss,css}')
], gulp.series('styles'))
.on('unlink', onDelete);
// watch locales => resources:i18n
gulp.watch([
conf.path.app('**/' + conf.i18n.pattern())
], gulp.series('resources:i18n', reloadBrowserSync));
// watch ts/js => scripts
gulp.watch([
conf.path.app('**/*.{ts,js}'),
conf.path.config('**/*.{ts,js}'),
conf.path.env('**/*.{ts,js}'),
'bower.json'],
gulp.series('scripts'))
.on('unlink', onDelete);
done();
}
function setEnv(cb, flavor) {
if (flavor) {
conf.env.flavor = flavor;
}
cb();
}
function flavorList() {
return fs.readdirSync(conf.path.env())
.map((filename) => {
let match = /(.*?)-conf\.js/g.exec(filename);
return match ? match[1] : undefined;
})
.filter((flavor) => {
return !!flavor;
});
}
function onDelete(file) {
cache.remove(file);
}