forked from coralproject/talk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (74 loc) · 2.26 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
const path = require("path");
const json = require("comment-json");
const fs = require("fs");
const del = require("del");
const gulp = require("gulp");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const babel = require("gulp-babel");
const generateTypescriptTypes = require("./scripts/generateSchemaTypes");
const _ = require("lodash");
// Parse the tsconfig.json file (which contains comments).
const tsconfig = json.parse(fs.readFileSync("./src/tsconfig.json").toString());
// Create the typescript project.
const tsProject = ts.createProject("./src/tsconfig.json");
const resolveDistFolder = (...paths) => "./" + path.join("dist", ...paths);
gulp.task("clean", () => del([resolveDistFolder()]));
gulp.task("server:schema", () => generateTypescriptTypes());
gulp.task("server:scripts", () =>
gulp
.src(
[
"./src/**/*.ts",
"./src/**/.*.ts",
// Exclude client files from this, that's for webpack.
"!./src/core/client/**/*.ts",
"!./src/core/client/**/.*.ts",
],
{ base: "src" }
)
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(
babel({
plugins: [
[
"module-resolver",
{
root: [resolveDistFolder()],
alias: _.reduce(
tsconfig.compilerOptions.paths,
(alias, [pathGlob], prefixBlob) => ({
...alias,
[prefixBlob.replace(/\/\*/g, "")]: pathGlob
.replace(/\/\*/g, "")
.replace(/^\./g, resolveDistFolder()),
}),
{}
),
},
],
],
})
)
.pipe(sourcemaps.write(".", { sourceRoot: "../src" }))
.pipe(gulp.dest(resolveDistFolder()))
);
gulp.task("server:static", () =>
gulp
.src(["./src/core/server/**/*", "!./src/core/server/**/*.ts"])
.pipe(gulp.dest(resolveDistFolder() + "/core/server"))
);
gulp.task("locales", () =>
gulp
.src(["./src/locales/**/*"])
.pipe(gulp.dest(resolveDistFolder() + "/locales"))
);
gulp.task(
"server",
gulp.series(
"server:schema",
gulp.parallel("server:scripts", "server:static", "locales")
)
);
gulp.task("default", gulp.series("clean", "server"));