@@ -387,10 +387,6 @@ async function processFromExampleInitForm(
387
387
name : 'directory' ,
388
388
message : 'Directory to create the subgraph in' ,
389
389
initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
390
- validate : value =>
391
- filesystem . exists ( value || initDirectory || getSubgraphBasename ( subgraphName ) )
392
- ? 'Directory already exists'
393
- : true ,
394
390
} ,
395
391
] ) ;
396
392
@@ -506,10 +502,6 @@ async function processInitForm(
506
502
name : 'directory' ,
507
503
message : 'Directory to create the subgraph in' ,
508
504
initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
509
- validate : value =>
510
- filesystem . exists ( value || initDirectory || getSubgraphBasename ( subgraphName ) )
511
- ? 'Directory already exists'
512
- : true ,
513
505
} ,
514
506
] ) ;
515
507
@@ -889,9 +881,17 @@ async function initSubgraphFromExample(
889
881
} ;
890
882
} ,
891
883
) {
892
- // Fail if the output directory already exists
884
+ let overwrite = false ;
893
885
if ( filesystem . exists ( directory ) ) {
894
- this . error ( `Directory or file "${ directory } " already exists` , { exit : 1 } ) ;
886
+ overwrite = await prompt . confirm (
887
+ 'Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?' ,
888
+ false ,
889
+ ) ;
890
+
891
+ if ( ! overwrite ) {
892
+ this . exit ( 1 ) ;
893
+ return ;
894
+ }
895
895
}
896
896
897
897
// Clone the example subgraph repository
@@ -921,7 +921,7 @@ async function initSubgraphFromExample(
921
921
return { result : false , error : `Example not found: ${ fromExample } ` } ;
922
922
}
923
923
924
- filesystem . copy ( exampleSubgraphPath , directory ) ;
924
+ filesystem . copy ( exampleSubgraphPath , directory , { overwrite } ) ;
925
925
return true ;
926
926
} finally {
927
927
filesystem . remove ( tmpDir ) ;
@@ -1050,9 +1050,15 @@ async function initSubgraphFromContract(
1050
1050
) {
1051
1051
const isSubstreams = protocolInstance . name === 'substreams' ;
1052
1052
1053
- // Fail if the output directory already exists
1054
- if ( filesystem . exists ( directory ) ) {
1055
- this . error ( `Directory or file "${ directory } " already exists` , { exit : 1 } ) ;
1053
+ if (
1054
+ filesystem . exists ( directory ) &&
1055
+ ! ( await prompt . confirm (
1056
+ 'Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?' ,
1057
+ false ,
1058
+ ) )
1059
+ ) {
1060
+ this . exit ( 1 ) ;
1061
+ return ;
1056
1062
}
1057
1063
1058
1064
if (
0 commit comments