Skip to content

Commit 05023ca

Browse files
authored
Pretty print goodies.json if NODE_ENV is "development" (#379)
1 parent a31077d commit 05023ca

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import { writeFile } from "node:fs/promises";
22
import path from "node:path";
33

4+
import prettier from "prettier";
5+
6+
import { isEnvironmentDev } from "@code-chronicles/util/isEnvironmentDev";
7+
48
import { readAllGoodies } from "../package-goodies/readAllGoodies";
59
import { WEBAPP_DIST } from "./constants";
610

7-
export async function writeGoodiesJson(): Promise<void> {
11+
async function readAllGoodiesAsString(): Promise<string> {
812
const goodies = await readAllGoodies();
13+
const text = JSON.stringify(goodies);
14+
15+
if (isEnvironmentDev()) {
16+
// Could also change the arguments to `JSON.stringify` but thought we
17+
// could give Prettier the chance to do something fancier.
18+
return await prettier.format(text, { parser: "json" });
19+
}
20+
21+
return text + "\n";
22+
}
23+
24+
export async function writeGoodiesJson(): Promise<void> {
25+
const text = await readAllGoodiesAsString();
926

10-
await writeFile(
11-
path.join(WEBAPP_DIST, "goodies.json"),
12-
// TODO: pretty print if NODE_ENV is "development"
13-
JSON.stringify(goodies) + "\n",
14-
);
27+
await writeFile(path.join(WEBAPP_DIST, "goodies.json"), text);
1528
}

0 commit comments

Comments
 (0)