-
Notifications
You must be signed in to change notification settings - Fork 29
/
Gulpfile.js
93 lines (80 loc) · 2.6 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
const gulp = require("gulp");
const gulpEslint = require("gulp-eslint-new");
//var ts = require("gulp-typescript");
//var sourcemaps = require("gulp-sourcemaps");
//var tsProject = ts.createProject("tsconfig.json");
const spawn = require("child_process").spawn;
const tsj = require("ts-json-schema-generator");
const fs = require("fs");
const ts_sources = ["src/**/*.ts", "src/**/*.tsx", "!src/**/*.test.ts", "!src/**/*.test.tsx"];
const schema_sources = ["src/config.ts"];
gulp.task("watch_eslint", watch_eslint);
//gulp.task("watch_build", watch_build);
gulp.task("watch_schema", watch_schema);
gulp.task("eslint", eslint);
//gulp.task("build", build);
gulp.task("background_webpack", background_webpack);
gulp.task("schema", build_schema);
gulp.task(
"default",
gulp.series("schema", gulp.parallel("watch_eslint", "watch_schema", "background_webpack")),
);
function watch_eslint(done) {
gulp.watch(ts_sources, { ignoreInitial: false }, eslint);
done();
}
function watch_schema(done) {
gulp.watch(schema_sources, { ignoreInitial: false }, build_schema);
done();
}
/*
function watch_build(done) {
gulp.watch(ts_sources, { ignoreInitial: false }, build);
done();
}
function build(done) {
return tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write("../dist"))
.pipe(gulp.dest("dist"))
.on("end", done);
}
*/
function background_webpack(done) {
function spawn_webpack() {
let env = process.env;
let webpack = spawn("npm", ["run", "webpack-watch"], { stdio: "inherit", shell: true });
webpack.on("exit", spawn_webpack);
}
spawn_webpack();
done();
}
function build_schema(done) {
/* We reference the schema within our config.ts file, so we need to
* generate a stub for it if it doesn't already exist */
if (!fs.existsSync("schema/Config.schema.json")) {
if (!fs.existsSync("schema")) {
fs.mkdirSync("schema");
}
console.warn("Generating stub schema/Config.schema.json");
fs.writeFileSync("schema/Config.schema.json", "{}");
}
const schema = tsj
.createGenerator({
path: "src/config.ts",
type: "Config",
tsconfig: "tsconfig.json",
})
.createSchema("Config");
//fs.mkdirSync("dist", { recursive: true });
fs.writeFile("schema/Config.schema.json", JSON.stringify(schema, null, 4), done);
}
function eslint() {
return gulp
.src(ts_sources)
.pipe(gulpEslint())
.pipe(gulpEslint.format())
.pipe(gulpEslint.failAfterError());
}