-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
153 lines (136 loc) · 3.85 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const gulp = require('gulp');
const fs = require('fs');
const zip = require('gulp-zip');
const del = require('del');
const merge2 = require('merge2');
function clean_task(cb) {
del([
'build',
'dist'
])
.then(function(value) {
cb();
});
}
function build_task() {
return merge2(build_dir('v2'), build_dir('v3'));
}
function build_dir(version) {
if (version !== 'v2' && version !== 'v3') {
throw Error('Version is not accepted');
}
let content_scripts = gulp.src('src/content-scripts/**')
.pipe(gulp.dest(`build/${version}/content-scripts`));
let icons = gulp.src('src/icons/**')
.pipe(gulp.dest(`build/${version}/icons`));
let lib = gulp.src('src/lib/**')
.pipe(gulp.dest(`build/${version}/lib`));
let popup = gulp.src('src/popup/**')
.pipe(gulp.dest(`build/${version}/popup`));
return merge2(content_scripts, icons, lib, popup);
};
function package_dir(version) {
fs.writeFileSync(`build/${version}/manifest.json`, buildManifest(version));
return gulp.src(`build/${version}/**`)
.pipe(zip(`potassium_manifest_${version}.zip`, { buffer: false }))
.pipe(gulp.dest('dist'));
};
function package_task(cb) {
merge2(package_dir('v2', cb), package_dir('v3', cb));
cb();
};
exports.clean = clean_task;
exports.build = build_task;
exports.package = package_task;
exports.default = gulp.series(clean_task, build_task, package_task);
function buildManifest(manifest_version, cb) {
const {
name,
version,
description,
author
} = require("./package.json");
const manifest_base = {
"name": "Potassium: Kindle Enhancer",
"version": version,
"description": description,
"author": author,
"icons": {
16: "icons/k+16.png",
32: "icons/k+32.png",
48: "icons/k+48.png",
128: "icons/k+128.png"
},
"content_scripts": [
{
"matches": [
"https://read.amazon.com/manga*"
],
"js": [
"lib/common.js",
"content-scripts/manga.js"
],
"run_at": "document_start"
},
{
"matches": [
"https://read.amazon.com/kindle-library*"
],
"js": [
"lib/common.js",
"content-scripts/kindle-library.js"
],
"run_at": "document_start"
}
]
}
const manifest_v2 = {
"manifest_version": 2,
"browser_action": {
"default_icon": {
"16": "icons/k+16.png",
"32": "icons/k+32.png"
},
"default_title": "Potassium",
"default_popup": "popup/index.html"
},
"permissions": [
"activeTab",
"https://read.amazon.com/*"
],
"web_accessible_resources": [
"js/*.js"
]
};
const manifest_v3 = {
"manifest_version": 3,
"action": {
"default_popup": "popup/index.html"
},
"permissions": [
"activeTab"
],
"host_permissions": [
"https://read.amazon.com/*"
],
"web_accessible_resources": [
{
"resources": [
"js/*.js"
],
"matches": [
"*://*/*"
]
}
]
};
if (manifest_version === 'v2') {
return JSON.stringify(Object.assign(manifest_v2, manifest_base));
}
else if (manifest_version === 'v3') {
return JSON.stringify(Object.assign(manifest_v3, manifest_base));
}
else {
return JSON.stringify({});
}
}