This repository has been archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.babel.js
117 lines (99 loc) · 3.12 KB
/
gulpfile.babel.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
import fs from "fs";
import gulp from "gulp";
import gutil from "gulp-util";
import jade from "gulp-jade";
import zip from "gulp-zip";
import rename from "gulp-rename";
import eslint from "gulp-eslint";
import webpack from "webpack";
import WebpackDevServer from "webpack-dev-server";
import devConfig from "./webpack/dev.config";
import prodConfig from "./webpack/prod.config";
import {settings} from "./chrome/app/settings"
const PORT = 3000;
const DEV_FOLDER = "./dev";
const PROD_FOLDER = "./build";
const RELEASE_FOLDER = "./dist"
gulp.task("replace-webpack-code", () => {
const replaceTasks = [ {
from: "./webpack/replace/JsonpMainTemplate.runtime.js",
to: "./node_modules/webpack/lib/JsonpMainTemplate.runtime.js"
}, {
from: "./webpack/replace/log-apply-result.js",
to: "./node_modules/webpack/hot/log-apply-result.js"
} ];
replaceTasks.forEach(task => fs.writeFileSync(task.to, fs.readFileSync(task.from)));
});
gulp.task("webpack-dev-server", () => {
let myConfig = Object.create(devConfig);
new WebpackDevServer(webpack(myConfig), {
proxy: {
"*": `https://localhost:${PORT}`,
},
publicPath: myConfig.output.publicPath,
stats: {colors: true},
hot: true,
historyApiFallback: true,
https: true
})
.listen(PORT, "localhost", (err) => {
if (err) {
throw new gutil.PluginError("webpack-dev-server", err);
} else {
gutil.log("[webpack-dev-server]", `listening at port ${PORT}`);
}
});
});
gulp.task("views:dev", () => {
gulp.src("./chrome/views/*.jade")
.pipe(jade({
locals: { settings: settings.dev }
}))
.pipe(gulp.dest(DEV_FOLDER));
});
gulp.task("copy:dev", () => {
gulp.src("./chrome/manifest.dev.json")
.pipe(rename("manifest.json"))
.pipe(gulp.dest(DEV_FOLDER));
gulp.src("./chrome/assets/**/*")
.pipe(gulp.dest(DEV_FOLDER));
});
gulp.task("webpack:build", (callback) => {
let myConfig = Object.create(prodConfig);
webpack(myConfig, (err, stats) => {
if (err) {
throw new gutil.PluginError('webpack:build', err);
}
gutil.log('[webpack:build]', stats.toString({ colors: true }));
callback();
});
});
gulp.task("views:prod", () => {
gulp.src("./chrome/views/*.jade")
.pipe(jade({
locals: { settings: settings.prod }
}))
.pipe(gulp.dest(PROD_FOLDER));
});
gulp.task("copy:prod", () => {
gulp.src("./chrome/manifest.prod.json")
.pipe(rename("manifest.json"))
.pipe(gulp.dest(PROD_FOLDER));
gulp.src("./chrome/assets/**/*")
.pipe(gulp.dest(PROD_FOLDER));
});
gulp.task("zip:compress", () => {
let manifest = require(`${PROD_FOLDER}/manifest.json`);
gulp.src(`${PROD_FOLDER}/**/*`)
.pipe(zip(`${RELEASE_FOLDER}/battle-extension-${manifest.version}.zip`))
.pipe(gulp.dest("."));
});
gulp.task("eslint", () => {
return gulp.src(["**/*.js", "!node_modules/**/*", "!backend/**/*"])
.pipe(eslint({useEslintrc: true}))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task("default", ["replace-webpack-code", "webpack-dev-server", "views:dev", "copy:dev"]);
gulp.task("build", ["replace-webpack-code", "webpack:build", "views:prod", "copy:prod"]);
gulp.task("compress", ["zip:compress"]);