2022-03-16 23:53:11 +08:00
|
|
|
const { webpack } = require("webpack");
|
2022-02-07 07:25:13 +08:00
|
|
|
const eslint = require("gulp-eslint-new");
|
2022-03-18 22:40:40 +08:00
|
|
|
const { task, src, series, watch } = require("gulp");
|
2023-09-04 19:29:18 +08:00
|
|
|
const { resolve } = require("path");
|
|
|
|
const fs = require("fs");
|
2022-03-17 03:57:30 +08:00
|
|
|
const webpackDevConfig = require("./webpack/config.dev.js");
|
|
|
|
const webpackProdConfig = require("./webpack/config.prod.js");
|
2022-02-19 01:08:22 +08:00
|
|
|
|
2022-03-18 04:00:20 +08:00
|
|
|
const JSONValidation = require("./scripts/json-validation");
|
2022-02-13 04:02:29 +08:00
|
|
|
const eslintConfig = "../.eslintrc.json";
|
2020-11-13 15:12:53 +08:00
|
|
|
|
2022-02-12 06:34:40 +08:00
|
|
|
task("lint", function () {
|
2022-09-22 19:42:54 +08:00
|
|
|
return src(["./src/ts/**/*.ts"])
|
2022-02-08 01:44:45 +08:00
|
|
|
.pipe(eslint(eslintConfig))
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError());
|
|
|
|
});
|
|
|
|
|
|
|
|
task("lint-json", function () {
|
2022-09-22 19:42:54 +08:00
|
|
|
return src("./static/**/*.json")
|
2022-02-08 01:16:38 +08:00
|
|
|
.pipe(eslint(eslintConfig))
|
|
|
|
.pipe(eslint.format())
|
|
|
|
.pipe(eslint.failAfterError());
|
|
|
|
});
|
|
|
|
|
2022-02-18 06:36:40 +08:00
|
|
|
task("validate-json-schema", function () {
|
2022-02-19 02:25:33 +08:00
|
|
|
return JSONValidation.validateAll();
|
2022-02-18 06:36:40 +08:00
|
|
|
});
|
|
|
|
|
2022-03-18 04:00:20 +08:00
|
|
|
const taskWithWebpackConfig = (webpackConfig) => {
|
|
|
|
return async () => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
webpack(webpackConfig, (err, stats) => {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
if (stats.hasErrors()) {
|
|
|
|
return reject(new Error(stats.compilation.errors.join("\n")));
|
|
|
|
}
|
|
|
|
console.log(
|
|
|
|
`Finished building in ${
|
|
|
|
(stats.endTime - stats.startTime) / 1000
|
|
|
|
} second(s)`
|
|
|
|
);
|
|
|
|
resolve();
|
|
|
|
});
|
2022-02-12 21:47:36 +08:00
|
|
|
});
|
2022-03-18 04:00:20 +08:00
|
|
|
};
|
|
|
|
};
|
2022-02-11 19:46:19 +08:00
|
|
|
|
2022-03-18 04:00:20 +08:00
|
|
|
task("webpack", taskWithWebpackConfig(webpackDevConfig));
|
|
|
|
task("webpack-production", taskWithWebpackConfig(webpackProdConfig));
|
2020-11-13 15:12:53 +08:00
|
|
|
|
2022-03-18 22:40:40 +08:00
|
|
|
task("compile", series("lint", "lint-json", "webpack"));
|
2022-02-12 21:47:36 +08:00
|
|
|
|
|
|
|
task(
|
|
|
|
"compile-production",
|
2022-03-18 22:40:40 +08:00
|
|
|
series("lint", "lint-json", "validate-json-schema", "webpack-production")
|
2020-11-13 15:12:53 +08:00
|
|
|
);
|
2020-11-03 09:53:53 +08:00
|
|
|
|
|
|
|
task("watch", function () {
|
2022-04-24 23:20:30 +08:00
|
|
|
watch(["./src/ts/**/*.ts", "./src/ts/*.ts"], series("lint"));
|
2022-03-18 04:00:20 +08:00
|
|
|
watch(["./static/**/*.*", "./static/*.*"], series("lint-json"));
|
2020-11-03 09:53:53 +08:00
|
|
|
});
|
|
|
|
|
2022-03-18 22:40:40 +08:00
|
|
|
task("build", series("compile"));
|
2022-02-19 01:14:39 +08:00
|
|
|
|
2022-03-18 22:40:40 +08:00
|
|
|
task("build-production", series("compile-production"));
|
2022-02-19 01:14:39 +08:00
|
|
|
|
2022-02-19 02:25:33 +08:00
|
|
|
//PR CHECK
|
2022-02-19 01:14:39 +08:00
|
|
|
|
2022-02-19 02:25:33 +08:00
|
|
|
task("validate-quote-json-schema", function () {
|
|
|
|
return JSONValidation.validateQuotes();
|
|
|
|
});
|
|
|
|
|
|
|
|
task("validate-language-json-schema", function () {
|
|
|
|
return JSONValidation.validateLanguages();
|
|
|
|
});
|
|
|
|
|
|
|
|
task("validate-other-json-schema", function () {
|
|
|
|
return JSONValidation.validateOthers();
|
|
|
|
});
|
|
|
|
|
|
|
|
task("pr-check-lint-json", series("lint-json"));
|
|
|
|
task("pr-check-quote-json", series("validate-quote-json-schema"));
|
|
|
|
task("pr-check-language-json", series("validate-language-json-schema"));
|
|
|
|
task("pr-check-other-json", series("validate-other-json-schema"));
|
|
|
|
|
|
|
|
task("pr-check-lint", series("lint"));
|
2022-02-19 01:14:39 +08:00
|
|
|
|
2022-02-19 02:25:33 +08:00
|
|
|
task("pr-check-ts", series("webpack-production"));
|