Comparing version 0.0.9 to 0.1.0
@@ -10,2 +10,3 @@ #!/usr/bin/env node | ||
const namespace = require('@rdfjs/namespace') | ||
const bufferDebug = require('../lib/bufferDebug') | ||
const runner = require('../lib/runner') | ||
@@ -69,28 +70,34 @@ | ||
.option('-v, --verbose', 'enable diagnostic console output') | ||
.action((filename, options = {}) => { | ||
let { format, output, pipeline, verbose } = options | ||
.option('--enable-buffer-monitor', 'enable histogram of buffer usage') | ||
.action(async (filename, options = {}) => { | ||
try { | ||
let { format, output, pipeline, verbose, enableBufferMonitor } = options | ||
runner.log.enabled = verbose | ||
runner.log.enabled = verbose | ||
p.fileToDataset(format, filename) | ||
.then(dataset => { | ||
if (!pipeline) { | ||
pipeline = guessPipeline(dataset) | ||
} | ||
const dataset = await p.fileToDataset(format, filename) | ||
const run = runner.create({ | ||
...options, | ||
pipeline, | ||
outputStream: createOutputStream(output), | ||
basePath: path.resolve(path.dirname(filename)) | ||
}) | ||
if (!pipeline) { | ||
pipeline = guessPipeline(dataset) | ||
} | ||
return run(dataset) | ||
const run = runner.create({ | ||
...options, | ||
dataset, | ||
term: pipeline, | ||
outputStream: createOutputStream(output), | ||
basePath: path.resolve(path.dirname(filename)) | ||
}) | ||
.catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) | ||
if (enableBufferMonitor) { | ||
bufferDebug(run.pipeline) | ||
} | ||
await run.promise | ||
} catch (err) { | ||
console.error(err) | ||
process.exit(1) | ||
} | ||
}) | ||
program.parse(process.argv) |
@@ -9,31 +9,34 @@ const { promisify } = require('util') | ||
function create ({ basePath, outputStream, pipeline, variable } = {}) { | ||
function create ({ dataset, term, basePath, outputStream, variable } = {}) { | ||
variable = variable || new Map() | ||
return function runner (dataset) { | ||
log('variables via CLI:') | ||
log('variables via CLI:') | ||
for (const [key, value] of variable) { | ||
log(` ${key}: ${value}`) | ||
} | ||
for (const [key, value] of variable) { | ||
log(` ${key}: ${value}`) | ||
} | ||
const stream = p.pipeline(dataset, pipeline, { | ||
basePath, | ||
variables: variable | ||
}) | ||
const pipeline = p.pipeline(dataset, term, { | ||
basePath, | ||
variables: variable | ||
}) | ||
log('variables in pipeline instance:') | ||
log('variables in pipeline instance:') | ||
for (const [key, value] of stream.variables) { | ||
log(` ${key}: ${value}`) | ||
} | ||
for (const [key, value] of pipeline.variables) { | ||
log(` ${key}: ${value}`) | ||
} | ||
stream.pipe(outputStream) | ||
pipeline.pipe(outputStream) | ||
const logger = stream.context.log.pipe(new TextLogStream()).on('data', log) | ||
const logger = pipeline.context.log.pipe(new TextLogStream()).on('data', log) | ||
return Promise.all([ | ||
promisify(finished)(logger), | ||
p.run(stream) | ||
]) | ||
const promise = Promise.all([ | ||
promisify(finished)(logger), | ||
p.run(pipeline) | ||
]) | ||
return { | ||
pipeline, | ||
promise | ||
} | ||
@@ -40,0 +43,0 @@ } |
{ | ||
"name": "barnard59", | ||
"version": "0.0.9", | ||
"version": "0.1.0", | ||
"description": "Barnard59 Linked Data pipelines", | ||
@@ -27,2 +27,3 @@ "main": "index.js", | ||
"debug": "^4.1.1", | ||
"lodash": "^4.17.15", | ||
"rdf-ext": "^1.1.2", | ||
@@ -29,0 +30,0 @@ "readable-stream": "^3.1.1" |
@@ -15,3 +15,4 @@ /* global describe, it */ | ||
const run = create({ | ||
pipeline: rdf.namedNode('http://example.org/pipeline'), | ||
dataset, | ||
term: rdf.namedNode('http://example.org/pipeline'), | ||
outputStream: process.stdout, | ||
@@ -22,3 +23,3 @@ basePath: dirname(pipelineFile) | ||
try { | ||
await run(dataset) | ||
await run.promise | ||
} catch (err) { | ||
@@ -25,0 +26,0 @@ strictEqual(err.message, 'error in pipeline step http://example.org/error') |
33039
23
393
9
+ Addedlodash@^4.17.15