Remember to close file handle [skip ci]
This commit is contained in:
parent
0d10dc2c89
commit
615a9364f0
1 changed files with 20 additions and 16 deletions
|
|
@ -140,23 +140,27 @@ async function generate() {
|
||||||
async function generate(file) {
|
async function generate(file) {
|
||||||
try {
|
try {
|
||||||
const handle = await fs.open(file, "r")
|
const handle = await fs.open(file, "r")
|
||||||
const relative = path.relative(r("docs"), file)
|
try {
|
||||||
const archive = r(`dist/archive/v${version}/${relative}`)
|
const relative = path.relative(r("docs"), file)
|
||||||
await fs.mkdir(path.dirname(archive), {recursive: true})
|
const archive = r(`dist/archive/v${version}/${relative}`)
|
||||||
|
await fs.mkdir(path.dirname(archive), {recursive: true})
|
||||||
|
|
||||||
if (file.endsWith(".md")) {
|
if (file.endsWith(".md")) {
|
||||||
const html = compilePage(file, await handle.readFile("utf-8"))
|
const html = compilePage(file, await handle.readFile("utf-8"))
|
||||||
const minified = HTMLMinifier.minify(html, htmlMinifierConfig)
|
const minified = HTMLMinifier.minify(html, htmlMinifierConfig)
|
||||||
await fs.writeFile(archive.replace(/\.md$/, ".html"), minified)
|
await fs.writeFile(archive.replace(/\.md$/, ".html"), minified)
|
||||||
} else if (file.endsWith(".html")) {
|
} else if (file.endsWith(".html")) {
|
||||||
const html = await handle.readFile("utf-8")
|
const html = await handle.readFile("utf-8")
|
||||||
const minified = HTMLMinifier.minify(html, htmlMinifierConfig)
|
const minified = HTMLMinifier.minify(html, htmlMinifierConfig)
|
||||||
await fs.writeFile(archive, minified)
|
await fs.writeFile(archive, minified)
|
||||||
} else {
|
} else {
|
||||||
await pipeline(
|
await pipeline(
|
||||||
createReadStream(null, {fd: handle.fd}),
|
createReadStream(null, {fd: handle.fd}),
|
||||||
createWriteStream(archive)
|
createWriteStream(archive)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
handle.close()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.code !== "EISDIR") throw e
|
if (e.code !== "EISDIR") throw e
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue