33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- const fs = require ( 'fs' ) . promises ;
7- const Bundler = require ( " @hyperjump/json-schema-bundle" ) ;
6+ import { writeFile } from 'node:fs/ promises' ;
7+ import Bundler from ' @hyperjump/json-schema-bundle' ;
88
99( async function ( ) {
10- bundle ( ` https://json-schema.org/draft/2019-09/schema` , 'draft-2019-09' , 'https://json-schema.org/draft/2019-09' ) ;
11- bundle ( ` https://json-schema.org/draft/2020-12/schema` , 'draft-2020-12' , 'https://json-schema.org/draft/2020-12' ) ;
10+ bundle ( ' https://json-schema.org/draft/2019-09/schema' , 'draft-2019-09' , 'https://json-schema.org/draft/2019-09' ) ;
11+ bundle ( ' https://json-schema.org/draft/2020-12/schema' , 'draft-2020-12' , 'https://json-schema.org/draft/2020-12' ) ;
1212} ( ) ) ;
1313
1414async function bundle ( uri , filename , derivedURL ) {
1515 const metaSchema = await Bundler . get ( uri ) ;
1616 let bundle = await Bundler . bundle ( metaSchema ) ;
1717 bundle = JSON . parse ( JSON . stringify ( bundle , null , 2 ) . replace ( / " u n d e f i n e d " : " " / g, '"$dynamicAnchor": "meta"' ) ) ;
18- fs . writeFile ( `./${ filename } .json` , JSON . stringify ( bundle , null , 2 ) , 'utf8' ) ;
18+ await writeFile ( `./${ filename } .json` , JSON . stringify ( bundle , null , 2 ) , 'utf8' ) ;
1919 bundle = flattenDraftMetaSchema ( bundle ) ;
2020 const jsified = getCopyright ( derivedURL ) + 'export default ' + printObject ( bundle ) ;
21- fs . writeFile ( `./${ filename } -flat.json` , JSON . stringify ( bundle , null , 2 ) , 'utf8' ) ;
22- fs . writeFile ( `./src/services/schemas/${ filename } -flat.ts` , jsified , 'utf8' ) ;
21+ await writeFile ( `./${ filename } -flat.json` , JSON . stringify ( bundle , null , 2 ) , 'utf8' ) ;
22+ await writeFile ( `./src/services/schemas/${ filename } -flat.ts` , jsified , 'utf8' ) ;
2323}
2424function getCopyright ( derivedURL ) {
2525 return [
@@ -55,7 +55,7 @@ function indent(level) {
5555function printObject ( obj , indentLevel = 0 ) {
5656 const result = [ ] ;
5757 if ( Array . isArray ( obj ) ) {
58- result . push ( `[` ) ;
58+ result . push ( '[' ) ;
5959 for ( const item of obj ) {
6060 if ( typeof item === 'object' && item !== null ) {
6161 result . push ( `${ indent ( indentLevel + 1 ) } ${ printObject ( item , indentLevel + 1 ) } ,` ) ;
@@ -67,11 +67,11 @@ function printObject(obj, indentLevel = 0) {
6767 return result . join ( '\n' ) ;
6868 }
6969 if ( obj === null ) {
70- result . push ( ` null` ) ;
70+ result . push ( ' null' ) ;
7171 return result . join ( '\n' ) ;
7272 }
7373
74- result . push ( `{` ) ;
74+ result . push ( '{' ) ;
7575 for ( const [ key , value ] of Object . entries ( obj ) ) {
7676 if ( typeof value === 'object' && value !== null ) {
7777 result . push ( `${ indent ( indentLevel + 1 ) } ${ printKey ( key ) } : ${ printObject ( value , indentLevel + 1 ) } ,` ) ;
@@ -106,9 +106,9 @@ function replaceDynamicRefs(node, anchorName = DEFAULT_ANCHOR) {
106106 visit ( node , ( n , k ) => {
107107 const v = n [ k ] ;
108108 if ( k === '$dynamicRef' && v === '#' + anchorName ) {
109- n [ ' $ref' ] = '#' ;
110- delete n [ ' $dynamicRef' ] ;
111- } ;
109+ n . $ref = '#' ;
110+ delete n . $dynamicRef ;
111+ }
112112 } ) ;
113113}
114114
@@ -117,9 +117,9 @@ function replaceRecursiveRefs(node, anchorName = DEFAULT_ANCHOR) {
117117 visit ( node , ( n , k ) => {
118118 const v = n [ k ] ;
119119 if ( k === '$recursiveRef' ) {
120- n [ ' $ref' ] = v ;
121- delete n [ ' $recursiveRef' ] ;
122- } ;
120+ n . $ref = v ;
121+ delete n . $recursiveRef ;
122+ }
123123 } ) ;
124124}
125125
@@ -130,7 +130,7 @@ function replaceOldRefs(node, anchorName = DEFAULT_ANCHOR) {
130130 if ( k === '$ref' && typeof v === 'string' && v . startsWith ( anchorName + '/' ) ) {
131131 const segments = v . split ( '#' ) ;
132132 if ( segments . length === 2 ) {
133- n [ ' $ref' ] = `#${ segments [ 1 ] } ` ;
133+ n . $ref = `#${ segments [ 1 ] } ` ;
134134 }
135135 }
136136 } ) ;
@@ -149,7 +149,7 @@ function stripDynamicAnchors(node) {
149149function collectVocabularies ( schema ) {
150150 const vocabularies = [ ] ;
151151 const defs = schema . $defs || { } ;
152- for ( const [ key , value ] of Object . entries ( defs ) ) {
152+ for ( const [ , value ] of Object . entries ( defs ) ) {
153153 if ( value && typeof value === 'object' && ! Array . isArray ( value ) && value . $id && value . $dynamicAnchor === DEFAULT_ANCHOR && value . properties ) {
154154 vocabularies . push ( value ) ;
155155 }
@@ -251,4 +251,4 @@ function flattenDraftMetaSchema(original) {
251251 }
252252
253253 return schema ;
254- }
254+ }
0 commit comments