-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgulpfile.ts
122 lines (112 loc) · 2.68 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
import del from "del";
import { dest, parallel, series, src, watch as gulpWatch } from "gulp";
import prettier = require("gulp-prettier");
import { init, write } from "gulp-sourcemaps";
import gtslint from "gulp-tslint";
import { createProject, Project } from "gulp-typescript";
import merge from "merge-stream";
import { Linter } from "tslint";
import tsc from "typescript";
let tsProject: Project;
createTsProject(null);
function createTsProject(cb: any) {
tsProject = createProject("tsconfig.json", {
declaration: true,
typescript: tsc,
});
if (cb) {
cb();
}
}
export function clean() {
return del(["generators/**", "types/*", "!types/gulp-prettier.d.ts"]);
}
export function pretty() {
return src([
"gulpfile.ts",
"**/*.json",
"**/*.md",
"src/**/*.yml",
"!CHANGELOG.md",
"!node_modules{,/**}",
"!generators{,/**}",
"!coverage/{,/**}",
"!**/obj/{,/**}",
"!__tests__/**/*.json",
]).pipe(prettier.check());
}
export function prettyFix() {
return src([
"gulpfile.ts",
"**/*.json",
"**/*.md",
"{src,__tests__}/**/*.ts",
"src/**/*.yml",
"!CHANGELOG.md",
"!node_modules{,/**}",
"!generators{,/**}",
"!coverage/{,/**}",
"!**/obj/{,/**}",
"!__tests__/**/*.json",
])
.pipe(prettier())
.pipe(dest("."));
}
export function lint() {
const program = Linter.createProgram("tsconfig.json");
return src("{src,__tests__}/**/*.ts")
.pipe(prettier.check())
.pipe(
gtslint({
formatter: "stylish",
program,
})
)
.pipe(
gtslint.report({
allowWarnings: true,
})
);
}
function exportTemplatesTask() {
return src(["src/**/templates/**", "src/**/templates/**/.*"]).pipe(
dest("generators")
);
}
function compileTypescript() {
const tsResult = src("src/**/*.ts").pipe(init()).pipe(tsProject());
return merge([
src("src/**/*.d.ts"),
tsResult.dts,
tsResult.js.pipe(write(".")),
]).pipe(dest("generators"));
}
function watchTask() {
gulpWatch("src/**/*.ts", series(lint, compileTypescript));
gulpWatch("__tests__/**/*.ts", lint);
gulpWatch("src/**/templates/**", exportTemplatesTask);
gulpWatch(
["tsconfig.json", "tslint.json"],
series(createTsProject, lint, pretty, compileTypescript)
);
gulpWatch(
[
"gulpfile.ts",
"**/*.json",
"**/*.md",
"**/*.yml",
"!node_modules{,/**}",
"!tsconfig.json",
"!tslint.json",
"!generators{,/**}",
"!coverage/{,/**}",
],
pretty
);
}
export const build = series(
parallel(clean, lint, pretty),
parallel(compileTypescript, exportTemplatesTask)
);
export const watch = series(build, watchTask);
export default build;