@@ -12,24 +12,41 @@ interface Config {
12
12
13
13
async function load ( globPath : string , configs : Config [ ] ) {
14
14
const filePaths : string [ ] = globSync ( globPath ) ;
15
- const filePathMap : any = { } ;
16
- filePaths . forEach ( filePath => filePathMap [ basename ( filePath , extname ( filePath ) ) ] = filePath . replace ( extname ( filePath ) , '' ) ) ;
15
+ const filePathMap : any = createFilePathMap ( filePaths ) ;
16
+ const inputData : InputData = await createJSONSchema ( filePaths ) ;
17
17
console . log ( `📁 ${ filePaths } ` ) ;
18
18
console . log ( filePathMap ) ;
19
+ for ( let i = 0 ; i < configs . length ; i ++ ) {
20
+ const { lang, ext, rendererOptions } = configs [ i ] ;
21
+ const packagePath : string = typeof rendererOptions . package === 'string' ? rendererOptions . package . replace ( '.' , '/' ) + '/' : '' ;
22
+ const results : MultiFileRenderResult = await quicktypeMultiFile ( { inputData, rendererOptions, lang } ) ;
23
+ results . forEach ( ( result : SerializedRenderResult , name : string ) => {
24
+ const fileKey : string = name . replace ( extname ( name ) , '' ) ;
25
+ const filePath : string = filePathMap [ fileKey ] || fileKey ;
26
+ createFile ( `./dist/${ lang } /${ packagePath } ${ filePath } .${ ext } ` , result . lines . join ( '\n' ) ) ;
27
+ } ) ;
28
+ }
29
+ }
30
+
31
+ function createFilePathMap ( filePaths : string [ ] ) {
32
+ const filePathMap : any = { } ;
33
+ filePaths . forEach ( ( filePath ) => {
34
+ const fileExt : string = extname ( filePath ) ;
35
+ const fileKey : string = basename ( filePath , fileExt ) ;
36
+ filePathMap [ fileKey ] = filePath . replace ( 'src/' , '' ) . replace ( fileExt , '' ) ;
37
+ } ) ;
38
+ return filePathMap ;
39
+ }
40
+
41
+ async function createJSONSchema ( filePaths : string [ ] ) {
19
42
const jsonSchema : JSONSchemaSourceData = schemaForTypeScriptSources ( filePaths ) ;
20
43
// @ts -ignore
21
44
const jsonStore : JSONSchemaStore = new JSONSchemaStore ( ) ;
22
45
const jsonInput : JSONSchemaInput = new JSONSchemaInput ( jsonStore ) ;
23
46
await jsonInput . addSource ( { name : '#/definitions/' , schema : jsonSchema . schema } ) ;
24
47
const inputData : InputData = new InputData ( ) ;
25
48
inputData . addInput ( jsonInput ) ;
26
- for ( let i = 0 ; i < configs . length ; i ++ ) {
27
- const { lang, ext, rendererOptions } = configs [ i ] ;
28
- const results : MultiFileRenderResult = await quicktypeMultiFile ( { inputData, rendererOptions, lang } ) ;
29
- results . forEach ( ( result : SerializedRenderResult , name : string ) => {
30
- if ( name . endsWith ( ext ) ) createFile ( `./dist/${ lang } /${ filePathMap [ name . replace ( extname ( name ) , '' ) ] } .${ ext } ` , result . lines . join ( '\n' ) ) ;
31
- } ) ;
32
- }
49
+ return inputData ;
33
50
}
34
51
35
52
function createFile ( filePath : string , fileContents : string ) {
@@ -39,7 +56,7 @@ function createFile(filePath: string, fileContents: string) {
39
56
}
40
57
41
58
load ( './src/**/*.ts' , [
42
- { lang : 'java' , ext : 'java' , rendererOptions : { "just-types" : true } } ,
59
+ { lang : 'java' , ext : 'java' , rendererOptions : { "just-types" : true , package : 'com.example' } } ,
43
60
{ lang : 'schema' , ext : 'json' , rendererOptions : { "just-types" : true } } ,
44
61
{ lang : 'ts' , ext : 'ts' , rendererOptions : { "just-types" : true } }
45
62
] ) ;
0 commit comments