This repository has been archived by the owner on Feb 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmanifest.config.js
124 lines (111 loc) · 2.91 KB
/
manifest.config.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
import { fileURLToPath } from "url";
import path from "path";
import fs from "fs";
const manifestFileName = "manifest.json";
const appManifestPath = "dist/.vite";
const contentManifestPath = "dist/content/.vite";
const relayManifestPath = "dist/relay/.vite";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "package.json"), "utf8")
);
const appManifestJson = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, appManifestPath, manifestFileName),
"utf8"
)
);
const contentManifestJson = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, contentManifestPath, manifestFileName),
"utf8"
)
);
const relayManifestJson = JSON.parse(
fs.readFileSync(
path.resolve(__dirname, relayManifestPath, manifestFileName),
"utf8"
)
);
const { author, description, manifest, name, version } = packageJson;
const contentJS = `content/${contentManifestJson[manifest.content].file}`;
const relayJS = `relay/${relayManifestJson[manifest.relay].file}`;
const manifestData = {
manifest_version: 3,
name,
description,
author,
version: version,
version_name: version,
action: {
default_icon: {
16: "icon16.png",
32: "icon32.png",
48: "icon48.png",
64: "icon64.png",
128: "icon128.png",
},
default_popup: "popup.html",
},
background: {
service_worker: appManifestJson[manifest.background].file,
type: "module",
},
content_scripts: [
{
js: [contentJS],
matches: ["<all_urls>"],
world: "MAIN",
},
{
js: [relayJS],
matches: ["<all_urls>"],
},
],
content_security_policy: {
extension_pages:
"script-src 'self' 'wasm-unsafe-eval' http://localhost;object-src 'self';",
},
host_permissions: ["https://*/*"],
icons: {
16: "icon16.png",
32: "icon32.png",
48: "icon48.png",
64: "icon64.png",
128: "icon128.png",
},
permissions: ["storage"],
web_accessible_resources: [
{
matches: ["<all_urls>"],
resources: ["wallet-core.wasm"],
use_dynamic_url: false,
},
{
matches: ["<all_urls>"],
resources: [contentJS, relayJS],
use_dynamic_url: true,
},
],
};
fs.writeFileSync(
path.resolve(__dirname, "dist", manifestFileName),
JSON.stringify(manifestData, null, 2),
"utf8"
);
function deleteFolderRecursive(folderPath) {
if (fs.existsSync(folderPath)) {
fs.readdirSync(folderPath).forEach((file) => {
const currentPath = path.join(folderPath, file);
if (fs.lstatSync(currentPath).isDirectory()) {
deleteFolderRecursive(currentPath);
} else {
fs.unlinkSync(currentPath);
}
});
fs.rmdirSync(folderPath);
}
}
deleteFolderRecursive(path.resolve(__dirname, appManifestPath));
deleteFolderRecursive(path.resolve(__dirname, contentManifestPath));
deleteFolderRecursive(path.resolve(__dirname, relayManifestPath));