Skip to content

Commit 2e72060

Browse files
committed
refactor: Adjust schema build script to allow local AND npm-versioned build
1 parent eec6dd2 commit 2e72060

File tree

5 files changed

+92
-44
lines changed

5 files changed

+92
-44
lines changed

.github/workflows/deploy-vitepress-docs.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ jobs:
6161
run: npm run jsdoc-generate
6262
- name: Build Schema
6363
working-directory: internal/documentation
64-
run: |
65-
npm run schema-generate
66-
npm run schema-workspace-generate
64+
run: npm run schema-generate
6765
- name: Checkout gh-pages
6866
uses: actions/checkout@v5
6967
with:

internal/documentation/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"jsdoc-generate": "jsdoc -c jsdoc/jsdoc.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
3434
"jsdoc-generate-workspace": "jsdoc -c jsdoc/jsdoc-workspace.json -t $(node -p 'path.dirname(require.resolve(\"docdash\"))') ./ || (echo 'Error during JSDoc generation! Check log.' && exit 1)",
3535
"generate-cli-doc": "node ./scripts/generateCliDoc.js",
36-
"schema-generate": "node ./scripts/buildSchema.js ui5",
37-
"schema-workspace-generate": "node ./scripts/buildSchema.js ui5-workspace"
36+
"schema-generate": "node ./scripts/buildSchema.js",
37+
"schema-generate-workspace": "node ./scripts/buildSchema-workspace.js"
3838
},
3939
"dependencies": {
4040
"@types/node": "^22.5.1",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import path from "node:path";
2+
import {fileURLToPath} from "node:url";
3+
import {writeFile, mkdir} from "node:fs/promises";
4+
import {$RefParser} from "@apidevtools/json-schema-ref-parser";
5+
import traverse from "traverse";
6+
7+
try {
8+
// Use ui5.yaml.json and ui5-workspace.yaml.json
9+
const schemaNames = ["ui5", "ui5-workspace"];
10+
11+
schemaNames.forEach(async (schemaName) => {
12+
// Using the local version of @ui5/project to use the current development version for local testing
13+
const SOURCE_SCHEMA_PATH = fileURLToPath(
14+
new URL(`./lib/validation/schema/${schemaName}.json`, import.meta.resolve("@ui5/project/package.json"))
15+
);
16+
const TARGET_SCHEMA_PATH = fileURLToPath(
17+
new URL(`../schema/${schemaName}.yaml.json`, import.meta.url)
18+
);
19+
20+
const parser = new $RefParser();
21+
const schema = await parser.bundle(SOURCE_SCHEMA_PATH);
22+
23+
// Remove $id from all nodes and $schema / $comment from all except the root node.
24+
// Defining $id on the root is not required and as the URL will be a different one it might even cause issues.
25+
// $schema only needs to be defined once per file.
26+
traverse(schema).forEach(function(v) {
27+
// eslint-disable-next-line no-invalid-this
28+
const traverseContext = this;
29+
if (v && typeof v === "object" && !Array.isArray(v)) {
30+
if (v.$id) {
31+
delete v.$id;
32+
}
33+
if (!traverseContext.isRoot) {
34+
if (v.$schema) {
35+
delete v.$schema;
36+
}
37+
if (v.$comment) {
38+
delete v.$comment;
39+
}
40+
}
41+
traverseContext.update(v);
42+
}
43+
});
44+
45+
await mkdir(path.dirname(TARGET_SCHEMA_PATH), {recursive: true});
46+
await writeFile(TARGET_SCHEMA_PATH, JSON.stringify(schema, null, 2));
47+
48+
console.log(`Wrote bundled ${schemaName}.yaml schema file to ${TARGET_SCHEMA_PATH}`);
49+
});
50+
} catch (error) {
51+
console.log(error);
52+
process.exit(1);
53+
}
54+

internal/documentation/scripts/buildSchema.js

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,49 @@ import {writeFile, mkdir} from "node:fs/promises";
44
import {$RefParser} from "@apidevtools/json-schema-ref-parser";
55
import traverse from "traverse";
66

7-
// Provide schema name as CLI argument
8-
const schemaName = process.argv[2] || "ui5";
7+
try {
8+
// Use ui5.yaml.json and ui5-workspace.yaml.json
9+
const schemaNames = ["ui5", "ui5-workspace"];
910

10-
// Using @ui5/project/package.json export to calculate the path to the root ui5-project folder
11-
const SOURCE_SCHEMA_PATH = fileURLToPath(
12-
new URL(`./lib/validation/schema/${schemaName}.json`, import.meta.resolve("@ui5/project/package.json"))
13-
);
14-
const TARGET_SCHEMA_PATH = fileURLToPath(
15-
new URL(`../schema/${schemaName}.yaml.json`, import.meta.url)
16-
);
11+
schemaNames.forEach(async (schemaName) => {
12+
// Using the npm version of @ui5/project to use the latest published version for Github Pages
13+
const SOURCE_SCHEMA_PATH = fileURLToPath(
14+
new URL(`./lib/validation/schema/${schemaName}.json`, import.meta.resolve("@ui5/project-npm/package.json"))
15+
);
16+
const TARGET_SCHEMA_PATH = fileURLToPath(
17+
new URL(`../schema/${schemaName}.yaml.json`, import.meta.url)
18+
);
1719

18-
try {
19-
const parser = new $RefParser();
20-
const schema = await parser.bundle(SOURCE_SCHEMA_PATH);
20+
const parser = new $RefParser();
21+
const schema = await parser.bundle(SOURCE_SCHEMA_PATH);
2122

22-
// Remove $id from all nodes and $schema / $comment from all except the root node.
23-
// Defining $id on the root is not required and as the URL will be a different one it might even cause issues.
24-
// $schema only needs to be defined once per file.
25-
traverse(schema).forEach(function(v) {
26-
// eslint-disable-next-line no-invalid-this
27-
const traverseContext = this;
28-
if (v && typeof v === "object" && !Array.isArray(v)) {
29-
if (v.$id) {
30-
delete v.$id;
31-
}
32-
if (!traverseContext.isRoot) {
33-
if (v.$schema) {
34-
delete v.$schema;
23+
// Remove $id from all nodes and $schema / $comment from all except the root node.
24+
// Defining $id on the root is not required and as the URL will be a different one it might even cause issues.
25+
// $schema only needs to be defined once per file.
26+
traverse(schema).forEach(function(v) {
27+
// eslint-disable-next-line no-invalid-this
28+
const traverseContext = this;
29+
if (v && typeof v === "object" && !Array.isArray(v)) {
30+
if (v.$id) {
31+
delete v.$id;
3532
}
36-
if (v.$comment) {
37-
delete v.$comment;
33+
if (!traverseContext.isRoot) {
34+
if (v.$schema) {
35+
delete v.$schema;
36+
}
37+
if (v.$comment) {
38+
delete v.$comment;
39+
}
3840
}
41+
traverseContext.update(v);
3942
}
40-
traverseContext.update(v);
41-
}
42-
});
43+
});
4344

44-
await mkdir(path.dirname(TARGET_SCHEMA_PATH), {recursive: true});
45-
await writeFile(TARGET_SCHEMA_PATH, JSON.stringify(schema, null, 2));
45+
await mkdir(path.dirname(TARGET_SCHEMA_PATH), {recursive: true});
46+
await writeFile(TARGET_SCHEMA_PATH, JSON.stringify(schema, null, 2));
4647

47-
console.log(`Wrote bundled ${schemaName}.yaml schema file to ${TARGET_SCHEMA_PATH}`);
48+
console.log(`Wrote bundled ${schemaName}.yaml schema file to ${TARGET_SCHEMA_PATH}`);
49+
});
4850
} catch (error) {
4951
console.log(error);
5052
process.exit(1);

package-lock.json

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

0 commit comments

Comments
 (0)