This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
169 lines (149 loc) · 4.53 KB
/
gulpfile.ts
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
const gulp = require("gulp"),
del = require("del"),
tsc = require("gulp-typescript"),
sourcemaps = require('gulp-sourcemaps'),
tsProject = tsc.createProject("tsconfig.json"),
tslint = require('gulp-tslint'),
runSequence = require('run-sequence'),
nodemon = require('gulp-nodemon');
/**
* Remove build directory.
*/
gulp.task('clean', (cb) => {
return del(["build"], cb);
});
/**
* Build Express server
*/
gulp.task('build:server', ()=> {
const tsProject = tsc.createProject('server/tsconfig.json');
const tsResult = gulp.src('server/src/**/*.ts')
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/server'));
});
gulp.task('build:client', () =>{
const tsProject = tsc.createProject('client/tsconfig.json');
const tsResult = gulp.src('client/**/*.ts')
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/client'));
});
/**
* Lint all custom TypeScript files.
*/
gulp.task('tslint', () => {
return gulp.src("client/app/**/*.ts")
.pipe(tslint({
formatter: "prose"
}))
.pipe(tslint.report());
});
/**
* Compile TypeScript sources and create sourcemaps in build directory.
*/
gulp.task("compile", ["tslint"], () => {
let tsResult = gulp.src("client/**/*.ts")
.pipe(sourcemaps.init())
.pipe(tsProject());
return tsResult.js
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("build/client"));
});
/**
* Copy all resources that are not TypeScript files into build directory. e.g. index.html, css, images
*/
gulp.task("clientResources", () => {
return gulp.src(["client/**/*", "!**/*.ts", "!client/*.json"])
.pipe(gulp.dest("build/client"));
});
/**
* Copy bin directory for www
*/
gulp.task("serverResources", () => {
return gulp.src(["server/src/bin/**"])
.pipe(gulp.dest("build/server/bin"));
});
/**
* Copy all required libraries into build directory.
*/
gulp.task("libs", () => {
return gulp.src([
'core-js/client/**',
'zone.js/dist/zone.js',
'reflect-metadata/Reflect.js',
'reflect-metadata/Reflect.js.map',
'systemjs/dist/system.src.js',
'hammerjs/hammer.js',
], { cwd: "node_modules/**" }) /* Glob required here. */
.pipe(gulp.dest("build/client/libs"));
});
/**
* Copy all required libraries into build directory.
*/
gulp.task("css", () => {
return gulp.src([
'@angular/material/prebuilt/**'
], { cwd: "node_modules/**" }) /* Glob required here. */
.pipe(gulp.dest("build/client/css"));
});
/**
* Start the express server with nodemon
*/
gulp.task('start', () =>{
nodemon({
script: 'build/server/bin/www'
, ext: 'html js'
, ignore: ['ignored.js']
, tasks: ['tslint']
})
.on('restart', ()=> {
console.log('restarted!');
});
});
/**
* Build the project.
* 1. Clean the build directory
* 2. Build Express server
* 3. Build the Angular app
* 4. Copy the resources
* 5. Copy the dependencies.
*/
gulp.task("build", (callback)=> {
runSequence('clean', 'build:server', 'build:client', 'clientResources', 'serverResources', 'libs', 'css', callback);
});
/**
* Watch for changes in TypeScript, HTML and CSS files.
*/
gulp.task('watch', ()=> {
gulp.watch(["client/**/*.*"], ['compile']).on('change', (e)=> {
console.log('File ' + e.path + ' has been changed. Compiling.');
});
gulp.watch(["client/**/*.ts"], ['compile']).on('change', (e)=> {
console.log('TypeScript file ' + e.path + ' has been changed. Compiling.');
});
gulp.watch(["client/**/*.html", "client/**/*.css"], ['clientResources']).on('change', (e)=> {
console.log('Resource file ' + e.path + ' has been changed. Updating.');
});
gulp.watch(["server/src/**/*.ts"], ['compile']).on('change', (e) =>{
console.log('TypeScript file ' + e.path + ' has been changed. Compiling.');
});
});
/**
* Build the project.
* 1. Clean the build directory
* 2. Build Express server
* 3. Build the Angular app
* 4. Copy the resources
* 5. Copy the dependencies.
*/
gulp.task("build", (callback)=> {
runSequence('clean', 'build:server', 'build:client', 'clientResources', 'serverResources', 'libs', 'css', callback);
});
gulp.task('default', () =>{
runSequence('build:server', 'build:client', 'clientResources', 'serverResources', 'libs', 'css', 'watch', 'start');
});