@graphprotocol/graph-cli 0.37.2 → 0.37.3-alpha-20230110163550-d64bef6
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 +7 -0
- package/babel.config.js +3 -0
- package/dist/bin.js +6 -0
- package/dist/cli.js +32 -0
- package/dist/codegen/schema.js +250 -0
- package/dist/codegen/schema.test.js +458 -0
- package/dist/codegen/template.js +65 -0
- package/dist/codegen/types/conversions.js +359 -0
- package/dist/codegen/types/index.js +71 -0
- package/dist/codegen/types/index.test.js +563 -0
- package/dist/codegen/typescript.js +200 -0
- package/dist/codegen/util.js +46 -0
- package/dist/codegen/util.test.js +93 -0
- package/dist/command-helpers/abi.js +78 -0
- package/dist/command-helpers/auth.js +77 -0
- package/dist/command-helpers/compiler.js +66 -0
- package/dist/command-helpers/data-sources.js +29 -0
- package/dist/command-helpers/fs.js +9 -0
- package/dist/command-helpers/gluegun.js +49 -0
- package/dist/command-helpers/ipfs.js +5 -0
- package/dist/command-helpers/jsonrpc.js +29 -0
- package/dist/command-helpers/network.js +93 -0
- package/dist/command-helpers/network.test.js +86 -0
- package/dist/command-helpers/node.js +40 -0
- package/dist/command-helpers/scaffold.js +112 -0
- package/dist/command-helpers/spinner.js +84 -0
- package/dist/command-helpers/studio.js +13 -0
- package/dist/command-helpers/studio.test.js +41 -0
- package/dist/command-helpers/subgraph.js +24 -0
- package/dist/command-helpers/version.js +74 -0
- package/dist/command-helpers/version.test.js +179 -0
- package/dist/commands/add.js +190 -0
- package/dist/commands/auth.js +127 -0
- package/dist/commands/build.js +140 -0
- package/dist/commands/codegen.js +135 -0
- package/dist/commands/create.js +86 -0
- package/dist/commands/deploy.js +334 -0
- package/dist/commands/init.js +788 -0
- package/dist/commands/local.js +387 -0
- package/dist/commands/remove.js +86 -0
- package/dist/commands/test.js +295 -0
- package/dist/compiler/asc.js +83 -0
- package/dist/compiler/index.js +474 -0
- package/dist/debug.js +16 -0
- package/dist/migrations/mapping_api_version_0_0_1.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_2.js +76 -0
- package/dist/migrations/mapping_api_version_0_0_3.js +78 -0
- package/dist/migrations/mapping_api_version_0_0_4.js +80 -0
- package/dist/migrations/mapping_api_version_0_0_5.js +80 -0
- package/dist/migrations/spec_version_0_0_2.js +49 -0
- package/dist/migrations/spec_version_0_0_3.js +54 -0
- package/dist/migrations/util/load-manifest.js +18 -0
- package/dist/migrations/util/versions.js +29 -0
- package/dist/migrations.js +56 -0
- package/dist/protocols/arweave/manifest.graphql +57 -0
- package/dist/protocols/arweave/scaffold/manifest.js +18 -0
- package/dist/protocols/arweave/scaffold/mapping.js +52 -0
- package/dist/protocols/arweave/subgraph.js +23 -0
- package/dist/protocols/cosmos/manifest.graphql +76 -0
- package/dist/protocols/cosmos/scaffold/manifest.js +15 -0
- package/dist/protocols/cosmos/scaffold/mapping.js +38 -0
- package/dist/protocols/cosmos/subgraph.js +25 -0
- package/dist/protocols/ethereum/abi.js +140 -0
- package/dist/protocols/ethereum/codegen/abi.js +451 -0
- package/dist/protocols/ethereum/codegen/abi.test.js +328 -0
- package/dist/protocols/ethereum/codegen/template.js +50 -0
- package/dist/protocols/ethereum/contract.js +20 -0
- package/dist/protocols/ethereum/manifest.graphql +94 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +32 -0
- package/dist/protocols/ethereum/scaffold/mapping.js +65 -0
- package/dist/protocols/ethereum/subgraph.js +171 -0
- package/dist/protocols/ethereum/type-generator.js +125 -0
- package/dist/protocols/index.js +268 -0
- package/dist/protocols/ipfs/codegen/file_template.js +50 -0
- package/dist/protocols/near/contract.js +41 -0
- package/dist/protocols/near/manifest.graphql +64 -0
- package/dist/protocols/near/scaffold/manifest.js +16 -0
- package/dist/protocols/near/scaffold/mapping.js +38 -0
- package/dist/protocols/near/subgraph.js +20 -0
- package/dist/protocols/subgraph.js +2 -0
- package/dist/protocols/substreams/manifest.graphql +45 -0
- package/dist/protocols/substreams/scaffold/manifest.js +12 -0
- package/dist/protocols/substreams/subgraph.js +23 -0
- package/dist/scaffold/cosmos.test.js +83 -0
- package/dist/scaffold/ethereum.test.js +505 -0
- package/dist/scaffold/index.js +128 -0
- package/dist/scaffold/mapping.js +61 -0
- package/dist/scaffold/near.test.js +86 -0
- package/dist/scaffold/schema.js +83 -0
- package/dist/scaffold/tests.js +175 -0
- package/dist/schema.js +54 -0
- package/dist/subgraph.js +249 -0
- package/dist/type-generator.js +224 -0
- package/dist/validation/contract.js +46 -0
- package/dist/validation/index.js +8 -0
- package/dist/validation/manifest.js +271 -0
- package/dist/validation/schema.js +796 -0
- package/dist/validation/schema.test.js +35 -0
- package/dist/watcher.js +79 -0
- package/jest.config.js +1 -1
- package/package.json +16 -9
- package/{bin/graph → src/bin.ts} +2 -1
- package/src/cli.ts +36 -0
- package/src/codegen/schema.js +23 -22
- package/src/codegen/schema.test.js +33 -27
- package/src/codegen/{template.js → template.ts} +8 -6
- package/src/codegen/types/conversions.ts +382 -0
- package/src/codegen/types/index.js +4 -7
- package/src/codegen/types/index.test.js +10 -4
- package/src/codegen/{typescript.js → typescript.ts} +44 -26
- package/src/codegen/util.js +1 -1
- package/src/codegen/util.test.js +5 -2
- package/src/command-helpers/abi.js +46 -30
- package/src/command-helpers/auth.js +6 -9
- package/src/command-helpers/compiler.js +4 -6
- package/src/command-helpers/data-sources.js +8 -11
- package/src/command-helpers/fs.ts +5 -0
- package/src/command-helpers/gluegun.js +2 -4
- package/src/command-helpers/ipfs.ts +3 -0
- package/src/command-helpers/{jsonrpc.js → jsonrpc.ts} +11 -16
- package/src/command-helpers/network.js +58 -44
- package/src/command-helpers/network.test.js +23 -19
- package/src/command-helpers/node.js +3 -7
- package/src/command-helpers/scaffold.js +34 -25
- package/src/command-helpers/{spinner.js → spinner.ts} +10 -10
- package/src/command-helpers/studio.test.js +61 -30
- package/src/command-helpers/studio.ts +20 -0
- package/src/command-helpers/{subgraph.js → subgraph.ts} +6 -6
- package/src/command-helpers/version.js +11 -16
- package/src/command-helpers/version.test.js +111 -82
- package/src/commands/add.js +49 -35
- package/src/commands/auth.js +13 -25
- package/src/commands/build.js +9 -9
- package/src/commands/codegen.js +12 -12
- package/src/commands/create.js +22 -22
- package/src/commands/deploy.js +39 -34
- package/src/commands/init.js +21 -24
- package/src/commands/local.js +15 -14
- package/src/commands/remove.js +22 -22
- package/src/commands/test.js +86 -70
- package/src/compiler/{asc.js → asc.ts} +29 -16
- package/src/compiler/index.js +18 -18
- package/src/{debug.js → debug.ts} +2 -2
- package/src/migrations/mapping_api_version_0_0_1.js +7 -7
- package/src/migrations/mapping_api_version_0_0_2.js +5 -5
- package/src/migrations/mapping_api_version_0_0_3.js +7 -7
- package/src/migrations/mapping_api_version_0_0_4.js +7 -7
- package/src/migrations/mapping_api_version_0_0_5.js +7 -7
- package/src/migrations/spec_version_0_0_2.js +5 -5
- package/src/migrations/spec_version_0_0_3.js +5 -5
- package/src/migrations/util/load-manifest.js +6 -9
- package/src/migrations/util/versions.js +5 -10
- package/src/{migrations.js → migrations.ts} +14 -15
- package/src/protocols/arweave/scaffold/manifest.js +1 -4
- package/src/protocols/arweave/scaffold/mapping.js +1 -3
- package/src/protocols/arweave/subgraph.ts +22 -0
- package/src/protocols/cosmos/scaffold/manifest.js +1 -4
- package/src/protocols/cosmos/scaffold/mapping.js +1 -3
- package/src/protocols/cosmos/subgraph.js +2 -2
- package/src/protocols/ethereum/abi.js +7 -13
- package/src/protocols/ethereum/codegen/abi.js +219 -222
- package/src/protocols/ethereum/codegen/abi.test.js +6 -6
- package/src/protocols/ethereum/codegen/template.js +3 -5
- package/src/protocols/ethereum/contract.js +3 -2
- package/src/protocols/ethereum/scaffold/manifest.js +4 -7
- package/src/protocols/ethereum/scaffold/mapping.js +4 -11
- package/src/protocols/ethereum/subgraph.js +21 -20
- package/src/protocols/ethereum/type-generator.js +24 -30
- package/src/protocols/{index.js → index.ts} +65 -46
- package/src/protocols/ipfs/codegen/file_template.js +2 -2
- package/src/protocols/near/{contract.js → contract.ts} +16 -12
- package/src/protocols/near/scaffold/manifest.js +2 -5
- package/src/protocols/near/scaffold/mapping.js +1 -3
- package/src/protocols/near/subgraph.js +3 -6
- package/src/protocols/subgraph.ts +12 -0
- package/src/protocols/substreams/scaffold/{manifest.js → manifest.ts} +2 -7
- package/src/protocols/substreams/subgraph.ts +22 -0
- package/src/scaffold/cosmos.test.js +3 -3
- package/src/scaffold/ethereum.test.js +4 -4
- package/src/scaffold/index.js +7 -7
- package/src/scaffold/mapping.js +3 -3
- package/src/scaffold/near.test.js +3 -3
- package/src/scaffold/schema.js +4 -4
- package/src/scaffold/tests.js +72 -58
- package/src/schema.ts +26 -0
- package/src/{subgraph.js → subgraph.ts} +80 -60
- package/src/type-generator.js +20 -20
- package/src/validation/contract.js +2 -6
- package/src/validation/index.js +1 -1
- package/src/validation/manifest.js +24 -22
- package/src/validation/schema.test.js +1 -1
- package/src/validation/{schema.js → schema.ts} +268 -221
- package/src/{watcher.js → watcher.ts} +23 -12
- package/tests/cli/globalSetup.js +2 -2
- package/tests/cli/globalTeardown.js +2 -2
- package/tests/cli/init.test.js +2 -2
- package/tests/cli/util.js +7 -13
- package/tsconfig.json +18 -0
- package/src/cli.js +0 -38
- package/src/codegen/types/conversions.js +0 -329
- package/src/command-helpers/fs.js +0 -8
- package/src/command-helpers/ipfs.js +0 -6
- package/src/command-helpers/studio.js +0 -15
- package/src/protocols/arweave/subgraph.js +0 -20
- package/src/protocols/substreams/subgraph.js +0 -17
- package/src/schema.js +0 -23
|
@@ -0,0 +1,788 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const os_1 = __importDefault(require("os"));
|
|
31
|
+
const path_1 = __importDefault(require("path"));
|
|
32
|
+
const toolbox = __importStar(require("gluegun/toolbox"));
|
|
33
|
+
const fs_1 = __importDefault(require("fs"));
|
|
34
|
+
const cli_1 = __importDefault(require("../cli"));
|
|
35
|
+
const subgraph_1 = require("../command-helpers/subgraph");
|
|
36
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
37
|
+
const studio_1 = require("../command-helpers/studio");
|
|
38
|
+
const network_1 = require("../command-helpers/network");
|
|
39
|
+
const spinner_1 = require("../command-helpers/spinner");
|
|
40
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
41
|
+
const node_1 = require("../command-helpers/node");
|
|
42
|
+
const abi_1 = require("../command-helpers/abi");
|
|
43
|
+
const scaffold_1 = require("../command-helpers/scaffold");
|
|
44
|
+
const schema_1 = require("../scaffold/schema");
|
|
45
|
+
const validation_1 = require("../validation");
|
|
46
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
47
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
48
|
+
const protocolChoices = Array.from(protocols_1.default.availableProtocols().keys());
|
|
49
|
+
const availableNetworks = protocols_1.default.availableNetworks();
|
|
50
|
+
const DEFAULT_EXAMPLE_SUBGRAPH = 'ethereum/gravatar';
|
|
51
|
+
let initDebug = (0, debug_1.default)('graph-cli:init');
|
|
52
|
+
const HELP = `
|
|
53
|
+
${chalk_1.default.bold('graph init')} [options] [subgraph-name] [directory]
|
|
54
|
+
|
|
55
|
+
${chalk_1.default.dim('Options:')}
|
|
56
|
+
|
|
57
|
+
--protocol <${protocolChoices.join('|')}>
|
|
58
|
+
--product <subgraph-studio|hosted-service>
|
|
59
|
+
Selects the product for which to initialize
|
|
60
|
+
--studio Shortcut for --product subgraph-studio
|
|
61
|
+
-g, --node <node> Graph node for which to initialize
|
|
62
|
+
--allow-simple-name Use a subgraph name without a prefix (default: false)
|
|
63
|
+
-h, --help Show usage information
|
|
64
|
+
|
|
65
|
+
${chalk_1.default.dim('Choose mode with one of:')}
|
|
66
|
+
|
|
67
|
+
--from-contract <contract> Creates a scaffold based on an existing contract
|
|
68
|
+
--from-example [example] Creates a scaffold based on an example subgraph
|
|
69
|
+
|
|
70
|
+
${chalk_1.default.dim('Options for --from-contract:')}
|
|
71
|
+
|
|
72
|
+
--contract-name Name of the contract (default: Contract)
|
|
73
|
+
--index-events Index contract events as entities
|
|
74
|
+
|
|
75
|
+
${chalk_1.default.dim.underline('Ethereum:')}
|
|
76
|
+
|
|
77
|
+
--abi <path> Path to the contract ABI (default: download from Etherscan)
|
|
78
|
+
--network <${availableNetworks.get('ethereum').join('|')}>
|
|
79
|
+
Selects the network the contract is deployed to
|
|
80
|
+
|
|
81
|
+
${chalk_1.default.dim.underline('NEAR:')}
|
|
82
|
+
|
|
83
|
+
--network <${availableNetworks.get('near').join('|')}>
|
|
84
|
+
Selects the network the contract is deployed to
|
|
85
|
+
|
|
86
|
+
${chalk_1.default.dim.underline('Cosmos:')}
|
|
87
|
+
|
|
88
|
+
--network <${availableNetworks.get('cosmos').join('|')}>
|
|
89
|
+
Selects the network the contract is deployed to
|
|
90
|
+
`;
|
|
91
|
+
const processInitForm = async (toolbox, { protocol, product, studio, node, abi, allowSimpleName, directory, contract, indexEvents, fromExample, network, subgraphName, contractName, }) => {
|
|
92
|
+
let abiFromEtherscan = undefined;
|
|
93
|
+
let abiFromFile = undefined;
|
|
94
|
+
let protocolInstance;
|
|
95
|
+
let ProtocolContract;
|
|
96
|
+
let ABI;
|
|
97
|
+
let questions = [
|
|
98
|
+
{
|
|
99
|
+
type: 'select',
|
|
100
|
+
name: 'protocol',
|
|
101
|
+
message: 'Protocol',
|
|
102
|
+
choices: protocolChoices,
|
|
103
|
+
skip: protocolChoices.includes(protocol),
|
|
104
|
+
result: value => {
|
|
105
|
+
protocol = protocol || value;
|
|
106
|
+
protocolInstance = new protocols_1.default(protocol);
|
|
107
|
+
return protocol;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: 'select',
|
|
112
|
+
name: 'product',
|
|
113
|
+
message: 'Product for which to initialize',
|
|
114
|
+
choices: ['subgraph-studio', 'hosted-service'],
|
|
115
|
+
skip: () => protocol === 'arweave' ||
|
|
116
|
+
protocol === 'cosmos' ||
|
|
117
|
+
protocol === 'near' ||
|
|
118
|
+
product === 'subgraph-studio' ||
|
|
119
|
+
product === 'hosted-service' ||
|
|
120
|
+
studio !== undefined ||
|
|
121
|
+
node !== undefined,
|
|
122
|
+
result: value => {
|
|
123
|
+
// For now we only support NEAR subgraphs in the Hosted Service
|
|
124
|
+
if (protocol === 'near') {
|
|
125
|
+
// Can be overwritten because the question will be skipped (product === undefined)
|
|
126
|
+
product = 'hosted-service';
|
|
127
|
+
return product;
|
|
128
|
+
}
|
|
129
|
+
if (value == 'subgraph-studio') {
|
|
130
|
+
allowSimpleName = true;
|
|
131
|
+
}
|
|
132
|
+
product = value;
|
|
133
|
+
return value;
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: 'input',
|
|
138
|
+
name: 'subgraphName',
|
|
139
|
+
message: () => product == 'subgraph-studio' || studio ? 'Subgraph slug' : 'Subgraph name',
|
|
140
|
+
initial: subgraphName,
|
|
141
|
+
validate: name => {
|
|
142
|
+
try {
|
|
143
|
+
(0, subgraph_1.validateSubgraphName)(name, { allowSimpleName });
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
return `${e.message}
|
|
148
|
+
|
|
149
|
+
Examples:
|
|
150
|
+
|
|
151
|
+
$ graph init ${os_1.default.userInfo().username}/${name}
|
|
152
|
+
$ graph init ${name} --allow-simple-name`;
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
result: value => {
|
|
156
|
+
subgraphName = value;
|
|
157
|
+
return value;
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
type: 'input',
|
|
162
|
+
name: 'directory',
|
|
163
|
+
message: 'Directory to create the subgraph in',
|
|
164
|
+
initial: () => directory || (0, subgraph_1.getSubgraphBasename)(subgraphName),
|
|
165
|
+
validate: value => toolbox.filesystem.exists(value || directory || (0, subgraph_1.getSubgraphBasename)(subgraphName))
|
|
166
|
+
? 'Directory already exists'
|
|
167
|
+
: true,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
type: 'select',
|
|
171
|
+
name: 'network',
|
|
172
|
+
message: () => `${protocolInstance.displayName()} network`,
|
|
173
|
+
choices: () => {
|
|
174
|
+
initDebug('Generating list of available networks for protocol "%s" (%M)', protocol, availableNetworks.get(protocol));
|
|
175
|
+
return availableNetworks
|
|
176
|
+
.get(protocol) // Get networks related to the chosen protocol.
|
|
177
|
+
.toArray(); // Needed because of gluegun. It can't even receive a JS iterable.
|
|
178
|
+
},
|
|
179
|
+
skip: fromExample !== undefined,
|
|
180
|
+
initial: network || 'mainnet',
|
|
181
|
+
result: value => {
|
|
182
|
+
network = value;
|
|
183
|
+
return value;
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
// TODO:
|
|
187
|
+
//
|
|
188
|
+
// protocols that don't support contract
|
|
189
|
+
// - arweave
|
|
190
|
+
// - cosmos
|
|
191
|
+
{
|
|
192
|
+
type: 'input',
|
|
193
|
+
name: 'contract',
|
|
194
|
+
message: () => {
|
|
195
|
+
ProtocolContract = protocolInstance.getContract();
|
|
196
|
+
return `Contract ${ProtocolContract.identifierName()}`;
|
|
197
|
+
},
|
|
198
|
+
skip: () => fromExample !== undefined || !protocolInstance.hasContract(),
|
|
199
|
+
initial: contract,
|
|
200
|
+
validate: async (value) => {
|
|
201
|
+
if (fromExample !== undefined || !protocolInstance.hasContract()) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
// Validate whether the contract is valid
|
|
205
|
+
const { valid, error } = (0, validation_1.validateContract)(value, ProtocolContract);
|
|
206
|
+
return valid ? true : error;
|
|
207
|
+
},
|
|
208
|
+
result: async (value) => {
|
|
209
|
+
if (fromExample !== undefined) {
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
ABI = protocolInstance.getABI();
|
|
213
|
+
// Try loading the ABI from Etherscan, if none was provided
|
|
214
|
+
if (protocolInstance.hasABIs() && !abi) {
|
|
215
|
+
try {
|
|
216
|
+
if (network === 'poa-core') {
|
|
217
|
+
abiFromBlockScout = await (0, abi_1.loadAbiFromBlockScout)(ABI, network, value);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
abiFromEtherscan = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e) { }
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
type: 'input',
|
|
230
|
+
name: 'abi',
|
|
231
|
+
message: 'ABI file (path)',
|
|
232
|
+
initial: abi,
|
|
233
|
+
skip: () => !protocolInstance.hasABIs() ||
|
|
234
|
+
fromExample !== undefined ||
|
|
235
|
+
abiFromEtherscan !== undefined,
|
|
236
|
+
validate: async (value) => {
|
|
237
|
+
if (fromExample || abiFromEtherscan || !protocolInstance.hasABIs()) {
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
abiFromFile = await loadAbiFromFile(ABI, value);
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
244
|
+
catch (e) {
|
|
245
|
+
return e.message;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: 'input',
|
|
251
|
+
name: 'contractName',
|
|
252
|
+
message: 'Contract Name',
|
|
253
|
+
initial: contractName || 'Contract',
|
|
254
|
+
skip: () => fromExample !== undefined || !protocolInstance.hasContract(),
|
|
255
|
+
validate: value => value && value.length > 0,
|
|
256
|
+
result: value => {
|
|
257
|
+
contractName = value;
|
|
258
|
+
return value;
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
type: 'confirm',
|
|
263
|
+
name: 'indexEvents',
|
|
264
|
+
message: 'Index contract events as entities',
|
|
265
|
+
initial: true,
|
|
266
|
+
skip: () => !!indexEvents,
|
|
267
|
+
result: value => {
|
|
268
|
+
indexEvents = value;
|
|
269
|
+
return value;
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
try {
|
|
274
|
+
let answers = await toolbox.prompt.ask(questions);
|
|
275
|
+
return { ...answers, abi: abiFromEtherscan || abiFromFile, protocolInstance };
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const loadAbiFromFile = async (ABI, filename) => {
|
|
282
|
+
let exists = await toolbox.filesystem.exists(filename);
|
|
283
|
+
if (!exists) {
|
|
284
|
+
throw Error('File does not exist.');
|
|
285
|
+
}
|
|
286
|
+
else if (exists === 'dir') {
|
|
287
|
+
throw Error('Path points to a directory, not a file.');
|
|
288
|
+
}
|
|
289
|
+
else if (exists === 'other') {
|
|
290
|
+
throw Error('Not sure what this path points to.');
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return await ABI.load('Contract', filename);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
exports.default = {
|
|
297
|
+
description: 'Creates a new subgraph with basic scaffolding',
|
|
298
|
+
run: async (toolbox) => {
|
|
299
|
+
// Obtain tools
|
|
300
|
+
let { print, system } = toolbox;
|
|
301
|
+
// Read CLI parameters
|
|
302
|
+
let { protocol, product, studio, node, g, abi, allowSimpleName, fromContract, contractName, fromExample, h, help, indexEvents, network, } = toolbox.parameters.options;
|
|
303
|
+
node = node || g;
|
|
304
|
+
({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
|
|
305
|
+
product,
|
|
306
|
+
studio,
|
|
307
|
+
node,
|
|
308
|
+
allowSimpleName,
|
|
309
|
+
}));
|
|
310
|
+
if (fromContract && fromExample) {
|
|
311
|
+
print.error(`Only one of --from-example and --from-contract can be used at a time.`);
|
|
312
|
+
process.exitCode = 1;
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
let subgraphName, directory;
|
|
316
|
+
try {
|
|
317
|
+
;
|
|
318
|
+
[subgraphName, directory] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
319
|
+
allowSimpleName,
|
|
320
|
+
help,
|
|
321
|
+
h,
|
|
322
|
+
indexEvents,
|
|
323
|
+
studio,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
print.error(e.message);
|
|
328
|
+
process.exitCode = 1;
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
// Show help text if requested
|
|
332
|
+
if (help || h) {
|
|
333
|
+
print.info(HELP);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
// Detect git
|
|
337
|
+
let git = await system.which('git');
|
|
338
|
+
if (git === null) {
|
|
339
|
+
print.error(`Git was not found on your system. Please install 'git' so it is in $PATH.`);
|
|
340
|
+
process.exitCode = 1;
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
// Detect Yarn and/or NPM
|
|
344
|
+
let yarn = await system.which('yarn');
|
|
345
|
+
let npm = await system.which('npm');
|
|
346
|
+
if (!yarn && !npm) {
|
|
347
|
+
print.error(`Neither Yarn nor NPM were found on your system. Please install one of them.`);
|
|
348
|
+
process.exitCode = 1;
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
let commands = {
|
|
352
|
+
install: yarn ? 'yarn' : 'npm install',
|
|
353
|
+
codegen: yarn ? 'yarn codegen' : 'npm run codegen',
|
|
354
|
+
deploy: yarn ? 'yarn deploy' : 'npm run deploy',
|
|
355
|
+
};
|
|
356
|
+
// If all parameters are provided from the command-line,
|
|
357
|
+
// go straight to creating the subgraph from the example
|
|
358
|
+
if (fromExample && subgraphName && directory) {
|
|
359
|
+
return await initSubgraphFromExample(toolbox, { fromExample, allowSimpleName, directory, subgraphName, studio, product }, { commands });
|
|
360
|
+
}
|
|
361
|
+
// If all parameters are provided from the command-line,
|
|
362
|
+
// go straight to creating the subgraph from an existing contract
|
|
363
|
+
if (fromContract && protocol && subgraphName && directory && network && node) {
|
|
364
|
+
if (!protocolChoices.includes(protocol)) {
|
|
365
|
+
print.error(`Protocol '${protocol}' is not supported, choose from these options: ${protocolChoices.join(', ')}`);
|
|
366
|
+
process.exitCode = 1;
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const protocolInstance = new protocols_1.default(protocol);
|
|
370
|
+
if (protocolInstance.hasABIs()) {
|
|
371
|
+
const ABI = protocolInstance.getABI();
|
|
372
|
+
if (abi) {
|
|
373
|
+
try {
|
|
374
|
+
abi = await loadAbiFromFile(ABI, abi);
|
|
375
|
+
}
|
|
376
|
+
catch (e) {
|
|
377
|
+
print.error(`Failed to load ABI: ${e.message}`);
|
|
378
|
+
process.exitCode = 1;
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
try {
|
|
384
|
+
if (network === 'poa-core') {
|
|
385
|
+
abi = await (0, abi_1.loadAbiFromBlockScout)(ABI, network, fromContract);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
abi = await (0, abi_1.loadAbiFromEtherscan)(ABI, network, fromContract);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
catch (e) {
|
|
392
|
+
process.exitCode = 1;
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return await initSubgraphFromContract(toolbox, {
|
|
398
|
+
protocolInstance,
|
|
399
|
+
abi,
|
|
400
|
+
allowSimpleName,
|
|
401
|
+
directory,
|
|
402
|
+
contract: fromContract,
|
|
403
|
+
indexEvents,
|
|
404
|
+
network,
|
|
405
|
+
subgraphName,
|
|
406
|
+
contractName,
|
|
407
|
+
node,
|
|
408
|
+
studio,
|
|
409
|
+
product,
|
|
410
|
+
}, { commands, addContract: false });
|
|
411
|
+
}
|
|
412
|
+
// Otherwise, take the user through the interactive form
|
|
413
|
+
let inputs = await processInitForm(toolbox, {
|
|
414
|
+
protocol,
|
|
415
|
+
product,
|
|
416
|
+
studio,
|
|
417
|
+
node,
|
|
418
|
+
abi,
|
|
419
|
+
allowSimpleName,
|
|
420
|
+
directory,
|
|
421
|
+
contract: fromContract,
|
|
422
|
+
indexEvents,
|
|
423
|
+
fromExample,
|
|
424
|
+
network,
|
|
425
|
+
subgraphName,
|
|
426
|
+
contractName,
|
|
427
|
+
});
|
|
428
|
+
// Exit immediately when the form is cancelled
|
|
429
|
+
if (inputs === undefined) {
|
|
430
|
+
process.exit(1);
|
|
431
|
+
}
|
|
432
|
+
print.info('———');
|
|
433
|
+
if (fromExample) {
|
|
434
|
+
await initSubgraphFromExample(toolbox, {
|
|
435
|
+
fromExample: fromExample,
|
|
436
|
+
subgraphName: inputs.subgraphName,
|
|
437
|
+
directory: inputs.directory,
|
|
438
|
+
studio: inputs.studio,
|
|
439
|
+
product: inputs.product,
|
|
440
|
+
}, { commands });
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
;
|
|
444
|
+
({ node, allowSimpleName } = (0, node_1.chooseNodeUrl)({
|
|
445
|
+
product: inputs.product,
|
|
446
|
+
studio,
|
|
447
|
+
node,
|
|
448
|
+
allowSimpleName,
|
|
449
|
+
}));
|
|
450
|
+
await initSubgraphFromContract(toolbox, {
|
|
451
|
+
protocolInstance: inputs.protocolInstance,
|
|
452
|
+
allowSimpleName,
|
|
453
|
+
subgraphName: inputs.subgraphName,
|
|
454
|
+
directory: inputs.directory,
|
|
455
|
+
abi: inputs.abi,
|
|
456
|
+
network: inputs.network,
|
|
457
|
+
contract: inputs.contract,
|
|
458
|
+
indexEvents: inputs.indexEvents,
|
|
459
|
+
contractName: inputs.contractName,
|
|
460
|
+
node,
|
|
461
|
+
studio: inputs.studio,
|
|
462
|
+
product: inputs.product,
|
|
463
|
+
}, { commands, addContract: true });
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
const revalidateSubgraphName = async (toolbox, subgraphName, { allowSimpleName }) => {
|
|
468
|
+
// Fail if the subgraph name is invalid
|
|
469
|
+
try {
|
|
470
|
+
(0, subgraph_1.validateSubgraphName)(subgraphName, { allowSimpleName });
|
|
471
|
+
return true;
|
|
472
|
+
}
|
|
473
|
+
catch (e) {
|
|
474
|
+
toolbox.print.error(`${e.message}
|
|
475
|
+
|
|
476
|
+
Examples:
|
|
477
|
+
|
|
478
|
+
$ graph init ${os_1.default.userInfo().username}/${subgraphName}
|
|
479
|
+
$ graph init ${subgraphName} --allow-simple-name`);
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
const initRepository = async (toolbox, directory) => await (0, spinner_1.withSpinner)(`Initialize subgraph repository`, `Failed to initialize subgraph repository`, `Warnings while initializing subgraph repository`, async (spinner) => {
|
|
484
|
+
// Remove .git dir in --from-example mode; in --from-contract, we're
|
|
485
|
+
// starting from an empty directory
|
|
486
|
+
let gitDir = path_1.default.join(directory, '.git');
|
|
487
|
+
if (toolbox.filesystem.exists(gitDir)) {
|
|
488
|
+
await toolbox.filesystem.remove(gitDir);
|
|
489
|
+
}
|
|
490
|
+
await toolbox.system.run('git init', { cwd: directory });
|
|
491
|
+
await toolbox.system.run('git add --all', { cwd: directory });
|
|
492
|
+
await toolbox.system.run('git commit -m "Initial commit"', {
|
|
493
|
+
cwd: directory,
|
|
494
|
+
});
|
|
495
|
+
return true;
|
|
496
|
+
});
|
|
497
|
+
// Only used for local testing / continuous integration.
|
|
498
|
+
//
|
|
499
|
+
// This requires that the command `npm link` is called
|
|
500
|
+
// on the root directory of this repository, as described here:
|
|
501
|
+
// https://docs.npmjs.com/cli/v7/commands/npm-link.
|
|
502
|
+
const npmLinkToLocalCli = async (toolbox, directory) => {
|
|
503
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
504
|
+
await toolbox.system.run('npm link @graphprotocol/graph-cli', { cwd: directory });
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const installDependencies = async (toolbox, directory, installCommand) => await (0, spinner_1.withSpinner)(`Install dependencies with ${toolbox.print.colors.muted(installCommand)}`, `Failed to install dependencies`, `Warnings while installing dependencies`, async (spinner) => {
|
|
508
|
+
// Links to local graph-cli if we're running the automated tests
|
|
509
|
+
await npmLinkToLocalCli(toolbox, directory);
|
|
510
|
+
await toolbox.system.run(installCommand, { cwd: directory });
|
|
511
|
+
return true;
|
|
512
|
+
});
|
|
513
|
+
const runCodegen = async (toolbox, directory, codegenCommand) => await (0, spinner_1.withSpinner)(`Generate ABI and schema types with ${toolbox.print.colors.muted(codegenCommand)}`, `Failed to generate code from ABI and GraphQL schema`, `Warnings while generating code from ABI and GraphQL schema`, async (spinner) => {
|
|
514
|
+
await toolbox.system.run(codegenCommand, { cwd: directory });
|
|
515
|
+
return true;
|
|
516
|
+
});
|
|
517
|
+
const printNextSteps = (toolbox, { subgraphName, directory }, { commands }) => {
|
|
518
|
+
let { print } = toolbox;
|
|
519
|
+
let relativeDir = path_1.default.relative(process.cwd(), directory);
|
|
520
|
+
// Print instructions
|
|
521
|
+
print.success(`
|
|
522
|
+
Subgraph ${print.colors.blue(subgraphName)} created in ${print.colors.blue(relativeDir)}
|
|
523
|
+
`);
|
|
524
|
+
print.info(`Next steps:
|
|
525
|
+
|
|
526
|
+
1. Run \`${print.colors.muted('graph auth')}\` to authenticate with your deploy key.
|
|
527
|
+
|
|
528
|
+
2. Type \`${print.colors.muted(`cd ${relativeDir}`)}\` to enter the subgraph.
|
|
529
|
+
|
|
530
|
+
3. Run \`${print.colors.muted(commands.deploy)}\` to deploy the subgraph.
|
|
531
|
+
|
|
532
|
+
Make sure to visit the documentation on https://thegraph.com/docs/ for further information.`);
|
|
533
|
+
};
|
|
534
|
+
const initSubgraphFromExample = async (toolbox, { fromExample, allowSimpleName, subgraphName, directory, studio, product }, { commands }) => {
|
|
535
|
+
let { filesystem, print, system } = toolbox;
|
|
536
|
+
// Fail if the subgraph name is invalid
|
|
537
|
+
if (!revalidateSubgraphName(toolbox, subgraphName, { allowSimpleName })) {
|
|
538
|
+
process.exitCode = 1;
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
// Fail if the output directory already exists
|
|
542
|
+
if (filesystem.exists(directory)) {
|
|
543
|
+
print.error(`Directory or file "${directory}" already exists`);
|
|
544
|
+
process.exitCode = 1;
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
// Clone the example subgraph repository
|
|
548
|
+
let cloned = await (0, spinner_1.withSpinner)(`Cloning example subgraph`, `Failed to clone example subgraph`, `Warnings while cloning example subgraph`, async (spinner) => {
|
|
549
|
+
// Create a temporary directory
|
|
550
|
+
const prefix = path_1.default.join(os_1.default.tmpdir(), 'example-subgraph-');
|
|
551
|
+
const tmpDir = fs_1.default.mkdtempSync(prefix);
|
|
552
|
+
try {
|
|
553
|
+
await system.run(`git clone http://github.com/graphprotocol/example-subgraphs ${tmpDir}`);
|
|
554
|
+
// If an example is not specified, use the default one
|
|
555
|
+
if (fromExample === undefined || fromExample === true) {
|
|
556
|
+
fromExample = DEFAULT_EXAMPLE_SUBGRAPH;
|
|
557
|
+
}
|
|
558
|
+
const exampleSubgraphPath = path_1.default.join(tmpDir, fromExample);
|
|
559
|
+
if (!filesystem.exists(exampleSubgraphPath)) {
|
|
560
|
+
return { result: false, error: `Example not found: ${fromExample}` };
|
|
561
|
+
}
|
|
562
|
+
filesystem.copy(exampleSubgraphPath, directory);
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
finally {
|
|
566
|
+
filesystem.remove(tmpDir);
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
if (!cloned) {
|
|
570
|
+
process.exitCode = 1;
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
// It doesn't matter if we changed the URL we clone the YAML,
|
|
575
|
+
// we'll check it's network anyway. If it's a studio subgraph we're dealing with.
|
|
576
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path_1.default.join(directory, 'subgraph.yaml'));
|
|
577
|
+
for (const { network } of dataSourcesAndTemplates) {
|
|
578
|
+
(0, studio_1.validateStudioNetwork)({ studio, product, network });
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
catch (e) {
|
|
582
|
+
print.error(e.message);
|
|
583
|
+
process.exitCode = 1;
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
let networkConf = await (0, network_1.initNetworksConfig)(toolbox, directory, 'address');
|
|
587
|
+
if (networkConf !== true) {
|
|
588
|
+
process.exitCode = 1;
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
// Update package.json to match the subgraph name
|
|
592
|
+
let prepared = await (0, spinner_1.withSpinner)(`Update subgraph name and commands in package.json`, `Failed to update subgraph name and commands in package.json`, `Warnings while updating subgraph name and commands in package.json`, async (spinner) => {
|
|
593
|
+
try {
|
|
594
|
+
// Load package.json
|
|
595
|
+
let pkgJsonFilename = filesystem.path(directory, 'package.json');
|
|
596
|
+
let pkgJson = await filesystem.read(pkgJsonFilename, 'json');
|
|
597
|
+
pkgJson.name = (0, subgraph_1.getSubgraphBasename)(subgraphName);
|
|
598
|
+
Object.keys(pkgJson.scripts).forEach(name => {
|
|
599
|
+
pkgJson.scripts[name] = pkgJson.scripts[name].replace('example', subgraphName);
|
|
600
|
+
});
|
|
601
|
+
delete pkgJson['license'];
|
|
602
|
+
delete pkgJson['repository'];
|
|
603
|
+
// Remove example's cli in favor of the local one (added via `npm link`)
|
|
604
|
+
if (process.env.GRAPH_CLI_TESTS) {
|
|
605
|
+
delete pkgJson['devDependencies']['@graphprotocol/graph-cli'];
|
|
606
|
+
}
|
|
607
|
+
// Write package.json
|
|
608
|
+
await filesystem.write(pkgJsonFilename, pkgJson, { jsonIndent: 2 });
|
|
609
|
+
return true;
|
|
610
|
+
}
|
|
611
|
+
catch (e) {
|
|
612
|
+
print.error(`Failed to preconfigure the subgraph: ${e}`);
|
|
613
|
+
filesystem.remove(directory);
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
if (!prepared) {
|
|
618
|
+
process.exitCode = 1;
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
// Initialize a fresh Git repository
|
|
622
|
+
let repo = await initRepository(toolbox, directory);
|
|
623
|
+
if (repo !== true) {
|
|
624
|
+
process.exitCode = 1;
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
// Install dependencies
|
|
628
|
+
let installed = await installDependencies(toolbox, directory, commands.install);
|
|
629
|
+
if (installed !== true) {
|
|
630
|
+
process.exitCode = 1;
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
// Run code-generation
|
|
634
|
+
let codegen = await runCodegen(toolbox, directory, commands.codegen);
|
|
635
|
+
if (codegen !== true) {
|
|
636
|
+
process.exitCode = 1;
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
639
|
+
printNextSteps(toolbox, { subgraphName, directory }, { commands });
|
|
640
|
+
};
|
|
641
|
+
const initSubgraphFromContract = async (toolbox, { protocolInstance, allowSimpleName, subgraphName, directory, abi, network, contract, indexEvents, contractName, node, studio, product, }, { commands, addContract }) => {
|
|
642
|
+
let { print } = toolbox;
|
|
643
|
+
// Fail if the subgraph name is invalid
|
|
644
|
+
if (!revalidateSubgraphName(toolbox, subgraphName, { allowSimpleName })) {
|
|
645
|
+
process.exitCode = 1;
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
// Fail if the output directory already exists
|
|
649
|
+
if (toolbox.filesystem.exists(directory)) {
|
|
650
|
+
print.error(`Directory or file "${directory}" already exists`);
|
|
651
|
+
process.exitCode = 1;
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
if (protocolInstance.hasABIs() && (0, schema_1.abiEvents)(abi).length === 0) {
|
|
655
|
+
// Fail if the ABI does not contain any events
|
|
656
|
+
print.error(`ABI does not contain any events`);
|
|
657
|
+
process.exitCode = 1;
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
// We can validate this before the scaffold because we receive
|
|
661
|
+
// the network from the form or via command line argument.
|
|
662
|
+
// We don't need to read the manifest in this case.
|
|
663
|
+
try {
|
|
664
|
+
(0, studio_1.validateStudioNetwork)({ studio, product, network });
|
|
665
|
+
}
|
|
666
|
+
catch (e) {
|
|
667
|
+
print.error(e.message);
|
|
668
|
+
process.exitCode = 1;
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
// Scaffold subgraph
|
|
672
|
+
let scaffold = await (0, spinner_1.withSpinner)(`Create subgraph scaffold`, `Failed to create subgraph scaffold`, `Warnings while creating subgraph scaffold`, async (spinner) => {
|
|
673
|
+
let scaffold = await (0, scaffold_1.generateScaffold)({
|
|
674
|
+
protocolInstance,
|
|
675
|
+
subgraphName,
|
|
676
|
+
abi,
|
|
677
|
+
network,
|
|
678
|
+
contract,
|
|
679
|
+
indexEvents,
|
|
680
|
+
contractName,
|
|
681
|
+
node,
|
|
682
|
+
}, spinner);
|
|
683
|
+
await (0, scaffold_1.writeScaffold)(scaffold, directory, spinner);
|
|
684
|
+
return true;
|
|
685
|
+
});
|
|
686
|
+
if (scaffold !== true) {
|
|
687
|
+
process.exitCode = 1;
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
if (protocolInstance.hasContract()) {
|
|
691
|
+
let identifierName = protocolInstance.getContract().identifierName();
|
|
692
|
+
let networkConf = await (0, network_1.initNetworksConfig)(toolbox, directory, identifierName);
|
|
693
|
+
if (networkConf !== true) {
|
|
694
|
+
process.exitCode = 1;
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
// Initialize a fresh Git repository
|
|
699
|
+
let repo = await initRepository(toolbox, directory);
|
|
700
|
+
if (repo !== true) {
|
|
701
|
+
process.exitCode = 1;
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
// Install dependencies
|
|
705
|
+
let installed = await installDependencies(toolbox, directory, commands.install);
|
|
706
|
+
if (installed !== true) {
|
|
707
|
+
process.exitCode = 1;
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
// Run code-generation
|
|
711
|
+
let codegen = await runCodegen(toolbox, directory, commands.codegen);
|
|
712
|
+
if (codegen !== true) {
|
|
713
|
+
process.exitCode = 1;
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
while (addContract) {
|
|
717
|
+
addContract = await addAnotherContract(toolbox, { protocolInstance, directory });
|
|
718
|
+
}
|
|
719
|
+
printNextSteps(toolbox, { subgraphName, directory }, { commands });
|
|
720
|
+
};
|
|
721
|
+
const addAnotherContract = async (toolbox, { protocolInstance, directory }) => {
|
|
722
|
+
const addContractConfirmation = await toolbox.prompt.confirm('Add another contract?');
|
|
723
|
+
if (addContractConfirmation) {
|
|
724
|
+
let abiFromFile;
|
|
725
|
+
let ProtocolContract = protocolInstance.getContract();
|
|
726
|
+
let questions = [
|
|
727
|
+
{
|
|
728
|
+
type: 'input',
|
|
729
|
+
name: 'contract',
|
|
730
|
+
message: () => `Contract ${ProtocolContract.identifierName()}`,
|
|
731
|
+
validate: async (value) => {
|
|
732
|
+
// Validate whether the contract is valid
|
|
733
|
+
const { valid, error } = (0, validation_1.validateContract)(value, ProtocolContract);
|
|
734
|
+
return valid ? true : error;
|
|
735
|
+
},
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
type: 'select',
|
|
739
|
+
name: 'localAbi',
|
|
740
|
+
message: 'Provide local ABI path?',
|
|
741
|
+
choices: ['yes', 'no'],
|
|
742
|
+
result: value => {
|
|
743
|
+
abiFromFile = value === 'yes' ? true : false;
|
|
744
|
+
return abiFromFile;
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
type: 'input',
|
|
749
|
+
name: 'abi',
|
|
750
|
+
message: 'ABI file (path)',
|
|
751
|
+
skip: () => abiFromFile === false,
|
|
752
|
+
},
|
|
753
|
+
{
|
|
754
|
+
type: 'input',
|
|
755
|
+
name: 'contractName',
|
|
756
|
+
message: 'Contract Name',
|
|
757
|
+
initial: 'Contract',
|
|
758
|
+
validate: value => value && value.length > 0,
|
|
759
|
+
},
|
|
760
|
+
];
|
|
761
|
+
// Get the cwd before process.chdir in order to switch back in the end of command execution
|
|
762
|
+
const cwd = process.cwd();
|
|
763
|
+
try {
|
|
764
|
+
let { abi, contract, contractName } = await toolbox.prompt.ask(questions);
|
|
765
|
+
if (fs_1.default.existsSync(directory)) {
|
|
766
|
+
process.chdir(directory);
|
|
767
|
+
}
|
|
768
|
+
let commandLine = ['add', contract, '--contract-name', contractName];
|
|
769
|
+
if (abiFromFile) {
|
|
770
|
+
if (abi.includes(directory)) {
|
|
771
|
+
commandLine.push('--abi', path_1.default.normalize(abi.replace(directory, '')));
|
|
772
|
+
}
|
|
773
|
+
else {
|
|
774
|
+
commandLine.push('--abi', abi);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
await cli_1.default.run(commandLine);
|
|
778
|
+
}
|
|
779
|
+
catch (e) {
|
|
780
|
+
toolbox.print.error(e);
|
|
781
|
+
process.exit(1);
|
|
782
|
+
}
|
|
783
|
+
finally {
|
|
784
|
+
process.chdir(cwd);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return addContractConfirmation;
|
|
788
|
+
};
|