Skip to content

Commit 70ee0b8

Browse files
committed
handle spkg path better
1 parent a4f0745 commit 70ee0b8

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/cli/src/commands/init.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const protocolChoices = Array.from(Protocol.availableProtocols().keys());
3232
const initDebugger = debugFactory('graph-cli:commands:init');
3333

3434
const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum-gravatar';
35+
const DEFAULT_CONTRACT_NAME = 'Contract';
3536

3637
export default class InitCommand extends Command {
3738
static description = 'Creates a new subgraph with basic scaffolding.';
@@ -103,7 +104,6 @@ export default class InitCommand extends Command {
103104
summary: 'Network the contract is deployed to.',
104105
description:
105106
'Refer to https://github.com/graphprotocol/networks-registry/ for supported networks',
106-
dependsOn: ['from-contract'],
107107
}),
108108

109109
ipfs: Flags.string({
@@ -143,6 +143,9 @@ export default class InitCommand extends Command {
143143
'The --skip-git flag will be removed in the next major version. By default we will stop initializing a Git repository.',
144144
);
145145
}
146+
if ((!fromContract || !spkgPath) && !network) {
147+
this.error('--network is required when using --from-contract or --spkg');
148+
}
146149

147150
const { node } = chooseNodeUrl({
148151
node: nodeFlag,
@@ -200,7 +203,7 @@ export default class InitCommand extends Command {
200203

201204
// If all parameters are provided from the command-line,
202205
// go straight to creating the subgraph from an existing contract
203-
if (fromContract && protocol && subgraphName && directory && network && node) {
206+
if ((fromContract || spkgPath) && protocol && subgraphName && directory && network && node) {
204207
const registry = await loadRegistry();
205208
const contractService = new ContractService(registry);
206209

@@ -225,7 +228,7 @@ export default class InitCommand extends Command {
225228
}
226229
} else {
227230
try {
228-
abi = await contractService.getABI(ABI, network, fromContract);
231+
abi = await contractService.getABI(ABI, network, fromContract!);
229232
} catch (e) {
230233
this.exit(1);
231234
}
@@ -237,11 +240,11 @@ export default class InitCommand extends Command {
237240
protocolInstance,
238241
abi,
239242
directory,
240-
source: fromContract,
243+
source: fromContract!,
241244
indexEvents,
242245
network,
243246
subgraphName,
244-
contractName,
247+
contractName: contractName || DEFAULT_CONTRACT_NAME,
245248
node,
246249
startBlock,
247250
spkgPath,
@@ -303,7 +306,7 @@ export default class InitCommand extends Command {
303306
network: answers.network,
304307
source: answers.source,
305308
indexEvents: answers.indexEvents,
306-
contractName: answers.contractName,
309+
contractName: answers.contractName || DEFAULT_CONTRACT_NAME,
307310
node,
308311
startBlock: answers.startBlock,
309312
spkgPath: answers.spkgPath,

packages/cli/src/scaffold/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export default class Scaffold {
118118

119119
async generateManifest() {
120120
const protocolManifest = this.protocol.getManifestScaffold();
121+
const name = this.contractName || getSubgraphBasename(String(this.subgraphName));
121122

122123
return await prettier.format(
123124
`
@@ -128,7 +129,7 @@ schema:
128129
file: ./schema.graphql
129130
dataSources:
130131
- kind: ${this.protocol.name}
131-
name: ${this.contractName}
132+
name: ${name}
132133
network: ${this.network}
133134
source: ${protocolManifest.source({ ...this, spkgPath: './substreams.spkg', spkgModule: 'graph_out' })}
134135
mapping: ${protocolManifest.mapping(this)}

0 commit comments

Comments
 (0)