@shaclmate/cli 4.0.15 → 4.0.17

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.
Files changed (2) hide show
  1. package/dist/cli.js +37 -16
  2. package/package.json +5 -10
package/dist/cli.js CHANGED
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import * as fs from "node:fs";
3
3
  import PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
4
+ import { RdfDirectory, RdfFileSystemEntry } from "@rdfx/fs";
4
5
  import { AstJsonGenerator, Compiler, ShapesGraph, TsGenerator, ZodGenerator, } from "@shaclmate/compiler";
5
6
  import { command, option, restPositionals, run, string, subcommands, } from "cmd-ts";
6
7
  import { ExistingPath } from "cmd-ts/dist/cjs/batteries/fs.js";
7
8
  import { DataFactory, Parser, Store, Writer } from "n3";
8
9
  import { pino } from "pino";
10
+ import { EitherAsync } from "purify-ts";
9
11
  import SHACLValidator from "rdf-validate-shacl";
10
12
  import { shaclShaclDataset } from "./shaclShaclDataset.js";
11
- const inputFilePaths = restPositionals({
12
- displayName: "inputFilePaths",
13
- description: "paths to RDF files containing SHACL shapes",
13
+ const inputPaths = restPositionals({
14
+ displayName: "inputPaths",
15
+ description: "paths to RDF files or directories of RDF files containing SHACL shapes",
14
16
  type: ExistingPath,
15
17
  });
16
18
  const logger = pino({
@@ -26,15 +28,15 @@ const outputFilePath = option({
26
28
  short: "o",
27
29
  type: string,
28
30
  });
29
- function generate({ generator, inputFilePaths, outputFilePath, }) {
30
- if (inputFilePaths.length === 0) {
31
+ function generate({ generator, inputFiles, outputFilePath, }) {
32
+ if (inputFiles.length === 0) {
31
33
  throw new Error("must specify at least one input shapes graph file path");
32
34
  }
33
35
  const inputParser = new Parser();
34
36
  const dataset = new Store();
35
37
  const iriPrefixes = [];
36
- for (const inputFilePath of inputFilePaths) {
37
- dataset.addQuads(inputParser.parse(fs.readFileSync(inputFilePath).toString(), null, (prefix, prefixNode) => {
38
+ for (const inputFile of inputFiles) {
39
+ dataset.addQuads(inputParser.parse(fs.readFileSync(inputFile.path).toString(), null, (prefix, prefixNode) => {
38
40
  const existingIriPrefix = iriPrefixes.find((iriPrefix) => iriPrefix[0] === prefix || iriPrefix[1].equals(prefixNode));
39
41
  if (existingIriPrefix) {
40
42
  if (existingIriPrefix[0] !== prefix ||
@@ -82,6 +84,25 @@ function generate({ generator, inputFilePaths, outputFilePath, }) {
82
84
  }
83
85
  });
84
86
  }
87
+ async function resolveInputPaths(inputPaths) {
88
+ return EitherAsync(async ({ liftEither }) => {
89
+ const inputFiles = [];
90
+ for (const inputPath of inputPaths) {
91
+ const fileSystemEntry = await liftEither(await RdfFileSystemEntry.fromPath(inputPath));
92
+ if (fileSystemEntry instanceof RdfDirectory) {
93
+ for await (const inputFile of fileSystemEntry.files({
94
+ recursive: true,
95
+ })) {
96
+ inputFiles.push(inputFile);
97
+ }
98
+ }
99
+ else {
100
+ inputFiles.push(fileSystemEntry);
101
+ }
102
+ }
103
+ return inputFiles;
104
+ });
105
+ }
85
106
  run(subcommands({
86
107
  cmds: {
87
108
  generate: subcommands({
@@ -90,13 +111,13 @@ run(subcommands({
90
111
  name: "ast-json",
91
112
  description: "generate AST JSON for the SHACL shapes graph",
92
113
  args: {
93
- inputFilePaths,
114
+ inputPaths,
94
115
  outputFilePath,
95
116
  },
96
- handler: async ({ inputFilePaths, outputFilePath }) => {
117
+ handler: async ({ inputPaths, outputFilePath }) => {
97
118
  generate({
98
119
  generator: new AstJsonGenerator(),
99
- inputFilePaths,
120
+ inputFiles: (await resolveInputPaths(inputPaths)).unsafeCoerce(),
100
121
  outputFilePath,
101
122
  });
102
123
  },
@@ -105,13 +126,13 @@ run(subcommands({
105
126
  name: "ts",
106
127
  description: "generate TypeScript for the SHACL shapes graph",
107
128
  args: {
108
- inputFilePaths,
129
+ inputPaths,
109
130
  outputFilePath,
110
131
  },
111
- handler: async ({ inputFilePaths, outputFilePath }) => {
132
+ handler: async ({ inputPaths, outputFilePath }) => {
112
133
  generate({
113
134
  generator: new TsGenerator(),
114
- inputFilePaths,
135
+ inputFiles: (await resolveInputPaths(inputPaths)).unsafeCoerce(),
115
136
  outputFilePath,
116
137
  });
117
138
  },
@@ -120,13 +141,13 @@ run(subcommands({
120
141
  name: "zod",
121
142
  description: "generate Zod schemas for the SHACL shapes graph",
122
143
  args: {
123
- inputFilePaths,
144
+ inputPaths,
124
145
  outputFilePath,
125
146
  },
126
- handler: async ({ inputFilePaths, outputFilePath }) => {
147
+ handler: async ({ inputPaths, outputFilePath }) => {
127
148
  generate({
128
149
  generator: new ZodGenerator(),
129
- inputFilePaths,
150
+ inputFiles: (await resolveInputPaths(inputPaths)).unsafeCoerce(),
130
151
  outputFilePath,
131
152
  });
132
153
  },
package/package.json CHANGED
@@ -3,25 +3,20 @@
3
3
  "shaclmate": "dist/cli.js"
4
4
  },
5
5
  "dependencies": {
6
- "@shaclmate/compiler": "4.0.15",
6
+ "@shaclmate/compiler": "4.0.17",
7
7
  "@rdfjs/prefix-map": "~0.1.2",
8
8
  "@rdfjs/types": "~2.0.1",
9
+ "@rdfx/fs": "0.0.7",
9
10
  "@types/n3": "~1.26.0",
10
11
  "@types/rdfjs__prefix-map": "~0.1.5",
11
12
  "cmd-ts": "~0.13.0",
12
13
  "n3": "~1.26.0",
13
14
  "pino": "~9.1.0",
15
+ "purify-ts": "~2.1.4",
14
16
  "rdf-validate-shacl": "0.5.8"
15
17
  },
16
18
  "description": "Command line program to generate TypeScript code from SHACL shapes",
17
- "devDependencies": {
18
- "@tsconfig/node18": "~18.2.4",
19
- "@tsconfig/strictest": "~2.0.8",
20
- "@types/node": "~18",
21
- "depcheck": "~1.4.7",
22
- "rimraf": "~6.0.1",
23
- "typescript": "5.9.3"
24
- },
19
+ "devDependencies": {},
25
20
  "files": [
26
21
  "README.md",
27
22
  "dist/*.d.ts",
@@ -51,5 +46,5 @@
51
46
  },
52
47
  "type": "module",
53
48
  "types": "./dist/index.d.ts",
54
- "version": "4.0.15"
49
+ "version": "4.0.17"
55
50
  }