-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from hereje/feat/migrate-to-esm
- Loading branch information
Showing
33 changed files
with
409 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
const fs = require("fs") | ||
const path = require("path") | ||
const mkdirp = require("mkdirp") | ||
const ndjson = require("./ndjson") | ||
import fs from "node:fs" | ||
import path, { dirname } from "node:path" | ||
import { fileURLToPath } from "node:url" | ||
import { mkdirp } from "mkdirp" | ||
import * as ndjson from "./ndjson.js" | ||
|
||
const getMappingSchemes = require("./queries/get-mapping-schemes") | ||
|
||
const cache = path.resolve(__dirname, "../cache") | ||
const assets = path.resolve(__dirname, "../assets") | ||
import getMappingSchemes from "./queries/get-mapping-schemes.js" | ||
|
||
module.exports = { | ||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
updateMappingSchemes() { | ||
mkdirp.sync(cache) | ||
return getMappingSchemes() | ||
.then( schemes => { | ||
ndjson.write(schemes, `${cache}/mapping-schemes.ndjson`) | ||
return schemes | ||
}) | ||
}, | ||
const cache = path.resolve(__dirname, "../cache") | ||
const assets = path.resolve(__dirname, "../assets") | ||
|
||
loadMappingSchemes() { | ||
const cachedSchemes = `${cache}/mapping-schemes.ndjson` | ||
const assetsSchemes = `${assets}/mapping-schemes.ndjson` | ||
return ndjson.read( fs.existsSync(cachedSchemes) ? cachedSchemes : assetsSchemes ) | ||
}, | ||
export function updateMappingSchemes() { | ||
mkdirp.sync(cache) | ||
return getMappingSchemes() | ||
.then(schemes => { | ||
ndjson.write(schemes, `${cache}/mapping-schemes.ndjson`) | ||
return schemes | ||
}) | ||
} | ||
|
||
export function loadMappingSchemes() { | ||
const cachedSchemes = `${cache}/mapping-schemes.ndjson` | ||
const assetsSchemes = `${assets}/mapping-schemes.ndjson` | ||
return ndjson.read(fs.existsSync(cachedSchemes) ? cachedSchemes : assetsSchemes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const fs = require("fs") | ||
import fs from "fs" | ||
|
||
module.exports = { | ||
read: (file) => { | ||
return fs.readFileSync(file).toString().split(/\n/).filter(s => s).map(JSON.parse) | ||
}, | ||
write: (data, file) => { | ||
const stream = file ? fs.createWriteStream(file) : process.stdout | ||
const objects = Array.isArray(data) ? data : [data] | ||
objects.forEach(obj => stream.write(JSON.stringify(obj) + "\n")) | ||
}, | ||
const read = (file) => { | ||
return fs.readFileSync(file).toString().split(/\n/).filter(s => s).map(JSON.parse) | ||
} | ||
|
||
const write = (data, file) => { | ||
const stream = file ? fs.createWriteStream(file) : process.stdout | ||
const objects = Array.isArray(data) ? data : [data] | ||
objects.forEach(obj => stream.write(JSON.stringify(obj) + "\n")) | ||
} | ||
|
||
export { | ||
read, | ||
write, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.