Skip to content

Commit

Permalink
add sanitize instead of bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Wang committed Jan 18, 2023
1 parent 2255fe9 commit abfa890
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Binary file modified bundle/chrome.zip
Binary file not shown.
Binary file modified bundle/firefox.zip
Binary file not shown.
Binary file modified bundle/safari.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion popup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"dev": "next dev",
"lint": "next lint",
"build": "next build && next export && mv out/_next out/next && sed -i '' -e 's/\\/_next/\\.\\/next/g' out/**.html",
"build": "next build && next export && node ./sanitize.js",
"start": "next start",
"check:prettier": "npx prettier --check .",
"write:prettier": "npx prettier --write ."
Expand Down
38 changes: 38 additions & 0 deletions popup/sanitize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Credit to @webbertakken for the gist:
// https://gist.github.com/webbertakken/ed82572b50f4e166562906757aede40a

const { readdir, readFile, rename, writeFile } = require("fs/promises")
const { resolve } = require("path")

const getFilesInDirectoryRecursively = async (directory) => {
const dirents = await readdir(directory, { withFileTypes: true })

const files = await Promise.all(
dirents.map((dirent) => {
const res = resolve(directory, dirent.name)
return dirent.isDirectory() ? getFilesInDirectoryRecursively(res) : res
})
)
return Array.prototype.concat(...files)
}

;(async () => {
// Replace underscores, which can't be used in chrome extensions
console.log(`Sanitizing for extension build...`)
await rename("out/_next", "out/next")
const files = await getFilesInDirectoryRecursively("out")
await Promise.all(
files
.filter(
(file) =>
file.endsWith(".html") || file.endsWith(".js") || file.endsWith("css")
)
.map(async (file) => {
const data = await readFile(file, "utf8")
const result = data
.replace(/\/_next\//g, "/next/")
.replace(/\\\/_next\\\//g, "\\/next\\/")
await writeFile(file, result, "utf8")
})
)
})()

0 comments on commit abfa890

Please sign in to comment.