File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed
workspaces/adventure-pack/src/scripts/build Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff line change 11import { writeFile } from "node:fs/promises" ;
22import path from "node:path" ;
33
4+ import prettier from "prettier" ;
5+
6+ import { isEnvironmentDev } from "@code-chronicles/util/isEnvironmentDev" ;
7+
48import { readAllGoodies } from "../package-goodies/readAllGoodies" ;
59import { 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}
You can’t perform that action at this time.
0 commit comments