@graphprotocol/graph-cli 0.51.1 → 0.51.2-alpha-20230620194216-37a1e4d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
+ ## 0.51.2-alpha-20230620194216-37a1e4d
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1382](https://github.com/graphprotocol/graph-tooling/pull/1382)
8
+ [`37a1e4d`](https://github.com/graphprotocol/graph-tooling/commit/37a1e4d1beaed7f069d617194f24e5449aa74ded)
9
+ Thanks [@saihaj](https://github.com/saihaj)! - Only ask directory and subgraph name when using
10
+ `graph init --from-example ...`
11
+
3
12
  ## 0.51.1
4
13
 
5
14
  ### Patch Changes
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
@@ -32,7 +9,6 @@ const path_1 = __importDefault(require("path"));
32
9
  const core_1 = require("@oclif/core");
33
10
  const gluegun_1 = require("gluegun");
34
11
  const abi_1 = require("../command-helpers/abi");
35
- const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
36
12
  const network_1 = require("../command-helpers/network");
37
13
  const node_1 = require("../command-helpers/node");
38
14
  const scaffold_1 = require("../command-helpers/scaffold");
@@ -83,15 +59,12 @@ class InitCommand extends core_1.Command {
83
59
  };
84
60
  // If all parameters are provided from the command-line,
85
61
  // go straight to creating the subgraph from the example
86
- if (fromExample && subgraphName && directory && protocol) {
62
+ if (fromExample && subgraphName && directory) {
87
63
  await initSubgraphFromExample.bind(this)({
88
64
  fromExample,
89
65
  allowSimpleName,
90
66
  directory,
91
67
  subgraphName,
92
- studio,
93
- product,
94
- protocolInstance: new protocols_1.default(protocol),
95
68
  }, { commands });
96
69
  // Exit with success
97
70
  return this.exit(0);
@@ -149,40 +122,46 @@ class InitCommand extends core_1.Command {
149
122
  // Exit with success
150
123
  return this.exit(0);
151
124
  }
152
- // Otherwise, take the user through the interactive form
153
- const answers = await processInitForm.bind(this)({
154
- protocol: protocol,
155
- product,
156
- studio,
157
- node,
158
- abi,
159
- abiPath,
160
- allowSimpleName,
161
- directory,
162
- contract: fromContract,
163
- indexEvents,
164
- fromExample,
165
- network,
166
- subgraphName,
167
- contractName,
168
- startBlock,
169
- spkgPath,
170
- });
171
- if (!answers) {
172
- this.exit(1);
173
- return;
174
- }
175
125
  if (fromExample) {
126
+ const answers = await processFromExampleInitForm.bind(this)({
127
+ allowSimpleName,
128
+ subgraphName,
129
+ directory,
130
+ });
131
+ if (!answers) {
132
+ this.exit(1);
133
+ return;
134
+ }
176
135
  await initSubgraphFromExample.bind(this)({
177
136
  fromExample,
178
137
  subgraphName: answers.subgraphName,
179
138
  directory: answers.directory,
180
- studio: answers.studio,
181
- product: answers.product,
182
- protocolInstance: answers.protocolInstance,
183
139
  }, { commands });
184
140
  }
185
141
  else {
142
+ // Otherwise, take the user through the interactive form
143
+ const answers = await processInitForm.bind(this)({
144
+ protocol: protocol,
145
+ product,
146
+ studio,
147
+ node,
148
+ abi,
149
+ abiPath,
150
+ allowSimpleName,
151
+ directory,
152
+ contract: fromContract,
153
+ indexEvents,
154
+ fromExample,
155
+ network,
156
+ subgraphName,
157
+ contractName,
158
+ startBlock,
159
+ spkgPath,
160
+ });
161
+ if (!answers) {
162
+ this.exit(1);
163
+ return;
164
+ }
186
165
  ({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
187
166
  product: answers.product,
188
167
  studio: answers.studio,
@@ -285,6 +264,51 @@ InitCommand.flags = {
285
264
  }),
286
265
  };
287
266
  exports.default = InitCommand;
267
+ async function processFromExampleInitForm({ directory: initDirectory, subgraphName: initSubgraphName, allowSimpleName: initAllowSimpleName, }) {
268
+ try {
269
+ const { subgraphName } = await gluegun_1.prompt.ask([
270
+ {
271
+ type: 'input',
272
+ name: 'subgraphName',
273
+ // TODO: is defaulting to studio ok?
274
+ message: () => 'Subgraph slug',
275
+ initial: initSubgraphName,
276
+ validate: name => {
277
+ try {
278
+ (0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
279
+ return true;
280
+ }
281
+ catch (e) {
282
+ return `${e.message}
283
+
284
+ Examples:
285
+
286
+ $ graph init ${os_1.default.userInfo().username}/${name}
287
+ $ graph init ${name} --allow-simple-name`;
288
+ }
289
+ },
290
+ },
291
+ ]);
292
+ const { directory } = await gluegun_1.prompt.ask([
293
+ {
294
+ type: 'input',
295
+ name: 'directory',
296
+ message: 'Directory to create the subgraph in',
297
+ initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
298
+ validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
299
+ ? 'Directory already exists'
300
+ : true,
301
+ },
302
+ ]);
303
+ return {
304
+ subgraphName,
305
+ directory,
306
+ };
307
+ }
308
+ catch (e) {
309
+ this.error(e, { exit: 1 });
310
+ }
311
+ }
288
312
  async function processInitForm({ protocol: initProtocol, product: initProduct, studio: initStudio, node: initNode, abi: initAbi, abiPath: initAbiPath, directory: initDirectory, contract: initContract, indexEvents: initIndexEvents, fromExample: initFromExample, network: initNetwork, subgraphName: initSubgraphName, contractName: initContractName, startBlock: initStartBlock, allowSimpleName: initAllowSimpleName, spkgPath: initSpkgPath, }) {
289
313
  let abiFromEtherscan = undefined;
290
314
  try {
@@ -622,8 +646,9 @@ Subgraph ${subgraphName} created in ${relativeDir}
622
646
 
623
647
  Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
624
648
  }
625
- async function initSubgraphFromExample({ protocolInstance, fromExample, allowSimpleName, subgraphName, directory, studio, product, }, { commands, }) {
626
- const isSubstreams = protocolInstance.name === 'substreams';
649
+ async function initSubgraphFromExample({
650
+ // protocolInstance,
651
+ fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
627
652
  // Fail if the subgraph name is invalid
628
653
  if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
629
654
  process.exitCode = 1;
@@ -663,17 +688,6 @@ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSim
663
688
  this.exit(1);
664
689
  return;
665
690
  }
666
- try {
667
- // It doesn't matter if we changed the URL we clone the YAML,
668
- // we'll check it's network anyway. If it's a studio subgraph we're dealing with.
669
- const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path_1.default.join(directory, 'subgraph.yaml'));
670
- for (const { network } of dataSourcesAndTemplates) {
671
- (0, studio_1.validateStudioNetwork)({ studio, product, network });
672
- }
673
- }
674
- catch (e) {
675
- this.error(e.message, { exit: 1 });
676
- }
677
691
  const networkConf = await (0, network_1.initNetworksConfig)(directory, 'address');
678
692
  if (networkConf !== true) {
679
693
  this.exit(1);
@@ -720,14 +734,14 @@ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSim
720
734
  this.exit(1);
721
735
  return;
722
736
  }
723
- if (!isSubstreams) {
724
- // Run code-generation
725
- const codegen = await runCodegen(directory, commands.codegen);
726
- if (codegen !== true) {
727
- this.exit(1);
728
- return;
729
- }
730
- }
737
+ // if (!isSubstreams) {
738
+ // // Run code-generation
739
+ // const codegen = await runCodegen(directory, commands.codegen);
740
+ // if (codegen !== true) {
741
+ // this.exit(1);
742
+ // return;
743
+ // }
744
+ // }
731
745
  printNextSteps.bind(this)({ subgraphName, directory }, { commands });
732
746
  }
733
747
  async function initSubgraphFromContract({ protocolInstance, allowSimpleName, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, studio, product, startBlock, spkgPath, }, { commands, addContract, }) {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.51.1",
2
+ "version": "0.51.2-alpha-20230620194216-37a1e4d",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.51.1",
3
+ "version": "0.51.2-alpha-20230620194216-37a1e4d",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {