@graphprotocol/graph-cli 0.51.1 → 0.51.2-alpha-20230621172007-4f03cf8
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 +9 -0
- package/dist/commands/init.js +86 -75
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
+
## 0.51.2-alpha-20230621172007-4f03cf8
|
|
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
|
package/dist/commands/init.js
CHANGED
|
@@ -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");
|
|
@@ -78,20 +54,18 @@ class InitCommand extends core_1.Command {
|
|
|
78
54
|
const commands = {
|
|
79
55
|
link: yarn ? 'yarn link @graphprotocol/graph-cli' : 'npm link @graphprotocol/graph-cli',
|
|
80
56
|
install: yarn ? 'yarn' : 'npm install',
|
|
81
|
-
|
|
57
|
+
// this ensure we run code-generation from our CLI instead of some script in package.json
|
|
58
|
+
codegen: yarn ? 'yarn graph codegen' : 'npx graph codegen',
|
|
82
59
|
deploy: yarn ? 'yarn deploy' : 'npm run deploy',
|
|
83
60
|
};
|
|
84
61
|
// If all parameters are provided from the command-line,
|
|
85
62
|
// go straight to creating the subgraph from the example
|
|
86
|
-
if (fromExample && subgraphName && directory
|
|
63
|
+
if (fromExample && subgraphName && directory) {
|
|
87
64
|
await initSubgraphFromExample.bind(this)({
|
|
88
65
|
fromExample,
|
|
89
66
|
allowSimpleName,
|
|
90
67
|
directory,
|
|
91
68
|
subgraphName,
|
|
92
|
-
studio,
|
|
93
|
-
product,
|
|
94
|
-
protocolInstance: new protocols_1.default(protocol),
|
|
95
69
|
}, { commands });
|
|
96
70
|
// Exit with success
|
|
97
71
|
return this.exit(0);
|
|
@@ -149,40 +123,46 @@ class InitCommand extends core_1.Command {
|
|
|
149
123
|
// Exit with success
|
|
150
124
|
return this.exit(0);
|
|
151
125
|
}
|
|
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
126
|
if (fromExample) {
|
|
127
|
+
const answers = await processFromExampleInitForm.bind(this)({
|
|
128
|
+
allowSimpleName,
|
|
129
|
+
subgraphName,
|
|
130
|
+
directory,
|
|
131
|
+
});
|
|
132
|
+
if (!answers) {
|
|
133
|
+
this.exit(1);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
176
136
|
await initSubgraphFromExample.bind(this)({
|
|
177
137
|
fromExample,
|
|
178
138
|
subgraphName: answers.subgraphName,
|
|
179
139
|
directory: answers.directory,
|
|
180
|
-
studio: answers.studio,
|
|
181
|
-
product: answers.product,
|
|
182
|
-
protocolInstance: answers.protocolInstance,
|
|
183
140
|
}, { commands });
|
|
184
141
|
}
|
|
185
142
|
else {
|
|
143
|
+
// Otherwise, take the user through the interactive form
|
|
144
|
+
const answers = await processInitForm.bind(this)({
|
|
145
|
+
protocol: protocol,
|
|
146
|
+
product,
|
|
147
|
+
studio,
|
|
148
|
+
node,
|
|
149
|
+
abi,
|
|
150
|
+
abiPath,
|
|
151
|
+
allowSimpleName,
|
|
152
|
+
directory,
|
|
153
|
+
contract: fromContract,
|
|
154
|
+
indexEvents,
|
|
155
|
+
fromExample,
|
|
156
|
+
network,
|
|
157
|
+
subgraphName,
|
|
158
|
+
contractName,
|
|
159
|
+
startBlock,
|
|
160
|
+
spkgPath,
|
|
161
|
+
});
|
|
162
|
+
if (!answers) {
|
|
163
|
+
this.exit(1);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
186
166
|
({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
|
|
187
167
|
product: answers.product,
|
|
188
168
|
studio: answers.studio,
|
|
@@ -285,6 +265,51 @@ InitCommand.flags = {
|
|
|
285
265
|
}),
|
|
286
266
|
};
|
|
287
267
|
exports.default = InitCommand;
|
|
268
|
+
async function processFromExampleInitForm({ directory: initDirectory, subgraphName: initSubgraphName, allowSimpleName: initAllowSimpleName, }) {
|
|
269
|
+
try {
|
|
270
|
+
const { subgraphName } = await gluegun_1.prompt.ask([
|
|
271
|
+
{
|
|
272
|
+
type: 'input',
|
|
273
|
+
name: 'subgraphName',
|
|
274
|
+
// TODO: is defaulting to studio ok?
|
|
275
|
+
message: () => 'Subgraph slug',
|
|
276
|
+
initial: initSubgraphName,
|
|
277
|
+
validate: name => {
|
|
278
|
+
try {
|
|
279
|
+
(0, subgraph_1.validateSubgraphName)(name, { allowSimpleName: initAllowSimpleName });
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
catch (e) {
|
|
283
|
+
return `${e.message}
|
|
284
|
+
|
|
285
|
+
Examples:
|
|
286
|
+
|
|
287
|
+
$ graph init ${os_1.default.userInfo().username}/${name}
|
|
288
|
+
$ graph init ${name} --allow-simple-name`;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
]);
|
|
293
|
+
const { directory } = await gluegun_1.prompt.ask([
|
|
294
|
+
{
|
|
295
|
+
type: 'input',
|
|
296
|
+
name: 'directory',
|
|
297
|
+
message: 'Directory to create the subgraph in',
|
|
298
|
+
initial: () => initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
299
|
+
validate: value => gluegun_1.filesystem.exists(value || initDirectory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
300
|
+
? 'Directory already exists'
|
|
301
|
+
: true,
|
|
302
|
+
},
|
|
303
|
+
]);
|
|
304
|
+
return {
|
|
305
|
+
subgraphName,
|
|
306
|
+
directory,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
catch (e) {
|
|
310
|
+
this.error(e, { exit: 1 });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
288
313
|
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
314
|
let abiFromEtherscan = undefined;
|
|
290
315
|
try {
|
|
@@ -622,8 +647,7 @@ Subgraph ${subgraphName} created in ${relativeDir}
|
|
|
622
647
|
|
|
623
648
|
Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
|
|
624
649
|
}
|
|
625
|
-
async function initSubgraphFromExample({
|
|
626
|
-
const isSubstreams = protocolInstance.name === 'substreams';
|
|
650
|
+
async function initSubgraphFromExample({ fromExample, allowSimpleName, subgraphName, directory, }, { commands, }) {
|
|
627
651
|
// Fail if the subgraph name is invalid
|
|
628
652
|
if (!revalidateSubgraphName.bind(this)(subgraphName, { allowSimpleName })) {
|
|
629
653
|
process.exitCode = 1;
|
|
@@ -663,17 +687,6 @@ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSim
|
|
|
663
687
|
this.exit(1);
|
|
664
688
|
return;
|
|
665
689
|
}
|
|
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
690
|
const networkConf = await (0, network_1.initNetworksConfig)(directory, 'address');
|
|
678
691
|
if (networkConf !== true) {
|
|
679
692
|
this.exit(1);
|
|
@@ -720,13 +733,11 @@ async function initSubgraphFromExample({ protocolInstance, fromExample, allowSim
|
|
|
720
733
|
this.exit(1);
|
|
721
734
|
return;
|
|
722
735
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
736
|
+
// Run code-generation
|
|
737
|
+
const codegen = await runCodegen(directory, commands.codegen);
|
|
738
|
+
if (codegen !== true) {
|
|
739
|
+
this.exit(1);
|
|
740
|
+
return;
|
|
730
741
|
}
|
|
731
742
|
printNextSteps.bind(this)({ subgraphName, directory }, { commands });
|
|
732
743
|
}
|
package/oclif.manifest.json
CHANGED