-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
94 lines (86 loc) · 2.65 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
'use strict';
// IMPORT
// ----------------------------------------------------------------------------
const gulp = require('gulp');
const gulpTS = require('gulp-typescript');
const gulpTSLint = require('gulp-tslint').default;
const gulpSourcemaps = require('gulp-sourcemaps');
const gulpNodemon = require('gulp-nodemon');
const tsLint = require('tslint');
const del = require('del');
const path = require('path');
// PREPARE PROJECT
// ----------------------------------------------------------------------------
const project = gulpTS.createProject('tsconfig.json');
const typeCheck = tsLint.Linter.createProgram('tsconfig.json');
// FUNCTIONS (StartBuild Build)
// ----------------------------------------------------------------------------
function startBuild() {
// => Delete old files
del.sync(['./dist/**/*.*', '!./dist/**/*.db']);
// => Copy files
gulp.src('./resources/**/*').pipe(gulp.dest('dist/'));
//=> Compile TS files
const tsCompile = gulp.src('./src/**/*.ts').pipe(gulpSourcemaps.init()).pipe(project());
return tsCompile.js
.pipe(
gulpSourcemaps.write({
sourceRoot: (file) => path.relative(path.join(file.cwd, file.path), file.base),
})
)
.pipe(gulp.dest('dist/'));
}
// FUNCTIONS (StartWatch Watch)
// ----------------------------------------------------------------------------
function startWatch() {
gulp.watch('./src/**/*.ts').on('change', function (path, stats) {
console.log(path + ' changed!');
startBuild();
});
}
// FUNCTIONS (StartNodemon Start)
// ----------------------------------------------------------------------------
function startNodemon() {
return gulpNodemon({
script: './dist/Main.js',
watch: './dist/Main.js',
});
}
// LINT TASK
// ----------------------------------------------------------------------------
gulp.task('lint', function () {
return gulp
.src('./src/**/*.ts')
.pipe(
gulpTSLint({
configuration: 'tslint.json',
formatter: 'verbose',
program: typeCheck,
})
)
.pipe(gulpTSLint.report());
});
// BUILD
// ----------------------------------------------------------------------------
gulp.task(
'build',
gulp.series('lint', startBuild)
);
// WATCH
// ----------------------------------------------------------------------------
gulp.task(
'watch',
gulp.parallel('build', startWatch)
);
// START
// ----------------------------------------------------------------------------
gulp.task(
'start',
gulp.series('build', startNodemon)
);
// SERVE
// ----------------------------------------------------------------------------
gulp.task(
'serve',
gulp.series('build', gulp.parallel(startWatch, startNodemon))
);