1
+ import fsp from 'fs/promises' ;
1
2
import path from 'path' ;
2
3
3
- import { createClientName , run , toAbsolutePath } from '../common' ;
4
+ import { createClientName , toAbsolutePath } from '../common' ;
4
5
import { getLanguageApiFolder , getLanguageModelFolder } from '../config' ;
5
6
import type { Generator } from '../types' ;
6
7
7
8
/**
8
9
* Remove `model` folder for the current language and client.
9
10
*/
10
- export async function removeExistingCodegen (
11
- { language, client, output } : Generator ,
12
- verbose ?: boolean
13
- ) : Promise < void > {
11
+ export async function removeExistingCodegen ( {
12
+ language,
13
+ client,
14
+ output,
15
+ } : Generator ) : Promise < void > {
14
16
const baseModelFolder = getLanguageModelFolder ( language ) ;
15
17
const baseApiFolder = getLanguageApiFolder ( language ) ;
16
18
const clientName = createClientName ( client , language ) ;
@@ -23,13 +25,11 @@ export async function removeExistingCodegen(
23
25
if ( client === 'query-suggestions' ) {
24
26
// eslint-disable-next-line no-warning-comments
25
27
// TODO: temporary solution, remove in next PR
26
- await run (
27
- `rm -rf ${ toAbsolutePath (
28
+ await fsp . rm (
29
+ toAbsolutePath (
28
30
path . resolve ( '..' , output , baseModelFolder , 'querySuggestions' )
29
- ) } `,
30
- {
31
- verbose,
32
- }
31
+ ) ,
32
+ { force : true , recursive : true }
33
33
) ;
34
34
}
35
35
clientModel = client . replace ( '-' , '' ) ;
@@ -42,44 +42,31 @@ export async function removeExistingCodegen(
42
42
case 'javascript' :
43
43
// We want to also delete the nested `lite` client or folders that only exists in JS
44
44
if ( clientName === 'algoliasearch' ) {
45
- await run (
46
- `rm -rf ${ toAbsolutePath ( path . resolve ( '..' , output , 'lite' ) ) } ` ,
47
- {
48
- verbose,
49
- }
50
- ) ;
45
+ await fsp . rm ( toAbsolutePath ( path . resolve ( '..' , output , 'lite' ) ) , {
46
+ force : true ,
47
+ recursive : true ,
48
+ } ) ;
51
49
}
52
50
53
51
// Delete `builds` folder
54
- await run (
55
- `rm -rf ${ toAbsolutePath ( path . resolve ( '..' , output , 'builds' ) ) } ` ,
56
- {
57
- verbose,
58
- }
59
- ) ;
60
-
52
+ await fsp . rm ( toAbsolutePath ( path . resolve ( '..' , output , 'builds' ) ) , {
53
+ force : true ,
54
+ recursive : true ,
55
+ } ) ;
61
56
break ;
62
57
default :
63
58
break ;
64
59
}
65
60
66
61
// Delete client model folder/file
67
- await run (
68
- `rm -rf ${ toAbsolutePath (
69
- path . resolve ( '..' , output , baseModelFolder , clientModel )
70
- ) } `,
71
- {
72
- verbose,
73
- }
62
+ await fsp . rm (
63
+ toAbsolutePath ( path . resolve ( '..' , output , baseModelFolder , clientModel ) ) ,
64
+ { force : true , recursive : true }
74
65
) ;
75
66
76
67
// Delete client api folder/file
77
- await run (
78
- `rm -rf ${ toAbsolutePath (
79
- path . resolve ( '..' , output , baseApiFolder , clientApi )
80
- ) } `,
81
- {
82
- verbose,
83
- }
68
+ await fsp . rm (
69
+ toAbsolutePath ( path . resolve ( '..' , output , baseApiFolder , clientApi ) ) ,
70
+ { force : true , recursive : true }
84
71
) ;
85
72
}
0 commit comments