Skip to content

Commit

Permalink
refactor(wrap-stream-in-html): read template elements asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Apr 24, 2023
1 parent a4063bc commit 8a89bd8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/cli/tools/wrap-stream-in-html.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { fileURLToPath } from "node:url";

const HEADER_FILE = fileURLToPath(
Expand All @@ -25,10 +25,13 @@ const FOOTER_FILE = fileURLToPath(
* @param {readStream} pStream stream whose characters are to be slapped between header and footer
* @param {writeStream} pOutStream stream to write to
*/
export default function wrap(pInStream, pOutStream) {
const lHeader = readFileSync(HEADER_FILE, "utf8");
const lScript = readFileSync(SCRIPT_FILE, "utf8");
const lEnd = readFileSync(FOOTER_FILE, "utf8");
export default async function wrap(pInStream, pOutStream) {
const [lHeader, lScript, lEnd] = await Promise.all([
readFile(HEADER_FILE, "utf8"),
readFile(SCRIPT_FILE, "utf8"),
readFile(FOOTER_FILE, "utf8"),
]);

const lFooter = `<script>${lScript}</script>${lEnd}`;

pOutStream.write(lHeader);
Expand Down

0 comments on commit 8a89bd8

Please sign in to comment.