-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
mergeManifest.js
50 lines (40 loc) · 1.18 KB
/
mergeManifest.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
const { Reporter } = require("@parcel/plugin")
const fs = require("fs").promises
module.exports = new Reporter({
async report({ event }) {
const target = process.env.HOPP_EXTENSION_TARGET
if (!target) {
return
}
if (event.type == "buildSuccess") {
const manifestCommon = (
await fs.readFile("./manifest.common.json")
).toString()
let targetManifestFilePath
if (target == "CHROME") {
targetManifestFilePath = "./manifest.chrome.json"
} else if (target == "FIREFOX") {
targetManifestFilePath = "./manifest.firefox.json"
} else {
return
}
const targetSpecificManifest = (
await fs.readFile(targetManifestFilePath)
).toString()
const manifestFinal = JSON.stringify(
{
...JSON.parse(manifestCommon),
...JSON.parse(targetSpecificManifest),
},
null,
2
)
// make sure the ./dist folder exists
await fs.mkdir("./dist").catch(() => {})
await fs.writeFile("./dist/manifest.json", manifestFinal, {
flag: "w",
})
process.stdout.write("💚 Manifest File Written Successfully")
}
},
})