Skip to content

Commit

Permalink
chore: change use of prettier API to async
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelgerber committed Oct 16, 2023
1 parent 3c22261 commit a991d64
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions devTools/regionsUpdater/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface Entity {
members?: string[]
}

function prettifiedJson(obj: any) {
function prettifiedJson(obj: any): Promise<string> {
// make sure the json we emit is diff-able even after running prettier on the repo
return prettier.format(JSON.stringify(obj), {
parser: "json",
Expand All @@ -70,7 +70,7 @@ function csvToJson(val: string, col: string) {
}
}

function prettifiedTopology(geoJson: FeatureCollection) {
function prettifiedTopology(geoJson: FeatureCollection): Promise<string> {
// 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),
Expand All @@ -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 {
Expand Down Expand Up @@ -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", [
Expand Down

0 comments on commit a991d64

Please sign in to comment.