@@ -4,47 +4,49 @@ import {writeFile, mkdir} from "node:fs/promises";
44import { $RefParser } from "@apidevtools/json-schema-ref-parser" ;
55import 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 @ui 5/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 @ui 5/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 ) ;
0 commit comments