Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-jobs-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Add prompt for existing directory in `init` flow
34 changes: 20 additions & 14 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,6 @@
name: 'directory',
message: 'Directory to create the subgraph in',
initial: () => initDirectory || getSubgraphBasename(subgraphName),
validate: value =>
filesystem.exists(value || initDirectory || getSubgraphBasename(subgraphName))
? 'Directory already exists'
: true,
},
]);

Expand Down Expand Up @@ -506,10 +502,6 @@
name: 'directory',
message: 'Directory to create the subgraph in',
initial: () => initDirectory || getSubgraphBasename(subgraphName),
validate: value =>
filesystem.exists(value || initDirectory || getSubgraphBasename(subgraphName))
? 'Directory already exists'
: true,
},
]);

Expand Down Expand Up @@ -889,9 +881,17 @@
};
},
) {
// Fail if the output directory already exists
let overwrite = false;
if (filesystem.exists(directory)) {
this.error(`Directory or file "${directory}" already exists`, { exit: 1 });
overwrite = await prompt.confirm(
'Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?',
false,
);

if (!overwrite) {
this.exit(1);
return;
}
}

// Clone the example subgraph repository
Expand Down Expand Up @@ -921,7 +921,7 @@
return { result: false, error: `Example not found: ${fromExample}` };
}

filesystem.copy(exampleSubgraphPath, directory);
filesystem.copy(exampleSubgraphPath, directory, { overwrite });
return true;
} finally {
filesystem.remove(tmpDir);
Expand Down Expand Up @@ -1050,9 +1050,15 @@
) {
const isSubstreams = protocolInstance.name === 'substreams';

// Fail if the output directory already exists
if (filesystem.exists(directory)) {
this.error(`Directory or file "${directory}" already exists`, { exit: 1 });
if (
filesystem.exists(directory) &&
!(await prompt.confirm(
'Directory already exists, do you want to initialize the subgraph here (files will be overwritten) ?',
false,
))
) {
this.exit(1);
return;
}

if (
Expand Down Expand Up @@ -1096,7 +1102,7 @@
}

if (protocolInstance.hasContract()) {
const identifierName = protocolInstance.getContract()!.identifierName();

Check warning on line 1105 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion
const networkConf = await initNetworksConfig(directory, identifierName);
if (networkConf !== true) {
process.exitCode = 1;
Expand Down Expand Up @@ -1159,7 +1165,7 @@
const addContractConfirmation = addContractAnswer.toLowerCase() === 'y';

if (addContractConfirmation) {
const ProtocolContract = protocolInstance.getContract()!;

Check warning on line 1168 in packages/cli/src/commands/init.ts

View workflow job for this annotation

GitHub Actions / Lint

Forbidden non-null assertion

let contract = '';
for (;;) {
Expand Down
Loading