Skip to content

Commit

Permalink
Replace custom writeAsJSONFile by fs.writeJson
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesboeufs committed Feb 22, 2022
1 parent 343fe6c commit c181d73
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
14 changes: 3 additions & 11 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const {promisify} = require('util')
const {writeJson} = require('fs-extra')
const {chain, pick} = require('lodash')
const {getLatestFIMOCTFileBuffer} = require('./download-fimoct')
const {extractFromFIMOCT} = require('./extract-fimoct')
const {expandWithCommune} = require('./communes')

const writeFile = promisify(fs.writeFile)

function writeAsJSONFile(path, codesPostaux) {
const data = codesPostaux.map(cp => JSON.stringify(cp)).join(',\n')
return writeFile(path, '[\n' + data + '\n]')
}

const COMPACT_KEYS = ['codePostal', 'codeCommune', 'nomCommune', 'libelleAcheminement']

function buildCompact(codesPostaux) {
Expand Down Expand Up @@ -58,9 +50,9 @@ async function main() {
const buffer = await getLatestFIMOCTFileBuffer()
const codesPostaux = expandWithDefault(await extractFromFIMOCT(buffer))
for (const item of codesPostaux) expandWithCommune(item)
await writeAsJSONFile(path.join(__dirname, '..', 'codes-postaux-full.json'), codesPostaux)
await writeJson(path.join(__dirname, '..', 'codes-postaux-full.json'), codesPostaux)
const codesPostauxCompact = buildCompact(codesPostaux)
await writeAsJSONFile(path.join(__dirname, '..', 'codes-postaux.json'), codesPostauxCompact)
await writeJson(path.join(__dirname, '..', 'codes-postaux.json'), codesPostauxCompact)
}

main().catch(error => {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"ava": "^4.0.1",
"csv-parser": "^3.0.0",
"decompress": "^4.2.1",
"fs-extra": "^10.0.0",
"get-stream": "^6.0.1",
"got": "^11.8.3",
"into-stream": "^6.0.0",
Expand All @@ -44,12 +45,14 @@
"space": 2,
"rules": {
"curly": "off",
"comma-dangle": ["error", "never"],
"comma-dangle": [
"error",
"never"
],
"unicorn/prefer-module": "off",
"unicorn/prefer-string-slice": "off",
"import/extensions": "off",
"node/prefer-global/process": "off"

}
},
"engines": {
Expand Down
34 changes: 31 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
dependencies:
"@types/node" "*"

"@typescript-eslint/eslint-plugin@*":
"@typescript-eslint/eslint-plugin@^5.11.0":
version "5.12.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.1.tgz#b2cd3e288f250ce8332d5035a2ff65aba3374ac4"
integrity sha512-M499lqa8rnNK7mUv74lSFFttuUsubIRdAbHcVaP93oFcKkEmHmLqy2n7jM9C8DVmFMYK61ExrZU6dLYhQZmUpw==
Expand All @@ -184,7 +184,7 @@
semver "^7.3.5"
tsutils "^3.21.0"

"@typescript-eslint/parser@*":
"@typescript-eslint/parser@^5.11.0":
version "5.12.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.12.1.tgz#b090289b553b8aa0899740d799d0f96e6f49771b"
integrity sha512-6LuVUbe7oSdHxUWoX/m40Ni8gsZMKCi31rlawBHt7VtW15iHzjbpj2WLiToG2758KjtCCiLRKZqfrOdl3cNKuw==
Expand Down Expand Up @@ -1081,7 +1081,7 @@ eslint-config-prettier@^8.3.0:
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.4.0.tgz#8e6d17c7436649e98c4c2189868562921ef563de"
integrity sha512-CFotdUcMY18nGRo5KGsnNxpznzhkopOcOo0InID+sgQssPrzjvsyKZPvOgymTFeHrFuC3Tzdf2YndhXtULK9Iw==

eslint-config-xo-typescript@*:
eslint-config-xo-typescript@^0.50.0:
version "0.50.0"
resolved "https://registry.yarnpkg.com/eslint-config-xo-typescript/-/eslint-config-xo-typescript-0.50.0.tgz#59a0a704fbd667592ca3ddcc599b9f8c855e4ebe"
integrity sha512-Ru2tXB8y2w9fFHLm4v2AVfY6P81UbfEuDZuxEpeXlfV65Ezlk0xO4nBaT899ojIFkWfr60rP9Ye4CdVUUT1UYg==
Expand Down Expand Up @@ -1558,6 +1558,15 @@ from2@^2.3.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
Expand Down Expand Up @@ -1734,6 +1743,11 @@ graceful-fs@^4.1.10, graceful-fs@^4.1.2:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"

graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.9"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96"
integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==

graceful-fs@^4.2.4:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
Expand Down Expand Up @@ -2270,6 +2284,15 @@ json5@^2.2.0:
dependencies:
minimist "^1.2.5"

jsonfile@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
dependencies:
universalify "^2.0.0"
optionalDependencies:
graceful-fs "^4.1.6"

keyv@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.0.1.tgz#9fe703cb4a94d6d11729d320af033307efd02ee6"
Expand Down Expand Up @@ -3559,6 +3582,11 @@ unc-path-regex@^0.1.2:
resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
integrity sha1-5z3T17DXxe2G+6xrCufYxqadUPo=

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

uri-js@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.2.2.tgz#94c540e1ff772956e2299507c010aea6c8838eb0"
Expand Down

0 comments on commit c181d73

Please sign in to comment.