-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check script to validate implementation info.
- Loading branch information
1 parent
df13a82
commit a0cabe6
Showing
3 changed files
with
89 additions
and
0 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,65 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
Copyright 2025 Digital Bazaar, Inc. | ||
SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
import {createRequire} from 'node:module'; | ||
import fs from 'node:fs'; | ||
import {glob} from 'glob'; | ||
import jsonld from 'jsonld'; | ||
import {JsonLdDocumentLoader} from 'jsonld-document-loader'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
// Pass in `extract` to get context list instead of safe mode check results | ||
const method = process.argv.at(2); | ||
|
||
const jdl = new JsonLdDocumentLoader(); | ||
|
||
// collection to track all loaded contexts | ||
const contextUrls = new Set(); | ||
|
||
jdl.addStatic( | ||
'https://raw.githubusercontent.com/digitalbazaar/mocha-w3c-interop-reporter/refs/heads/main/context.json', | ||
require('./context.json') | ||
); | ||
|
||
const loader = jdl.build(); | ||
jsonld.documentLoader = loader; | ||
|
||
let failure = false; | ||
const paths = await glob([ | ||
`./implementations/*.json` | ||
]); | ||
await Promise.all(paths.map(async implementationPath => { | ||
const implementation = JSON.parse( | ||
await fs.promises.readFile(implementationPath) | ||
); | ||
// non-JSON-LD description, so skip it | ||
if(!('@context' in implementation)) { | ||
return; | ||
} | ||
try { | ||
await jsonld.expand(implementation, {safe: true}); | ||
if(method !== 'extract') { | ||
console.log('👍 All terms correctly defined in', implementationPath); | ||
} | ||
} catch(err) { | ||
if(method !== 'extract') { | ||
console.log('😢 Errors found in', implementationPath); | ||
} | ||
console.dir(err, {depth: 5}); | ||
failure = true; | ||
} | ||
})); | ||
|
||
if(failure) { | ||
process.exit(1); | ||
} | ||
|
||
if(method === 'extract') { | ||
console.log(JSON.stringify([...contextUrls].sort(), null, 2)); | ||
} |
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