Skip to content

Commit ecf8343

Browse files
mikeharderjohnkoh-msft
authored andcommitted
[shared] Add SpecModel (Azure#33362)
- Fixes Azure#33227
1 parent 991346f commit ecf8343

File tree

70 files changed

+9541
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+9541
-938
lines changed

.github/package-lock.json

Lines changed: 970 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/shared/cmd/spec-model.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
3+
import { ConsoleLogger } from "../src/logger.js";
4+
import { SpecModel } from "../src/spec-model.js";
5+
6+
const USAGE =
7+
"Usage: npx spec-model path/to/spec [--debug] [--include-refs] [--relative-paths]\n" +
8+
"Example: npx spec-model ../../specfication/contosowidgetmanager";
9+
10+
// Exclude first two args (node, script file)
11+
let args = process.argv.slice(2);
12+
13+
const debug = args.includes("--debug");
14+
args = args.filter((a) => a != "--debug");
15+
16+
const includeRefs = args.includes("--include-refs");
17+
args = args.filter((a) => a != "--include-refs");
18+
19+
const relativePaths = args.includes("--relative-paths");
20+
args = args.filter((a) => a != "--relative-paths");
21+
22+
if (args.length < 1) {
23+
console.error(USAGE);
24+
process.exit(1);
25+
}
26+
27+
if (args.length > 1) {
28+
console.error("ERROR: Too many arguments\n");
29+
console.error(USAGE);
30+
process.exit(1);
31+
}
32+
33+
const specPath = args[0];
34+
35+
const specModel = new SpecModel(specPath, {
36+
logger: new ConsoleLogger(debug),
37+
});
38+
39+
console.log(
40+
JSON.stringify(
41+
await specModel.toJSONAsync({ includeRefs, relativePaths }),
42+
null,
43+
2,
44+
),
45+
);

0 commit comments

Comments
 (0)