Skip to content

Commit c51f6f9

Browse files
committed
Add index-events as default to init-form-wizard
1 parent fa44165 commit c51f6f9

File tree

1 file changed

+54
-30
lines changed

1 file changed

+54
-30
lines changed

src/commands/init.js

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ const processInitForm = async (
7777
allowSimpleName,
7878
directory,
7979
contract,
80+
indexEvents,
8081
fromExample,
8182
network,
8283
subgraphName,
83-
contractName
84+
contractName,
8485
},
8586
) => {
8687
let abiFromEtherscan = undefined
@@ -108,10 +109,13 @@ const processInitForm = async (
108109
message: 'Product for which to initialize',
109110
choices: ['subgraph-studio', 'hosted-service'],
110111
skip: () =>
111-
protocol === 'arweave' || protocol === 'cosmos' || protocol === 'near' ||
112+
protocol === 'arweave' ||
113+
protocol === 'cosmos' ||
114+
protocol === 'near' ||
112115
product === 'subgraph-studio' ||
113116
product === 'hosted-service' ||
114-
studio !== undefined || node !== undefined,
117+
studio !== undefined ||
118+
node !== undefined,
115119
result: value => {
116120
// For now we only support NEAR subgraphs in the Hosted Service
117121
if (protocol === 'near') {
@@ -131,7 +135,8 @@ const processInitForm = async (
131135
{
132136
type: 'input',
133137
name: 'subgraphName',
134-
message: () => product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name',
138+
message: () =>
139+
product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name',
135140
initial: subgraphName,
136141
validate: name => {
137142
try {
@@ -198,9 +203,7 @@ const processInitForm = async (
198203
// Validate whether the contract is valid
199204
const { valid, error } = validateContract(value, ProtocolContract)
200205

201-
return valid
202-
? true
203-
: error
206+
return valid ? true : error
204207
},
205208
result: async value => {
206209
if (fromExample !== undefined) {
@@ -254,7 +257,18 @@ const processInitForm = async (
254257
result: value => {
255258
contractName = value
256259
return value
257-
}
260+
},
261+
},
262+
{
263+
type: 'confirm',
264+
name: 'indexEvents',
265+
message: 'Index contract events as entities',
266+
initial: true,
267+
skip: () => !!indexEvents,
268+
result: value => {
269+
indexEvents = value
270+
return value
271+
},
258272
},
259273
]
260274

@@ -305,7 +319,12 @@ module.exports = {
305319
} = toolbox.parameters.options
306320

307321
node = node || g
308-
;({ node, allowSimpleName } = chooseNodeUrl({ product, studio, node, allowSimpleName }))
322+
;({ node, allowSimpleName } = chooseNodeUrl({
323+
product,
324+
studio,
325+
node,
326+
allowSimpleName,
327+
}))
309328

310329
if (fromContract && fromExample) {
311330
print.error(`Only one of --from-example and --from-contract can be used at a time.`)
@@ -320,7 +339,7 @@ module.exports = {
320339
help,
321340
h,
322341
indexEvents,
323-
studio
342+
studio,
324343
})
325344
} catch (e) {
326345
print.error(e.message)
@@ -375,7 +394,11 @@ module.exports = {
375394
// go straight to creating the subgraph from an existing contract
376395
if (fromContract && protocol && subgraphName && directory && network && node) {
377396
if (!protocolChoices.includes(protocol)) {
378-
print.error(`Protocol '${protocol}' is not supported, choose from these options: ${protocolChoices.join(', ')}`)
397+
print.error(
398+
`Protocol '${protocol}' is not supported, choose from these options: ${protocolChoices.join(
399+
', ',
400+
)}`,
401+
)
379402
process.exitCode = 1
380403
return
381404
}
@@ -420,7 +443,7 @@ module.exports = {
420443
contractName,
421444
node,
422445
studio,
423-
product
446+
product,
424447
},
425448
{ commands, addContract: false },
426449
)
@@ -436,10 +459,11 @@ module.exports = {
436459
allowSimpleName,
437460
directory,
438461
contract: fromContract,
462+
indexEvents,
439463
fromExample,
440464
network,
441465
subgraphName,
442-
contractName
466+
contractName,
443467
})
444468

445469
// Exit immediately when the form is cancelled
@@ -466,7 +490,7 @@ module.exports = {
466490
product: inputs.product,
467491
studio,
468492
node,
469-
allowSimpleName
493+
allowSimpleName,
470494
}))
471495
await initSubgraphFromContract(
472496
toolbox,
@@ -478,11 +502,11 @@ module.exports = {
478502
abi: inputs.abi,
479503
network: inputs.network,
480504
contract: inputs.contract,
481-
indexEvents,
505+
indexEvents: inputs.indexEvents,
482506
contractName: inputs.contractName,
483507
node,
484508
studio: inputs.studio,
485-
product: inputs.product
509+
product: inputs.product,
486510
},
487511
{ commands, addContract: true },
488512
)
@@ -617,24 +641,23 @@ const initSubgraphFromExample = async (
617641

618642
try {
619643
await system.run(
620-
`git clone http://github.com/graphprotocol/example-subgraphs ${tmpDir}`
644+
`git clone http://github.com/graphprotocol/example-subgraphs ${tmpDir}`,
621645
)
622646

623647
// If an example is not specified, use the default one
624648
if (fromExample === undefined || fromExample === true) {
625649
fromExample = DEFAULT_EXAMPLE_SUBGRAPH
626650
}
627651

628-
const exampleSubgraphPath = path.join(tmpDir, fromExample);
652+
const exampleSubgraphPath = path.join(tmpDir, fromExample)
629653

630654
if (!filesystem.exists(exampleSubgraphPath)) {
631655
return { result: false, error: `Example not found: ${fromExample}` }
632656
}
633657

634658
filesystem.copy(exampleSubgraphPath, directory)
635659
return true
636-
}
637-
finally {
660+
} finally {
638661
filesystem.remove(tmpDir)
639662
}
640663
},
@@ -647,7 +670,9 @@ const initSubgraphFromExample = async (
647670
try {
648671
// It doesn't matter if we changed the URL we clone the YAML,
649672
// we'll check it's network anyway. If it's a studio subgraph we're dealing with.
650-
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path.join(directory, 'subgraph.yaml'))
673+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(
674+
path.join(directory, 'subgraph.yaml'),
675+
)
651676

652677
for (const { network } of dataSourcesAndTemplates) {
653678
validateStudioNetwork({ studio, product, network })
@@ -658,7 +683,7 @@ const initSubgraphFromExample = async (
658683
return
659684
}
660685

661-
let networkConf = await initNetworksConfig(toolbox, directory, "address")
686+
let networkConf = await initNetworksConfig(toolbox, directory, 'address')
662687
if (networkConf !== true) {
663688
process.exitCode = 1
664689
return
@@ -740,7 +765,7 @@ const initSubgraphFromContract = async (
740765
contractName,
741766
node,
742767
studio,
743-
product
768+
product,
744769
},
745770
{ commands, addContract },
746771
) => {
@@ -854,7 +879,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
854879
type: 'input',
855880
name: 'contract',
856881
message: () => `Contract ${ProtocolContract.identifierName()}`,
857-
validate: async (value) => {
882+
validate: async value => {
858883
// Validate whether the contract is valid
859884
const { valid, error } = validateContract(value, ProtocolContract)
860885
return valid ? true : error
@@ -865,7 +890,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
865890
name: 'localAbi',
866891
message: 'Provide local ABI path?',
867892
choices: ['yes', 'no'],
868-
result: (value) => {
893+
result: value => {
869894
abiFromFile = value === 'yes' ? true : false
870895
return abiFromFile
871896
},
@@ -874,19 +899,19 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
874899
type: 'input',
875900
name: 'abi',
876901
message: 'ABI file (path)',
877-
skip: () => abiFromFile === false
902+
skip: () => abiFromFile === false,
878903
},
879904
{
880905
type: 'input',
881906
name: 'contractName',
882907
message: 'Contract Name',
883908
initial: 'Contract',
884-
validate: (value) => value && value.length > 0,
909+
validate: value => value && value.length > 0,
885910
},
886911
]
887912

888913
// Get the cwd before process.chdir in order to switch back in the end of command execution
889-
const cwd = process.cwd();
914+
const cwd = process.cwd()
890915

891916
try {
892917
let { abi, contract, contractName } = await toolbox.prompt.ask(questions)
@@ -909,8 +934,7 @@ const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
909934
} catch (e) {
910935
toolbox.print.error(e)
911936
process.exit(1)
912-
}
913-
finally {
937+
} finally {
914938
process.chdir(cwd)
915939
}
916940
}

0 commit comments

Comments
 (0)