-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Wang
committed
Jan 18, 2023
1 parent
2255fe9
commit abfa890
Showing
5 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
}) | ||
) | ||
})() |