-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
92 lines (76 loc) · 2.57 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
'use strict';
const gulp = require('gulp-help')(require('gulp-param')(require('gulp'), process.argv));
// const async = require('async');
const del = require('del');
const merge = require('merge2');
// const path = require('path');
// load gulp plugins
const G$ = require('gulp-load-plugins')({ lazy: true });
// load settings
const settings = require('./gulp.json');
const tsconfig = require('./tsconfig.json');
let tsProject = undefined;
// const exec = require('child_process').exec;
gulp.task('debug', 'Run the project and auto-restart for changes', function (project, debug) {
debug = debug || 'weather-stats:*';
console.log(`>> debug weather-stats application with DEBUG=${debug}`);
G$.nodemon({
script: `index.js`,
ext: 'js',
env: {
NODE_ENV: 'development',
DEBUG: debug
},
delay: 1, // Sec
watch: `app`,
ignore: `app/src`
});
}, {
options: {
project: `Project name: weather-stats`
}
});
// Building
gulp.task('build', 'Compiles all TypeScript source files and updates module references', function (callback) {
G$.sequence(['tslint', 'clean'], 'typescript', callback);
});
// Watching
gulp.task('watch', 'Contiuous build', ['build'], function () {
gulp.watch(settings.src, ['tslint', `typescript`]);
});
// Cleaning
gulp.task('clean', 'Cleans the generated files from lib directory', function () {
return del((settings.dest), { dot: true });
});
// Transpiling
gulp.task(`typescript`, `Transpile typescript files`, function () {
tsProject = G$.typescript.createProject(tsconfig.compilerOptions);
const tsResult = gulp.src(settings.tsfiles)
.pipe(G$.sourcemaps.init())
.pipe(tsProject());
const dest = settings.dest;
return merge([
// .d.ts files
tsResult.dts.pipe(gulp.dest(dest)),
// .js files + sourcemaps
settings.inlineSourcemaps ?
tsResult.js
.pipe(G$.sourcemaps.write()) // inline sourcemaps
.pipe(gulp.dest(dest)) :
tsResult.js
.pipe(G$.sourcemaps.write('.')) // separate .js.map files
.pipe(gulp.dest(dest)),
// all other files
gulp.src(settings.resources).pipe(gulp.dest(dest))
]);
});
// see https://www.npmjs.com/package/tslint
gulp.task('tslint', 'Lints all TypeScript source files', function () {
return gulp.src(settings.tsfiles)
.pipe(G$.tslint({
formatter: 'verbose'
}))
.pipe(G$.tslint.report({
emitError: false
}));
});