@@ -387,10 +387,6 @@ async function processFromExampleInitForm(
387387 name : 'directory' ,
388388 message : 'Directory to create the subgraph in' ,
389389 initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
390- validate : value =>
391- filesystem . exists ( value || initDirectory || getSubgraphBasename ( subgraphName ) )
392- ? 'Directory already exists'
393- : true ,
394390 } ,
395391 ] ) ;
396392
@@ -506,10 +502,6 @@ async function processInitForm(
506502 name : 'directory' ,
507503 message : 'Directory to create the subgraph in' ,
508504 initial : ( ) => initDirectory || getSubgraphBasename ( subgraphName ) ,
509- validate : value =>
510- filesystem . exists ( value || initDirectory || getSubgraphBasename ( subgraphName ) )
511- ? 'Directory already exists'
512- : true ,
513505 } ,
514506 ] ) ;
515507
@@ -889,9 +881,17 @@ async function initSubgraphFromExample(
889881 } ;
890882 } ,
891883) {
892- // Fail if the output directory already exists
884+ let overwrite = false ;
893885 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+ }
895895 }
896896
897897 // Clone the example subgraph repository
@@ -921,7 +921,7 @@ async function initSubgraphFromExample(
921921 return { result : false , error : `Example not found: ${ fromExample } ` } ;
922922 }
923923
924- filesystem . copy ( exampleSubgraphPath , directory ) ;
924+ filesystem . copy ( exampleSubgraphPath , directory , { overwrite } ) ;
925925 return true ;
926926 } finally {
927927 filesystem . remove ( tmpDir ) ;
@@ -1050,9 +1050,15 @@ async function initSubgraphFromContract(
10501050) {
10511051 const isSubstreams = protocolInstance . name === 'substreams' ;
10521052
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 ;
10561062 }
10571063
10581064 if (
0 commit comments