1
+ import path from 'path' ;
2
+
1
3
import { buildJSClientUtils } from './buildClients' ;
2
4
import { buildSpecs } from './buildSpecs' ;
3
5
import {
@@ -7,40 +9,58 @@ import {
7
9
runIfExists ,
8
10
toAbsolutePath ,
9
11
} from './common' ;
10
- import { getCustomGenerator , getLanguageFolder } from './config' ;
12
+ import {
13
+ getCustomGenerator ,
14
+ getLanguageFolder ,
15
+ getLanguageModelFolder ,
16
+ } from './config' ;
11
17
import { formatter } from './formatter' ;
12
18
import { createSpinner } from './oraLog' ;
13
19
import { setHostsOptions } from './pre-gen/setHostsOptions' ;
14
20
import type { Generator } from './types' ;
15
21
16
- async function preGen (
17
- { language, client, key, output } : Generator ,
22
+ /**
23
+ * Remove `model` folder for the current language and client.
24
+ */
25
+ async function removeExistingModel (
26
+ { language, client, output } : Generator ,
18
27
verbose ?: boolean
19
28
) : Promise < void > {
20
- await runIfExists ( `./scripts/pre-gen/${ language } .sh` , `${ output } ${ key } ` , {
21
- verbose,
22
- } ) ;
29
+ const baseModelFolder = getLanguageModelFolder ( language ) ;
23
30
24
- // We clean models to avoid outdated files.
25
- let modelPath = '' ;
31
+ let clientModel = '' ;
26
32
switch ( language ) {
27
- case 'javascript' :
28
- modelPath = 'model' ;
29
- break ;
30
33
case 'java' :
31
- modelPath = `algoliasearch-core/com/algolia/model /${ client } ` ;
34
+ clientModel = `/${ client } ` ;
32
35
break ;
33
36
default :
34
- return ;
37
+ break ;
35
38
}
36
39
37
- if ( modelPath ) {
38
- await run ( `rm -rf ${ toAbsolutePath ( `${ output } /${ modelPath } ` ) } ` , {
40
+ await run (
41
+ `rm -rf ${ toAbsolutePath (
42
+ path . resolve ( output , `/${ baseModelFolder } ` , clientModel )
43
+ ) } `,
44
+ {
39
45
verbose,
40
- } ) ;
41
- }
46
+ }
47
+ ) ;
48
+ }
49
+
50
+ async function preGen ( gen : Generator , verbose ?: boolean ) : Promise < void > {
51
+ // Run bash pre-gen script
52
+ await runIfExists (
53
+ `./scripts/pre-gen/${ gen . language } .sh` ,
54
+ `${ gen . output } ${ gen . key } ` ,
55
+ {
56
+ verbose,
57
+ }
58
+ ) ;
59
+
60
+ await removeExistingModel ( gen ) ;
42
61
43
- await setHostsOptions ( { client, key } ) ;
62
+ // Updates `openapitools.json` file based on the spec `servers`
63
+ await setHostsOptions ( { client : gen . client , key : gen . key } ) ;
44
64
}
45
65
46
66
async function generateClient (
0 commit comments