-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
69 lines (61 loc) · 1.64 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
import fs, { promises as fsPromises } from "node:fs";
import gulp from "gulp";
import zip from "gulp-zip";
import { rollup } from "rollup";
import { babel } from "@rollup/plugin-babel";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import terser from "@rollup/plugin-terser";
gulp.task("scripts", async () => {
const bundle = await rollup({
input: {
app: "src/app.jsx",
options: "src/options.jsx",
},
onwarn(warning, warn) {
if (warning.code === "UNRESOLVED_IMPORT") {
throw new Error(warning.message);
}
warn(warning);
},
plugins: [
nodeResolve(),
babel({
babelHelpers: "bundled",
}),
terser(),
],
});
return bundle.write({
dir: "build",
format: "es",
});
});
gulp.task("build", () =>
gulp
.src(["src/index.html", "src/options.html", "src/manifest.json"])
.pipe(gulp.dest("build")),
);
gulp.task("images", () => gulp.src("src/*img/*").pipe(gulp.dest("build")));
gulp.task("clean:build", () =>
fsPromises.rm("build", { force: true, recursive: true }),
);
gulp.task("clean:bundle", () =>
fsPromises.rm("bundle", { force: true, recursive: true }),
);
gulp.task(
"default",
gulp.series("build", "scripts", () => {
gulp.watch("src/**/*.html", gulp.series("build"));
gulp.watch("src/**/*.jsx", gulp.series("scripts"));
}),
);
const manifest = JSON.parse(fs.readFileSync("src/manifest.json", "utf8"));
gulp.task(
"bundle",
gulp.series("clean:bundle", "build", "images", "scripts", () =>
gulp
.src("build/**/*")
.pipe(zip(`trivia-for-reddit-${manifest.version}.zip`))
.pipe(gulp.dest("bundle")),
),
);