@graphprotocol/graph-cli 0.38.0-alpha-20230131175746-0102e0f → 0.38.0
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 +5 -1
- package/dist/bin.js +3 -31
- package/dist/cli.js +26 -0
- package/dist/command-helpers/scaffold.js +2 -1
- package/dist/commands/add.js +183 -25
- package/dist/commands/auth.js +122 -0
- package/dist/commands/build.js +136 -0
- package/dist/commands/codegen.js +128 -0
- package/dist/commands/create.js +94 -0
- package/dist/commands/deploy.js +335 -0
- package/dist/commands/init.js +817 -0
- package/dist/commands/local.js +380 -0
- package/dist/commands/remove.js +95 -0
- package/dist/commands/test.js +293 -0
- package/dist/protocols/ethereum/scaffold/manifest.js +6 -1
- package/dist/scaffold/ethereum.test.js +2 -0
- package/dist/scaffold/index.js +1 -0
- package/package.json +3 -10
- package/dist/index.js +0 -5
- package/oclif.manifest.json +0 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.38.0
|
|
3
|
+
## 0.38.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- [#1049](https://github.com/graphprotocol/graph-tooling/pull/1049)
|
|
8
|
+
[`18cf83f`](https://github.com/graphprotocol/graph-tooling/commit/18cf83fe1ec703fdc74fa03f898e2ca8b7e5f1fd)
|
|
9
|
+
Thanks [@incrypto32](https://github.com/incrypto32)! - Add startBlock prompt
|
|
10
|
+
|
|
7
11
|
- [#1053](https://github.com/graphprotocol/graph-tooling/pull/1053)
|
|
8
12
|
[`bc82507`](https://github.com/graphprotocol/graph-tooling/commit/bc8250763799ae2871c5d5b67c279c673329bcbc)
|
|
9
13
|
Thanks [@saihaj](https://github.com/saihaj)! - Remove arbitrum-rinkeby to add arbitrum-goerli
|
package/dist/bin.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const handle_1 = __importDefault(require("@oclif/core/handle"));
|
|
34
|
-
oclif.run().then(flush_1.default).catch(handle_1.default);
|
|
4
|
+
// run the CLI with the current process arguments
|
|
5
|
+
const cli_1 = require("./cli");
|
|
6
|
+
(0, cli_1.run)(process.argv);
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.run = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const gluegun_1 = require("gluegun");
|
|
9
|
+
const run = async (argv) => {
|
|
10
|
+
let builder = (0, gluegun_1.build)().brand('graph').src(__dirname);
|
|
11
|
+
const pluginDirs = [];
|
|
12
|
+
await Promise.all(['npm root -g', 'npm root', 'yarn global dir'].map(async (cmd) => {
|
|
13
|
+
try {
|
|
14
|
+
const dir = await gluegun_1.system.run(cmd, { trim: true });
|
|
15
|
+
pluginDirs.push(dir);
|
|
16
|
+
}
|
|
17
|
+
catch (_) {
|
|
18
|
+
// noop
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
// Inject potential plugin directories
|
|
22
|
+
builder = pluginDirs.reduce((cli, dir) => cli.plugin(path_1.default.join(dir, '@graphprotocol', 'indexer-cli', 'dist')), builder);
|
|
23
|
+
const cli = builder.help().version().defaultCommand().create();
|
|
24
|
+
return await cli.run(argv);
|
|
25
|
+
};
|
|
26
|
+
exports.run = run;
|
|
@@ -24,7 +24,7 @@ const generateDataSource = async (protocol, contractName, network, contractAddre
|
|
|
24
24
|
}))).asMutable();
|
|
25
25
|
};
|
|
26
26
|
exports.generateDataSource = generateDataSource;
|
|
27
|
-
const generateScaffold = async ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName = 'Contract', node, }, spinner) => {
|
|
27
|
+
const generateScaffold = async ({ protocolInstance, abi, contract, network, subgraphName, indexEvents, contractName = 'Contract', startBlock, node, }, spinner) => {
|
|
28
28
|
(0, spinner_1.step)(spinner, 'Generate subgraph');
|
|
29
29
|
const scaffold = new scaffold_1.default({
|
|
30
30
|
protocol: protocolInstance,
|
|
@@ -33,6 +33,7 @@ const generateScaffold = async ({ protocolInstance, abi, contract, network, subg
|
|
|
33
33
|
contract,
|
|
34
34
|
network,
|
|
35
35
|
contractName,
|
|
36
|
+
startBlock,
|
|
36
37
|
subgraphName,
|
|
37
38
|
node,
|
|
38
39
|
});
|
package/dist/commands/add.js
CHANGED
|
@@ -1,29 +1,187 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const immutable_1 = __importDefault(require("immutable"));
|
|
31
|
+
const abi_1 = require("../command-helpers/abi");
|
|
32
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
33
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
34
|
+
const network_1 = require("../command-helpers/network");
|
|
35
|
+
const scaffold_1 = require("../command-helpers/scaffold");
|
|
36
|
+
const spinner_1 = require("../command-helpers/spinner");
|
|
37
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
38
|
+
const abi_2 = __importDefault(require("../protocols/ethereum/abi"));
|
|
39
|
+
const subgraph_1 = __importDefault(require("../subgraph"));
|
|
40
|
+
const HELP = `
|
|
41
|
+
${chalk_1.default.bold('graph add')} <address> [<subgraph-manifest default: "./subgraph.yaml">]
|
|
42
|
+
|
|
43
|
+
${chalk_1.default.dim('Options:')}
|
|
44
|
+
|
|
45
|
+
--abi <path> Path to the contract ABI (default: download from Etherscan)
|
|
46
|
+
--contract-name Name of the contract (default: Contract)
|
|
47
|
+
--merge-entities Whether to merge entities with the same name (default: false)
|
|
48
|
+
--network-file <path> Networks config file path (default: "./networks.json")
|
|
49
|
+
-h, --help Show usage information
|
|
50
|
+
`;
|
|
51
|
+
exports.default = {
|
|
52
|
+
description: 'Adds a new datasource to a subgraph',
|
|
53
|
+
run: async (toolbox) => {
|
|
54
|
+
// Obtain tools
|
|
55
|
+
const { print, system } = toolbox;
|
|
56
|
+
// Read CLI parameters
|
|
57
|
+
let { abi, contractName, h, help, mergeEntities, networkFile } = toolbox.parameters.options;
|
|
58
|
+
contractName || (contractName = 'Contract');
|
|
59
|
+
try {
|
|
60
|
+
(0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
61
|
+
h,
|
|
62
|
+
help,
|
|
63
|
+
mergeEntities,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
print.error(e.message);
|
|
68
|
+
process.exitCode = 1;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const address = toolbox.parameters.first || toolbox.parameters.array?.[0];
|
|
72
|
+
const manifestPath = toolbox.parameters.second || toolbox.parameters.array?.[1] || './subgraph.yaml';
|
|
73
|
+
// Show help text if requested
|
|
74
|
+
if (help || h) {
|
|
75
|
+
print.info(HELP);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Validate the address
|
|
79
|
+
if (!address) {
|
|
80
|
+
print.error('No contract address provided');
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifestPath);
|
|
85
|
+
const protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
86
|
+
const manifest = await subgraph_1.default.load(manifestPath, { protocol });
|
|
87
|
+
const network = manifest.result.getIn(['dataSources', 0, 'network']);
|
|
88
|
+
const result = manifest.result.asMutable();
|
|
89
|
+
const entities = getEntities(manifest);
|
|
90
|
+
const contractNames = getContractNames(manifest);
|
|
91
|
+
if (contractNames.includes(contractName)) {
|
|
92
|
+
print.error(`Datasource or template with name ${contractName} already exists, please choose a different name`);
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let ethabi = null;
|
|
97
|
+
if (abi) {
|
|
98
|
+
ethabi = abi_2.default.load(contractName, abi);
|
|
99
|
+
}
|
|
100
|
+
else if (network === 'poa-core') {
|
|
101
|
+
ethabi = await (0, abi_1.loadAbiFromBlockScout)(abi_2.default, network, address);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
ethabi = await (0, abi_1.loadAbiFromEtherscan)(abi_2.default, network, address);
|
|
105
|
+
}
|
|
106
|
+
const { collisionEntities, onlyCollisions, abiData } = updateEventNamesOnCollision(toolbox, ethabi, entities, contractName, mergeEntities);
|
|
107
|
+
ethabi.data = abiData;
|
|
108
|
+
await (0, scaffold_1.writeABI)(ethabi, contractName);
|
|
109
|
+
await (0, scaffold_1.writeSchema)(ethabi, protocol, result.getIn(['schema', 'file']), collisionEntities);
|
|
110
|
+
await (0, scaffold_1.writeMapping)(ethabi, protocol, contractName, collisionEntities);
|
|
111
|
+
await (0, scaffold_1.writeTestsFiles)(ethabi, protocol, contractName);
|
|
112
|
+
const dataSources = result.get('dataSources');
|
|
113
|
+
const dataSource = await (0, scaffold_1.generateDataSource)(protocol, contractName, network, address, ethabi);
|
|
114
|
+
// Handle the collisions edge case by copying another data source yaml data
|
|
115
|
+
if (mergeEntities && onlyCollisions) {
|
|
116
|
+
const firstDataSource = dataSources.get(0);
|
|
117
|
+
const source = dataSource.get('source');
|
|
118
|
+
const mapping = firstDataSource.get('mapping').asMutable();
|
|
119
|
+
// Save the address of the new data source
|
|
120
|
+
source.abi = firstDataSource.get('source').get('abi');
|
|
121
|
+
dataSource.set('mapping', mapping);
|
|
122
|
+
dataSource.set('source', source);
|
|
123
|
+
}
|
|
124
|
+
result.set('dataSources', dataSources.push(dataSource));
|
|
125
|
+
await subgraph_1.default.write(result, manifestPath);
|
|
126
|
+
// Update networks.json
|
|
127
|
+
const networksFile = networkFile || './networks.json';
|
|
128
|
+
await (0, network_1.updateNetworksFile)(toolbox, network, contractName, address, networksFile);
|
|
129
|
+
// Detect Yarn and/or NPM
|
|
130
|
+
const yarn = system.which('yarn');
|
|
131
|
+
const npm = system.which('npm');
|
|
132
|
+
if (!yarn && !npm) {
|
|
133
|
+
print.error(`Neither Yarn nor NPM were found on your system. Please install one of them.`);
|
|
134
|
+
process.exitCode = 1;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', async () => {
|
|
138
|
+
await system.run(yarn ? 'yarn codegen' : 'npm run codegen');
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
const getEntities = (manifest) => {
|
|
143
|
+
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
144
|
+
const templates = manifest.result.get('templates', immutable_1.default.List());
|
|
145
|
+
return dataSources
|
|
146
|
+
.concat(templates)
|
|
147
|
+
.map((dataSource) => dataSource.getIn(['mapping', 'entities']))
|
|
148
|
+
.flatten();
|
|
149
|
+
};
|
|
150
|
+
const getContractNames = (manifest) => {
|
|
151
|
+
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
152
|
+
const templates = manifest.result.get('templates', immutable_1.default.List());
|
|
153
|
+
return dataSources.concat(templates).map((dataSource) => dataSource.get('name'));
|
|
154
|
+
};
|
|
155
|
+
const updateEventNamesOnCollision = (toolbox, ethabi, entities, contractName, mergeEntities) => {
|
|
156
|
+
let abiData = ethabi.data;
|
|
157
|
+
const { print } = toolbox;
|
|
158
|
+
const collisionEntities = [];
|
|
159
|
+
let onlyCollisions = true;
|
|
160
|
+
for (let i = 0; i < abiData.size; i++) {
|
|
161
|
+
const dataRow = abiData.get(i).asMutable();
|
|
162
|
+
if (dataRow.get('type') === 'event') {
|
|
163
|
+
if (entities.includes(dataRow.get('name'))) {
|
|
164
|
+
if (entities.includes(`${contractName}${dataRow.get('name')}`)) {
|
|
165
|
+
print.error(`Contract name ('${contractName}')
|
|
166
|
+
+ event name ('${dataRow.get('name')}') entity already exists.`);
|
|
167
|
+
process.exitCode = 1;
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
if (mergeEntities) {
|
|
171
|
+
collisionEntities.push(dataRow.get('name'));
|
|
172
|
+
abiData = abiData.asImmutable().delete(i); // needs to be immutable when deleting, yes you read that right - https://github.com/immutable-js/immutable-js/issues/1901
|
|
173
|
+
i--; // deletion also shifts values to the left
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
dataRow.set('name', `${contractName}${dataRow.get('name')}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
onlyCollisions = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
abiData = abiData.asMutable().set(i, dataRow);
|
|
8
185
|
}
|
|
9
|
-
}
|
|
10
|
-
exports.default = Add;
|
|
11
|
-
Add.description = 'Adds a new datasource to a subgraph.';
|
|
12
|
-
Add.flags = {
|
|
13
|
-
abi: core_1.Flags.string({
|
|
14
|
-
summary: 'Path to the contract ABI.',
|
|
15
|
-
default: '*Download from Etherscan*',
|
|
16
|
-
}),
|
|
17
|
-
contractName: core_1.Flags.string({
|
|
18
|
-
summary: 'Name of the contract.',
|
|
19
|
-
default: 'Contract',
|
|
20
|
-
}),
|
|
21
|
-
mergeEntities: core_1.Flags.boolean({
|
|
22
|
-
summary: 'Whether to merge entities with the same name.',
|
|
23
|
-
default: false,
|
|
24
|
-
}),
|
|
25
|
-
networkFile: core_1.Flags.string({
|
|
26
|
-
summary: 'Networks config file path.',
|
|
27
|
-
default: 'networks.json',
|
|
28
|
-
}),
|
|
186
|
+
return { abiData, collisionEntities, onlyCollisions };
|
|
29
187
|
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const auth_1 = require("../command-helpers/auth");
|
|
8
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
9
|
+
const node_1 = require("../command-helpers/node");
|
|
10
|
+
const HELP = `
|
|
11
|
+
${chalk_1.default.bold('graph auth')} [options] ${chalk_1.default.bold('<node>')} ${chalk_1.default.bold('<deploy-key>')}
|
|
12
|
+
|
|
13
|
+
${chalk_1.default.dim('Options:')}
|
|
14
|
+
|
|
15
|
+
--product <subgraph-studio|hosted-service>
|
|
16
|
+
Selects the product for which to authenticate
|
|
17
|
+
--studio Shortcut for --product subgraph-studio
|
|
18
|
+
-h, --help Show usage information
|
|
19
|
+
`;
|
|
20
|
+
const processForm = async (toolbox, { product, studio, node, deployKey }) => {
|
|
21
|
+
const questions = [
|
|
22
|
+
{
|
|
23
|
+
type: 'select',
|
|
24
|
+
name: 'product',
|
|
25
|
+
message: 'Product for which to initialize',
|
|
26
|
+
choices: ['subgraph-studio', 'hosted-service'],
|
|
27
|
+
skip: product === 'subgraph-studio' ||
|
|
28
|
+
product === 'hosted-service' ||
|
|
29
|
+
studio !== undefined ||
|
|
30
|
+
node !== undefined,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: 'password',
|
|
34
|
+
name: 'deployKey',
|
|
35
|
+
message: 'Deploy key',
|
|
36
|
+
skip: deployKey !== undefined,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
try {
|
|
40
|
+
const answers = await toolbox.prompt.ask(questions);
|
|
41
|
+
return answers;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.default = {
|
|
48
|
+
description: 'Sets the deploy key to use when deploying to a Graph node',
|
|
49
|
+
run: async (toolbox) => {
|
|
50
|
+
// Obtain tools
|
|
51
|
+
const { print } = toolbox;
|
|
52
|
+
// Read CLI parameters
|
|
53
|
+
const { product, studio, h, help } = toolbox.parameters.options;
|
|
54
|
+
// Show help text if requested
|
|
55
|
+
if (help || h) {
|
|
56
|
+
print.info(HELP);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
let firstParam, secondParam;
|
|
60
|
+
try {
|
|
61
|
+
[firstParam, secondParam] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
62
|
+
h,
|
|
63
|
+
help,
|
|
64
|
+
studio,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
print.error(e.message);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// if user specifies --product or --studio then deployKey is the first parameter
|
|
73
|
+
let node;
|
|
74
|
+
let deployKey;
|
|
75
|
+
if (product || studio) {
|
|
76
|
+
({ node } = (0, node_1.chooseNodeUrl)({ product, studio, node }));
|
|
77
|
+
deployKey = firstParam;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
node = firstParam;
|
|
81
|
+
deployKey = secondParam;
|
|
82
|
+
}
|
|
83
|
+
if (!node || !deployKey) {
|
|
84
|
+
const inputs = await processForm(toolbox, {
|
|
85
|
+
product,
|
|
86
|
+
studio,
|
|
87
|
+
node,
|
|
88
|
+
deployKey,
|
|
89
|
+
});
|
|
90
|
+
if (inputs === undefined) {
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
if (!node) {
|
|
94
|
+
({ node } = (0, node_1.chooseNodeUrl)({
|
|
95
|
+
product: inputs.product,
|
|
96
|
+
studio,
|
|
97
|
+
node,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
deployKey || (deployKey = inputs.deployKey);
|
|
101
|
+
}
|
|
102
|
+
if (!deployKey) {
|
|
103
|
+
print.error(`No deploy key provided`);
|
|
104
|
+
print.info(HELP);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (deployKey.length > 200) {
|
|
109
|
+
print.error(`Deploy key must not exceed 200 characters`);
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
await (0, auth_1.saveDeployKey)(node, deployKey);
|
|
115
|
+
print.success(`Deploy key set for ${node}`);
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
print.error(e);
|
|
119
|
+
process.exitCode = 1;
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
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 compiler_1 = require("../command-helpers/compiler");
|
|
31
|
+
const DataSourcesExtractor = __importStar(require("../command-helpers/data-sources"));
|
|
32
|
+
const gluegun_1 = require("../command-helpers/gluegun");
|
|
33
|
+
const network_1 = require("../command-helpers/network");
|
|
34
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
35
|
+
const protocols_1 = __importDefault(require("../protocols"));
|
|
36
|
+
const buildDebug = (0, debug_1.default)('graph-cli:build');
|
|
37
|
+
const HELP = `
|
|
38
|
+
${chalk_1.default.bold('graph build')} [options] ${chalk_1.default.bold('[<subgraph-manifest>]')}
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
|
|
42
|
+
-h, --help Show usage information
|
|
43
|
+
-i, --ipfs <node> Upload build results to an IPFS node
|
|
44
|
+
-o, --output-dir <path> Output directory for build results (default: build/)
|
|
45
|
+
-t, --output-format <format> Output format for mappings (wasm, wast) (default: wasm)
|
|
46
|
+
--skip-migrations Skip subgraph migrations (default: false)
|
|
47
|
+
-w, --watch Regenerate types when subgraph files change (default: false)
|
|
48
|
+
--network <name> Network configuration to use from the networks config file
|
|
49
|
+
--network-file <path> Networks config file path (default: "./networks.json")
|
|
50
|
+
`;
|
|
51
|
+
exports.default = {
|
|
52
|
+
description: 'Builds a subgraph and (optionally) uploads it to IPFS',
|
|
53
|
+
run: async (toolbox) => {
|
|
54
|
+
// Obtain tools
|
|
55
|
+
const { filesystem, print } = toolbox;
|
|
56
|
+
// Parse CLI parameters
|
|
57
|
+
let { i, h, help, ipfs, o, outputDir, outputFormat, skipMigrations, t, w, watch, network, networkFile, } = toolbox.parameters.options;
|
|
58
|
+
// Support both short and long option variants
|
|
59
|
+
help || (help = h);
|
|
60
|
+
ipfs || (ipfs = i);
|
|
61
|
+
outputDir || (outputDir = o);
|
|
62
|
+
outputFormat || (outputFormat = t);
|
|
63
|
+
watch || (watch = w);
|
|
64
|
+
let manifest;
|
|
65
|
+
try {
|
|
66
|
+
[manifest] = (0, gluegun_1.fixParameters)(toolbox.parameters, {
|
|
67
|
+
h,
|
|
68
|
+
help,
|
|
69
|
+
w,
|
|
70
|
+
watch,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
print.error(e.message);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Fall back to default values for options / parameters
|
|
79
|
+
outputFormat = outputFormat && ['wasm', 'wast'].includes(outputFormat) ? outputFormat : 'wasm';
|
|
80
|
+
outputDir = outputDir && outputDir !== '' ? outputDir : filesystem.path('build');
|
|
81
|
+
manifest =
|
|
82
|
+
manifest !== undefined && manifest !== '' ? manifest : filesystem.resolve('subgraph.yaml');
|
|
83
|
+
networkFile =
|
|
84
|
+
networkFile !== undefined && networkFile !== ''
|
|
85
|
+
? networkFile
|
|
86
|
+
: filesystem.resolve('networks.json');
|
|
87
|
+
// Show help text if requested
|
|
88
|
+
if (help) {
|
|
89
|
+
print.info(HELP);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let protocol;
|
|
93
|
+
try {
|
|
94
|
+
const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest);
|
|
95
|
+
protocol = protocols_1.default.fromDataSources(dataSourcesAndTemplates);
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
print.error(e.message);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
buildDebug('Detected protocol "%s" (%o)', protocol.name, protocol);
|
|
103
|
+
if (network && filesystem.exists(networkFile) !== 'file') {
|
|
104
|
+
print.error(`Network file '${networkFile}' does not exists or is not a file!`);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (network) {
|
|
109
|
+
const identifierName = protocol.getContract().identifierName();
|
|
110
|
+
await (0, network_1.updateSubgraphNetwork)(toolbox, manifest, network, networkFile, identifierName);
|
|
111
|
+
}
|
|
112
|
+
const compiler = (0, compiler_1.createCompiler)(manifest, {
|
|
113
|
+
ipfs,
|
|
114
|
+
outputDir,
|
|
115
|
+
outputFormat,
|
|
116
|
+
skipMigrations,
|
|
117
|
+
protocol,
|
|
118
|
+
});
|
|
119
|
+
// Exit with an error code if the compiler couldn't be created
|
|
120
|
+
if (!compiler) {
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// Watch subgraph files for changes or additions, trigger
|
|
125
|
+
// compile (if watch argument specified)
|
|
126
|
+
if (watch) {
|
|
127
|
+
await compiler.watchAndCompile();
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const result = await compiler.compile();
|
|
131
|
+
if (result === false) {
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|