@@ -13,51 +13,55 @@ export const clone = async (
13
13
storeId : string ,
14
14
skipData : boolean = false
15
15
) : Promise < void > => {
16
- console . log ( `Cloning store: ${ storeId } ` ) ;
16
+ try {
17
+ console . log ( `Cloning store: ${ storeId } ` ) ;
17
18
18
- const storeDir = path . join ( DIG_FOLDER_PATH , "stores" , storeId ) ;
19
+ const storeDir = path . join ( DIG_FOLDER_PATH , "stores" , storeId ) ;
19
20
20
- // Check if the store directory already exists
21
- if ( fs . existsSync ( storeDir ) ) {
22
- console . error ( `Store with ID ${ storeId } already exists at ${ storeDir } .` ) ;
23
- process . exit ( 1 ) ; // Exit the process with an error code
24
- }
21
+ // Check if the store directory already exists
22
+ if ( fs . existsSync ( storeDir ) ) {
23
+ console . error ( `Store with ID ${ storeId } already exists at ${ storeDir } .` ) ;
24
+ process . exit ( 1 ) ; // Exit the process with an error code
25
+ }
25
26
26
- try {
27
- // Create an instance of DigNetwork
28
- const digNetwork = new DigNetwork ( storeId ) ;
29
-
30
- // Pull files from the network using DigNetwork
31
- await digNetwork . downloadFiles ( true , true , skipData ) ;
32
- } catch ( error : any ) {
33
- console . error ( error . message ) ;
34
- process . exit ( 1 ) ; // Exit the process with an error code
35
- }
27
+ try {
28
+ // Create an instance of DigNetwork
29
+ const digNetwork = new DigNetwork ( storeId ) ;
30
+
31
+ // Pull files from the network using DigNetwork
32
+ await digNetwork . downloadFiles ( true , true , skipData ) ;
33
+ } catch ( error : any ) {
34
+ console . error ( error . message ) ;
35
+ process . exit ( 1 ) ; // Exit the process with an error code
36
+ }
36
37
37
- const dataStore = DataStore . from ( storeId ) ;
38
+ const dataStore = DataStore . from ( storeId ) ;
38
39
39
- if ( skipData ) {
40
- console . log ( "Skipping store integrity check due to --skip-data flag." ) ;
41
- return ;
42
- }
43
-
44
- try {
45
- // Perform the store integrity check after pulling files
46
- const storeIntegrityCheck = await waitForPromise (
47
- ( ) => dataStore . validate ( ) ,
48
- "Checking store integrity..." ,
49
- "Store integrity check passed." ,
50
- "Store integrity check failed."
51
- ) ;
52
-
53
- // Handle integrity check failure
54
- if ( ! storeIntegrityCheck ) {
40
+ if ( skipData ) {
41
+ console . log ( "Skipping store integrity check due to --skip-data flag." ) ;
42
+ return ;
43
+ }
44
+
45
+ try {
46
+ // Perform the store integrity check after pulling files
47
+ const storeIntegrityCheck = await waitForPromise (
48
+ ( ) => dataStore . validate ( ) ,
49
+ "Checking store integrity..." ,
50
+ "Store integrity check passed." ,
51
+ "Store integrity check failed."
52
+ ) ;
53
+
54
+ // Handle integrity check failure
55
+ if ( ! storeIntegrityCheck ) {
56
+ console . error ( "Store integrity check failed. Reverting Clone" ) ;
57
+ fs . rmdirSync ( path . resolve ( STORE_PATH , storeId ) , { recursive : true } ) ;
58
+ }
59
+ } catch ( error : any ) {
60
+ console . trace ( error . message ) ;
55
61
console . error ( "Store integrity check failed. Reverting Clone" ) ;
56
62
fs . rmdirSync ( path . resolve ( STORE_PATH , storeId ) , { recursive : true } ) ;
57
63
}
58
- } catch ( error : any ) {
59
- console . trace ( error . message ) ;
60
- console . error ( "Store integrity check failed. Reverting Clone" ) ;
61
- fs . rmdirSync ( path . resolve ( STORE_PATH , storeId ) , { recursive : true } ) ;
64
+ } finally {
65
+ process . exit ( 0 ) ;
62
66
}
63
67
} ;
0 commit comments