Skip to content

Commit

Permalink
refactor and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
samizdatco committed Apr 25, 2023
1 parent 5cb902b commit aee3181
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 0 additions & 2 deletions devTools/regionsImporter/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ The data file is used primarily for:
- determining whether entities are states and which of those have country pages (see `regions.ts`)
- establishing region → country mappings (see `WorldRegionsToProjection.ts`)


## Updating Region Data

The `regions.json` file can be updated manually by running `yarn importRegions` which triggers the `update.ts` script in `devTools/regionsImporter` and prints out a diff if anything has changed. If, after looking over the changes, everything looks good-to-go you can commit the updated `regions.json` and merge back into `master`.

> Note: pay particular attention to changes in `slug` values for countries since this determines the URL of their country page. If a slug changes, be sure to add a redirect from the old value to the new one in WordPress.
16 changes: 7 additions & 9 deletions devTools/regionsImporter/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,26 @@ async function main() {
.value()
})

// generate new regions.json file compare to old version
// generate new regions.json file and compare to old version
let newRegions = prettifiedJson(entities),
oldRegions = await readFile(GRAPHER_REGIONS_PATH).catch((e) => ""),
newHash = createHash("md5").update(newRegions).digest("hex"),
oldHash = createHash("md5").update(oldRegions).digest("hex")
oldHash = createHash("md5").update(oldRegions).digest("hex"),
message = newHash === oldHash ? "No changes" : "Contents changed"
await writeFile(GRAPHER_REGIONS_PATH, newRegions)

// report changes (if any)
console.log(
`${
newHash === oldHash ? "No changes" : "Contents changed"
}: ${GRAPHER_REGIONS_PATH}`
)

console.log(`${message}: ${GRAPHER_REGIONS_PATH}`)
if (newHash !== oldHash) {
let diff = execFileSync("git", [
"diff",
"--color=always",
GRAPHER_REGIONS_PATH,
])
console.log(diff.toString())
console.log("Be sure to set up redirects for any slugs that have changed")
console.log(
"Be sure to set up redirects for any slugs that have changed"
)
}
}

Expand Down

0 comments on commit aee3181

Please sign in to comment.