| 112 | const firefox = new ZipWriter({ outputAs: "uint8array" }); |
| 113 | |
| 114 | async function addDir(zip, localDir, toDir, filters) { |
| 115 | const sub = async (localDir, toDir) => { |
| 116 | const files = await fs.readdir(localDir); |
| 117 | for (const file of files) { |
| 118 | if (filters?.includes(file)) { |
| 119 | continue; |
| 120 | } |
| 121 | const localPath = `${localDir}/${file}`; |
| 122 | const toPath = `${toDir}${file}`; |
| 123 | const stats = await fs.stat(localPath); |
| 124 | if (stats.isDirectory()) { |
| 125 | await sub(localPath, `${toPath}/`); |
| 126 | } else { |
| 127 | await addZipFile(zip, toPath, await fs.readFile(localPath)); |
| 128 | } |
| 129 | } |
| 130 | }; |
| 131 | await sub(localDir, toDir); |
| 132 | } |
| 133 | |
| 134 | await addZipFile(chrome, "manifest.json", JSON.stringify(chromeManifest)); |
| 135 | await addZipFile(firefox, "manifest.json", JSON.stringify(firefoxManifest)); |