forked from noodlebox/KawaiiDiscord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
78 lines (66 loc) · 3.13 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
const gulp = require("gulp"),
header = require("gulp-header"),
footer = require("gulp-footer"),
rename = require("gulp-rename"),
uglify = require("gulp-uglify"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
zip = require("gulp-zip"),
_ = require("lodash"),
generateUserscriptHeader = require("generate-userscript-header");
const pkg = require("./package.json");
const safeName = _.camelCase(pkg.name);
gulp.task("browserify", function () {
const pluginInfo = [
"var <%= safeName %> = window.<%= safeName %> = window.<%= safeName %>.default;",
"<%= safeName %>.prototype.getName = function () { return <% print(JSON.stringify(pkg.name)) %>; };",
"<%= safeName %>.prototype.getAuthor = function () { return <% print(JSON.stringify(pkg.author)) %>; };",
"<%= safeName %>.prototype.getVersion = function () { return <% print(JSON.stringify(pkg.version)) %>; };",
"<%= safeName %>.prototype.getDescription = function () { return <% print(JSON.stringify(pkg.description)) %>; };",
"",
].join("\n");
return browserify("./src/js/main.js", {standalone: safeName})
.transform("strictify")
.transform("babelify", {plugins: ["lodash"], presets: ["es2015"]})
.bundle()
.pipe(source("KawaiiDiscord.bundle.js"))
.pipe(buffer())
.pipe(footer(pluginInfo, {pkg, safeName}))
.pipe(uglify())
.pipe(gulp.dest("./build"));
});
gulp.task("userscript", ["browserify"], function () {
const bootstrap = "(function (plugin) { var p = new plugin(); p.load(); p.start(); })(<%= safeName %>);";
return gulp.src("./build/KawaiiDiscord.bundle.js")
.pipe(rename("KawaiiDiscord.user.js"))
.pipe(footer(bootstrap, {safeName}))
.pipe(header(generateUserscriptHeader(pkg.userscript, {pkg})))
.pipe(gulp.dest("./dist"));
});
gulp.task("bdplugin", ["browserify"], function () {
const bdPluginHeader = "//META<% print(JSON.stringify({name: safeName})) %>*//\n\n";
return gulp.src("./build/KawaiiDiscord.bundle.js")
.pipe(rename("KawaiiDiscord.plugin.js"))
.pipe(header(bdPluginHeader, {pkg, safeName}))
.pipe(gulp.dest("./dist"));
});
gulp.task("build_extension", ["browserify"], function () {
gulp.src("./manifest.json")
.pipe(gulp.dest("./build/extension/"));
gulp.src("./src/js/cspwhitelist.js")
.pipe(gulp.dest("./build/extension/"));
gulp.src("./src/js/inject.js")
.pipe(gulp.dest("./build/extension/"));
const bootstrap = "(function (plugin) { var p = new plugin(); p.load(); p.start(); })(<%= safeName %>);";
return gulp.src("./build/KawaiiDiscord.bundle.js")
.pipe(rename("KawaiiDiscord.extension.js"))
.pipe(footer(bootstrap, {safeName}))
.pipe(gulp.dest("./build/extension/"));
});
gulp.task("extension", ["build_extension"], function () {
return gulp.src("./build/extension/*")
.pipe(zip("KawaiiDiscord-ng.zip"))
.pipe(gulp.dest("./dist"))
});
gulp.task("default", ["userscript", "bdplugin", "extension"]);