From a991d641e030e3db94413d4dd7f7d9943f2e36e8 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Mon, 16 Oct 2023 16:36:06 +0200 Subject: [PATCH] chore: change use of prettier API to async --- devTools/regionsUpdater/update.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/devTools/regionsUpdater/update.ts b/devTools/regionsUpdater/update.ts index 46194268fe0..264e208df94 100644 --- a/devTools/regionsUpdater/update.ts +++ b/devTools/regionsUpdater/update.ts @@ -47,7 +47,7 @@ interface Entity { members?: string[] } -function prettifiedJson(obj: any) { +function prettifiedJson(obj: any): Promise { // make sure the json we emit is diff-able even after running prettier on the repo return prettier.format(JSON.stringify(obj), { parser: "json", @@ -70,7 +70,7 @@ function csvToJson(val: string, col: string) { } } -function prettifiedTopology(geoJson: FeatureCollection) { +function prettifiedTopology(geoJson: FeatureCollection): Promise { // make sure the MapTopology.ts file will be diff-able even after running prettier on the repo let topoData = topology({ world: geoJson }), arcs = _.remove(topoData.arcs), @@ -94,11 +94,10 @@ function prettifiedTopology(geoJson: FeatureCollection) { parser: "typescript", tabWidth: 4, semi: false, - }) - .replace( + }).then(formatted => formatted.replace( /^( arcs:\s*\[)\]/m, `\n // prettier-ignore\n$1\n ${arcJson}\n ]` - ) + )) } function transformGeography(orig: FeatureCollection): FeatureCollection { @@ -258,13 +257,13 @@ async function main() { }) // generate new MapTopology.ts file and compare to old version - let newTopology = prettifiedTopology(owidGeoJson) + let newTopology = await prettifiedTopology(owidGeoJson) if (await didChange(GRAPHER_TOPOLOGY_PATH, newTopology)) { await writeFile(GRAPHER_TOPOLOGY_PATH, newTopology) } // generate new regions.json file and compare to old version - let regionsJson = prettifiedJson(entities) + let regionsJson = await prettifiedJson(entities) if (await didChange(GRAPHER_REGIONS_PATH, regionsJson)) { await writeFile(GRAPHER_REGIONS_PATH, regionsJson) let diff = execFileSync("git", [