-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGulpfile.ts
More file actions
112 lines (95 loc) · 2.82 KB
/
Gulpfile.ts
File metadata and controls
112 lines (95 loc) · 2.82 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
import * as del from 'del';
import * as gulp from 'gulp';
import * as about from 'gulp-about';
import * as tsc from 'gulp-typescript';
import * as merge from 'merge2';
import * as runSequence from 'run-sequence';
gulp.task('default', ['build']);
gulp.task('build', ['clean'], (cb) => {
runSequence('common:build', 'server:build', cb);
});
gulp.task('testPrep', ['common:build', 'server:testPrep']);
gulp.task('watch', () => {
watch({
'common/**/*.ts': 'common:build',
'server/src/**/*.ts': 'server:compile'
});
});
gulp.task('clean', () =>
del([
'.nyc_output',
'coverage',
'dist',
'server/src/common',
'server/src/public',
'server/src/about.json'
])
);
gulp.task('common:build', () => {
const source = 'common/**/*.ts';
del.sync(['server/src/common', 'client/app/common']);
return merge(
cp(source, 'server/src/common'),
cp(source, 'client/app/common')
);
});
gulp.task('server:build', [
'server:compile',
'server:about'
]);
gulp.task('server:compile', () =>
merge(
typescript({
project: 'server/tsconfig.json',
src: 'server/src/**/*.ts',
dest: 'dist'
}),
gulp.src('package.json')
.pipe(about())
.pipe(gulp.dest('dist'))
)
);
gulp.task('server:testPrep', () =>
// Copy index.html so that GET /* won't throw a 404. In an actual build,
// webpack will modify index.html and place it in this directory
cp('client/index.html', 'server/src/public')
);
gulp.task('server:about', () =>
gulp.src('package.json')
.pipe(about())
.pipe(gulp.dest('server/src'))
);
/** Options specific for compiling a TypeScript project */
interface CompileTypescriptOptions {
/** Passed to gulp.src() */
src: string | string[];
/** Passed to gulp.dest() */
dest: string;
/** Path to tsconfig.json relative to Gruntfile.ts */
project: string;
}
/**
* Each entry in the configuration object maps a file glob to the task(s) to
* execute when a file matching that glob is modified.
*/
interface WatchConfig {
[fileGlob: string]: string[] | string;
}
/** Compiles a TypeScript project */
function typescript(opts: CompileTypescriptOptions) {
const proj = tsc.createProject(opts.project);
const result = gulp.src(opts.src).pipe(proj());
return result.js.pipe(gulp.dest(opts.dest));
}
/** simple `cp -r` for gulp */
export function cp(src: string | string[], dest: string) {
return gulp.src(src).pipe(gulp.dest(dest));
}
/** Uses gulp to watch for file changes */
export function watch(conf: WatchConfig) {
for (const src of Object.keys(conf)) {
// Ensure the tasks are an array
const tasks = Array.isArray(conf[src]) ? conf[src] : [conf[src]];
gulp.watch(src, tasks);
}
}