-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
95 lines (83 loc) · 2 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
95
const gulp = require('gulp'),
tsc = require('gulp-typescript').createProject('tsconfig.json'),
jeditor = require('gulp-json-editor'),
del = require("del"),
gulpSrc = require('gulp-src-ordered-globs');
/**
* Source dir where all the schematics are located
*/
const srcDir = 'src';
/**
* Folder for compiled files
*/
const distDir = 'dist';
/**
* Files being watched in ./ to be copied to /dist
*/
const rootFiles = [
'package.json',
'README.md'
];
/**
* Globs to select all files but .ts
*/
const allButTsGlob = [
`${srcDir}/**/*`,
`!${srcDir}/**/*.ts`,
`${srcDir}/**/*.d.ts`,
`${srcDir}/**/files/**/*.ts`
];
/**
* Run TypeScript compiler
*/
gulp.task('tsc', function() {
// use tsc.src() instead of gulp.src(...) to load files based
// on the tsconfig file: files, excludes and includes
const tsResult = tsc.src().pipe(tsc());
return tsResult.pipe(gulp.dest(`${distDir}/`));
});
/**
* Copy ./src into ./dist, but ignore .ts files
*/
gulp.task('copy:src', function() {
gulpSrc(allButTsGlob)
.pipe(gulp.dest(`${distDir}/`));
});
/**
* Copy files in 'rootFiles' into ./dist
*/
gulp.task('copy:root', function() {
gulp.src(rootFiles)
.pipe(gulp.dest(`${distDir}/`));
});
/**
* Set 'private' to false when moving the manifest to dist
* so that it becomes publishable
*/
gulp.task('edit:manifest', function() {
gulp.src('package.json')
.pipe(jeditor({
'private': false
}))
.pipe(gulp.dest(`${distDir}/`));
});
/**
* Clean dist directory
*/
gulp.task('clean', function() {
return del.sync([distDir]);
});
/**
* Watch changes and run relevant tasks
*/
gulp.task('watch', function() {
gulp.watch([
`${srcDir}/**/*.ts`,
`!${srcDir}/**/files/**/*.ts`,
`!${srcDir}/**/*.d.ts`
], ['tsc']);
gulp.watch(allButTsGlob, ['copy:src']);
gulp.watch(rootFiles, ['copy:root', 'edit:manifest']);
});
gulp.task('build', ['clean', 'tsc', 'copy:src', 'copy:root', 'edit:manifest']);
gulp.task('default', ['clean', 'build', 'watch']);