-
Notifications
You must be signed in to change notification settings - Fork 281
/
Copy pathgulpfile.js
139 lines (119 loc) · 2.97 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const child = require("child_process");
const fs = require("fs");
const gulp = require("gulp");
const terser = require("gulp-terser");
const ts = require("gulp-typescript");
const replace = require("gulp-replace");
const pkg = require("./package.json");
process.env.LUCI_VERSION = pkg.version;
process.env.LUCI_RELEASE = pkg.release;
const resDest = "package/htdocs/luci-static/resources";
const tsProject = ts.createProject("tsconfig.json");
function clean(...paths) {
return child.spawn("rm", ["-rf", ...paths]);
}
function replaceEnvs() {
return replace(/process\.env\.(\w+)/g, function (_, pl) {
return JSON.stringify(process.env[pl]);
});
}
gulp.task("clean-package", function () {
return clean("package");
});
gulp.task("clean-output", function () {
return clean("output");
});
gulp.task("compile", function () {
return tsProject
.src()
.pipe(tsProject())
.js.pipe(
terser({
parse: {
// allow 'return' outside of function
bare_returns: true,
},
compress: {
directives: false,
},
mangle: {},
output: {
comments: "some",
beautify: false,
},
})
)
.pipe(replaceEnvs())
.pipe(gulp.dest("output"));
});
gulp.task("compile:test", function () {
return tsProject
.src()
.pipe(tsProject())
.js.pipe(
terser({
parse: {
bare_returns: true,
},
compress: false,
mangle: false,
output: {
comments: "some",
beautify: true,
indent_level: 2,
},
})
)
.pipe(replaceEnvs())
.pipe(gulp.dest("output"));
});
gulp.task("copy-output", function () {
return gulp.src("output/**").pipe(gulp.dest(resDest));
});
gulp.task("build", gulp.series("clean-output", "compile", "copy-output"));
gulp.task(
"build:test",
gulp.series("clean-output", "compile:test", "copy-output")
);
gulp.task("copy-makefile", function () {
return gulp
.src("public/Makefile")
.pipe(
replace(/#\{(\w+)\}/g, function (_, pl) {
return pkg[pl];
})
)
.pipe(gulp.dest("package"));
});
gulp.task("copy-public", function () {
return gulp
.src(["public/luasrc/**/*", "public/po/**/*.po", "public/root/**/*"], {
cwd: ".",
base: "public",
dot: false,
})
.pipe(gulp.dest("package"));
});
gulp.task(
"test",
gulp.series(
"clean-package",
gulp.parallel("build:test", "copy-public", "copy-makefile")
)
);
gulp.task("i18n:scan", function () {
const scan = child.spawn("./scripts/i18n-scan.pl", ["package"]);
scan.stdout.pipe(fs.createWriteStream("public/po/templates/v2ray.pot"));
return scan;
});
gulp.task("i18n:update", function () {
return child.spawn("./scripts/i18n-update.pl", ["public/po"]);
});
gulp.task("i18n:sync", gulp.series("test", "i18n:scan", "i18n:update"));
gulp.task(
"default",
gulp.series(
"clean-package",
gulp.parallel("build", "copy-public", "copy-makefile")
)
);