@@ -8,16 +8,20 @@ function run(url) {
8
8
fetch ( apiUrl )
9
9
. then ( res => res . json ( ) )
10
10
. then ( json => {
11
- const path = _parseUrl ( apiUrl )
12
- const res = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
13
- const content = _buildContent ( res . go , path . pkg )
14
- fs . mkdirSync ( path . dir , { recursive : true } )
15
- fs . writeFile ( path . filePath , content , ( err ) => {
16
- if ( err ) throw err ;
17
- console . log ( json )
18
- console . log ( )
19
- console . log ( `generated: ${ path . filePath } ` )
20
- } ) ;
11
+ const path = _parseUrl ( apiUrl )
12
+ const res = jsonToGo ( JSON . stringify ( json ) , path . struct ) ;
13
+ const content = _buildContent ( res . go , path . pkg )
14
+ fs . mkdirSync ( path . dir , { recursive : true } )
15
+ console . log ( json )
16
+ console . log ( )
17
+ fs . writeFile ( path . jsonFilePath , JSON . stringify ( json , null , "\t" ) , ( err ) => {
18
+ if ( err ) throw err ;
19
+ console . log ( `saved: ${ path . jsonFilePath } ` )
20
+ } ) ;
21
+ fs . writeFile ( path . goFilePath , content , ( err ) => {
22
+ if ( err ) throw err ;
23
+ console . log ( `generated: ${ path . goFilePath } ` )
24
+ } ) ;
21
25
}
22
26
) ;
23
27
}
@@ -28,16 +32,15 @@ function _parseUrl(apiUrl) {
28
32
const pathArr = path . split ( "/" )
29
33
const pkg = pathArr [ pathArr . length - 2 ] . replace ( / \. / g, '' )
30
34
const last = pathArr [ pathArr . length - 1 ] || "index"
31
- const file = last + ".go"
32
35
const struct = _capitalize ( last )
33
36
pathArr . pop ( )
34
37
const dir = pathArr . join ( "/" )
35
38
return {
36
39
struct,
37
- file,
38
40
pkg,
39
41
dir,
40
- filePath : `${ dir } /${ file } `
42
+ jsonFilePath : `${ dir } /${ last } _sample.json` ,
43
+ goFilePath : `${ dir } /${ last } .go`
41
44
}
42
45
}
43
46
0 commit comments