-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prefetch frequently used contexts in OA v4
- Loading branch information
Showing
5 changed files
with
416 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { ContextUrl, urlToSafeFilename } from "../src/4.0/context"; | ||
|
||
const OUTPUT_DIR = path.resolve("./src/4.0/contexts/__generated__"); | ||
|
||
// make sure the output directory exists | ||
if (fs.existsSync(OUTPUT_DIR)) { | ||
fs.rmSync(OUTPUT_DIR, { recursive: true }); | ||
} | ||
fs.mkdirSync(OUTPUT_DIR, { recursive: true }); | ||
|
||
const CONTEXTS_TO_FETCH = Object.values(ContextUrl); | ||
|
||
for (const url of CONTEXTS_TO_FETCH) { | ||
fetch(url) | ||
.then((res) => res.json()) | ||
.then((context) => { | ||
const filename = urlToSafeFilename(url); | ||
fs.writeFileSync(path.join(OUTPUT_DIR, filename), JSON.stringify(context, null, 2)); | ||
}) | ||
.catch((err) => { | ||
console.error(`Unable to fetch OA v4.0 context`, err); | ||
}); | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...s/__generated__/https---schemata.openattestation.com-com-openattestation-4.0-context.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.