@lde/docgen 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +33 -0
- package/dist/frame.d.ts +4 -0
- package/dist/frame.d.ts.map +1 -0
- package/dist/frame.js +7 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/parse.d.ts +3 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +14 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +38 -0
- package/frames/shacl.frame.jsonld +1 -1
- package/package.json +1 -1
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { generateDocumentation } from './index.js';
|
|
4
|
+
import packageJson from '../package.json' with { type: 'json' };
|
|
5
|
+
import { dirname } from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program
|
|
10
|
+
.name('docgen')
|
|
11
|
+
.description('Generate documentation from RDF data')
|
|
12
|
+
.version(packageJson.version);
|
|
13
|
+
program
|
|
14
|
+
.command('from-shacl')
|
|
15
|
+
.description('Generate documentation from a SHACL shapes file')
|
|
16
|
+
.argument('<shacl-file>', 'Path to SHACL shapes file (in any RDF serialization format)')
|
|
17
|
+
.argument('<template-file>', 'Path to Liquid template file')
|
|
18
|
+
.option('-f --frame <json-ld-frame-file>', 'Path to a JSON-LD Frame file', __dirname + '/../frames/shacl.frame.jsonld')
|
|
19
|
+
.addHelpText('after', `
|
|
20
|
+
Example:
|
|
21
|
+
$ npx @lde/docgen@latest from-shacl shacl.ttl template.liquid
|
|
22
|
+
`)
|
|
23
|
+
.action(async (rdfFile, templateFile, { frame }) => {
|
|
24
|
+
try {
|
|
25
|
+
const documentation = await generateDocumentation(rdfFile, templateFile, frame);
|
|
26
|
+
console.log(documentation);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(`Error: ${error instanceof Error ? error.message : error}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
program.parse();
|
package/dist/frame.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../src/frame.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,wBAAsB,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,8BAQ/D"}
|
package/dist/frame.js
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAKjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { parseRdfToJsonLd } from './parse.js';
|
|
2
|
+
import { frame } from './frame.js';
|
|
3
|
+
import { render } from './render.js';
|
|
4
|
+
export async function generateDocumentation(rdfPath, templatePath, framePath) {
|
|
5
|
+
const jsonld = await parseRdfToJsonLd(rdfPath);
|
|
6
|
+
const framed = await frame(jsonld, framePath);
|
|
7
|
+
return render(framed, templatePath);
|
|
8
|
+
}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAa7E"}
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { rdfDereferencer } from 'rdf-dereference';
|
|
2
|
+
import jsonld from 'jsonld';
|
|
3
|
+
export async function parseRdfToJsonLd(filePath) {
|
|
4
|
+
const { data } = await rdfDereferencer.dereference(filePath, {
|
|
5
|
+
localFiles: true,
|
|
6
|
+
});
|
|
7
|
+
const quads = [];
|
|
8
|
+
for await (const quad of data) {
|
|
9
|
+
quads.push(quad);
|
|
10
|
+
}
|
|
11
|
+
return jsonld.fromRDF(quads, {
|
|
12
|
+
useNativeTypes: true, // Convert xsd:integer to Number etc.
|
|
13
|
+
});
|
|
14
|
+
}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,wBAAsB,MAAM,CAC1B,MAAM,EAAE,UAAU,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CA+CjB"}
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Liquid } from 'liquidjs';
|
|
2
|
+
import { dirname } from 'path';
|
|
3
|
+
export async function render(shapes, templatePath) {
|
|
4
|
+
const templatesDir = dirname(templatePath);
|
|
5
|
+
const engine = new Liquid({
|
|
6
|
+
root: templatesDir,
|
|
7
|
+
extname: '.liquid',
|
|
8
|
+
});
|
|
9
|
+
engine.registerFilter('lang', (nodes, language) => {
|
|
10
|
+
if (nodes === undefined) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
const filtered = [nodes]
|
|
14
|
+
.flat()
|
|
15
|
+
.filter((node) => node['@language'] === language);
|
|
16
|
+
return filtered[0]?.['@value'] ?? '';
|
|
17
|
+
});
|
|
18
|
+
engine.registerFilter('mergePropertiesByPath', (properties) => {
|
|
19
|
+
const grouped = properties.reduce((acc, propertyShape) => {
|
|
20
|
+
const path = propertyShape.path;
|
|
21
|
+
acc[path] ??= [];
|
|
22
|
+
acc[path].push(propertyShape);
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
return Object.entries(grouped).map(([_path, propertyShapes]) => {
|
|
26
|
+
const result = {};
|
|
27
|
+
for (const propertyShape of propertyShapes) {
|
|
28
|
+
for (const key in propertyShape) {
|
|
29
|
+
if (result[key] === undefined && propertyShape[key] !== undefined) {
|
|
30
|
+
result[key] = propertyShape[key];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return engine.renderFile(templatePath, { nodeShapes: shapes['@graph'] });
|
|
38
|
+
}
|