This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 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,69 @@ | ||
const path = require('path') | ||
const ChecksCollection = require('./checksCollection') | ||
const parser = require('./parser') | ||
const namespace = require('@rdfjs/namespace') | ||
const { removeFilePart } = require('./utils') | ||
const iriResolve = require('rdf-loader-code/lib/iriResolve') | ||
|
||
const ns = { | ||
schema: namespace('http://schema.org/'), | ||
rdf: namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), | ||
p: namespace('https://pipeline.described.at/'), | ||
code: namespace('https://code.described.at/') | ||
} | ||
|
||
async function validateManifest (file, options) { | ||
const manifestPath = path.resolve(file) | ||
const manifestDir = removeFilePart(manifestPath) | ||
const manifestDirPart = manifestDir.substr(manifestDir.lastIndexOf('/') + 1) | ||
const checks = new ChecksCollection() | ||
|
||
try { | ||
const manifestGraph = await parser.readGraph(manifestPath, checks) | ||
const operations = manifestGraph.has(ns.rdf.type, ns.p.Operation) | ||
.map(operation => { | ||
const implementedBy = operation.out(ns.code.implementedBy) | ||
const codeLink = implementedBy.out(ns.code.link) | ||
const identifier = codeLink.term | ||
|
||
const { filename, method } = iriResolve(identifier.value) | ||
return { operation: operation.term.value, filename, method } | ||
}) | ||
.map(({ operation, filename, method }) => { | ||
filename = manifestDir + filename.replace(manifestDirPart, '') | ||
method = method || 'default' | ||
return { operation, filename, method } | ||
}) | ||
|
||
operations.reduce(async (promise, { operation, filename, method }) => { | ||
await promise | ||
let imported | ||
try { | ||
imported = await import(filename) | ||
} | ||
catch (err) { | ||
console.error(`Cannot import ${filename} for operation ${operation}`) | ||
} | ||
if (typeof imported[method] !== 'function') { | ||
console.error(`Fn ${method} not found in ${filename} for operation ${operation}`) | ||
} | ||
}, Promise.resolve()) | ||
} | ||
catch (err) { | ||
if (options.debug) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
checks.print(options.levels) | ||
|
||
if (!process.stdout.isTTY) { | ||
console.log(checks.filterToJSON(options.levels)) | ||
} | ||
|
||
if (checks.countIssues(options.strict)) { | ||
process.exit(-1) | ||
} | ||
} | ||
|
||
module.exports = validateManifest |
Empty file.