Skip to content

Commit

Permalink
Adding support to read JSON frame from a file
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed May 11, 2022
1 parent 6ec6097 commit d14d336
Show file tree
Hide file tree
Showing 2 changed files with 5,862 additions and 19 deletions.
14 changes: 12 additions & 2 deletions bin/ldfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var ldfetch = require('../lib/ldfetch.js');
var fetch = new ldfetch();
var n3 = require('n3');
var program = require('commander');
var path = require('path');
var fs = require('fs');

var url = "";
console.error('LDFetch. Use --help to discover more instructions');
Expand All @@ -13,7 +15,7 @@ var list = function (val) {

program
.option('-p, --predicates <predicates ...>', 'Some predicates can be followed [predicates]', list)
.option('--frame <jsonldframe>', 'Add a JSON-LD frame')
.option('--frame <jsonldframe|file>', 'Add a JSON-LD frame')
.arguments('<url>')
.action(function (argUrl) {
//TODO: check whether starts with http(s)?
Expand Down Expand Up @@ -47,7 +49,15 @@ var processPage = async function (pageUrl) {
history.push(response.url);
if (response.triples) {
if (program.frame) {
let frame = JSON.parse(program.frame);
let frame;

if (fs.existsSync(program.frame)) {
frame = JSON.parse(fs.readFileSync(program.frame));
}
else {
frame = JSON.parse(program.frame);
}

let object = await fetch.frame(response.triples, frame);
console.log(JSON.stringify(object));
} else {
Expand Down
Loading

0 comments on commit d14d336

Please sign in to comment.