@graphprotocol/graph-cli 0.22.4 → 0.23.2

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.
Files changed (60) hide show
  1. package/README.md +83 -0
  2. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/.travis.yml +4 -0
  3. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/ethereum.ts +10 -16
  4. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/chain/near.ts +402 -0
  5. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/collections.ts +125 -4
  6. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/eager_offset.ts +2 -1
  7. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/json.ts +14 -0
  8. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/numbers.ts +58 -16
  9. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/common/value.ts +2 -5
  10. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/global/global.ts +108 -0
  11. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/helper-functions.ts +5 -5
  12. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/index.ts +6 -15
  13. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/package.json +5 -2
  14. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bigInt.ts +138 -108
  15. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/bytes.ts +31 -20
  16. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/test/test.js +120 -88
  17. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/tsconfig.json +2 -2
  18. package/examples/basic-event-handlers/node_modules/@graphprotocol/graph-ts/types/tsconfig.base.json +3 -0
  19. package/examples/basic-event-handlers/package.json +1 -1
  20. package/examples/basic-event-handlers/yarn.lock +4 -4
  21. package/examples/example-subgraph/package.json +1 -1
  22. package/examples/example-subgraph/yarn.lock +4 -4
  23. package/jest.config.js +2 -2
  24. package/manifest-schema.graphql +35 -2
  25. package/package.json +2 -6
  26. package/src/codegen/schema.js +1 -2
  27. package/src/codegen/template.js +9 -51
  28. package/src/codegen/typescript.js +7 -0
  29. package/src/command-helpers/compiler.js +6 -2
  30. package/src/command-helpers/data-sources.js +38 -0
  31. package/src/command-helpers/fs.js +8 -0
  32. package/src/commands/build.js +14 -0
  33. package/src/commands/codegen.js +8 -0
  34. package/src/commands/deploy.js +11 -8
  35. package/src/commands/init.js +36 -11
  36. package/src/commands/test.js +37 -27
  37. package/src/compiler/index.js +90 -73
  38. package/src/{abi.js → protocols/ethereum/abi.js} +0 -0
  39. package/src/{codegen → protocols/ethereum/codegen}/abi.js +9 -6
  40. package/src/{codegen → protocols/ethereum/codegen}/abi.test.js +1 -1
  41. package/src/protocols/ethereum/codegen/template.js +42 -0
  42. package/src/protocols/ethereum/subgraph.js +205 -0
  43. package/src/protocols/ethereum/type-generator.js +203 -0
  44. package/src/protocols/index.js +97 -0
  45. package/src/protocols/near/subgraph.js +42 -0
  46. package/src/scaffold.js +21 -4
  47. package/src/scaffold.test.js +1 -1
  48. package/src/subgraph.js +30 -252
  49. package/src/type-generator.js +31 -211
  50. package/src/validation/index.js +1 -0
  51. package/src/validation/manifest.js +73 -23
  52. package/src/validation/schema.js +6 -0
  53. package/tests/cli/globalSetup.js +6 -0
  54. package/tests/cli/globalTeardown.js +6 -0
  55. package/tests/cli/init.test.js +1 -1
  56. package/tests/cli/util.js +17 -8
  57. package/tests/cli/validation/near-is-valid/mapping.ts +0 -0
  58. package/tests/cli/validation/near-is-valid/schema.graphql +8 -0
  59. package/tests/cli/validation/near-is-valid/subgraph.yaml +21 -0
  60. package/tests/cli/validation.test.js +8 -0
@@ -6,7 +6,10 @@ type Schema {
6
6
  file: File!
7
7
  }
8
8
 
9
- union DataSource = EthereumContractDataSource
9
+ union DataSource =
10
+ EthereumContractDataSource |
11
+ NearContractDataSource
12
+
10
13
  union DataSourceTemplate = EthereumContractDataSourceTemplate
11
14
 
12
15
  type EthereumContractDataSource {
@@ -17,14 +20,27 @@ type EthereumContractDataSource {
17
20
  mapping: EthereumContractMapping!
18
21
  }
19
22
 
23
+ type NearContractDataSource {
24
+ kind: String!
25
+ name: String!
26
+ network: String
27
+ source: NearContractSource!
28
+ mapping: NearContractMapping!
29
+ }
30
+
20
31
  type EthereumContractSource {
21
32
  address: String
22
33
  abi: String!
23
34
  startBlock: BigInt
24
35
  }
25
36
 
37
+ type NearContractSource {
38
+ account: String
39
+ startBlock: BigInt
40
+ }
41
+
26
42
  type EthereumContractMapping {
27
- kind: String!
43
+ kind: String
28
44
  apiVersion: String!
29
45
  language: String!
30
46
  file: File!
@@ -35,6 +51,15 @@ type EthereumContractMapping {
35
51
  eventHandlers: [EthereumContractEventHandler!]
36
52
  }
37
53
 
54
+ type NearContractMapping {
55
+ apiVersion: String!
56
+ language: String!
57
+ file: File!
58
+ entities: [String!]!
59
+ blockHandlers: [NearBlockHandler!]
60
+ receiptHandlers: [NearReceiptHandler!]
61
+ }
62
+
38
63
  type EthereumContractAbi {
39
64
  name: String!
40
65
  file: File!
@@ -49,11 +74,19 @@ type EthereumBlockFilter {
49
74
  kind: String!
50
75
  }
51
76
 
77
+ type NearBlockHandler {
78
+ handler: String!
79
+ }
80
+
52
81
  type EthereumCallHandler {
53
82
  function: String!
54
83
  handler: String!
55
84
  }
56
85
 
86
+ type NearReceiptHandler {
87
+ handler: String!
88
+ }
89
+
57
90
  type EthereumContractEventHandler {
58
91
  event: String!
59
92
  topic0: String
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.22.4",
3
+ "version": "0.23.2",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "dependencies": {
6
6
  "assemblyscript": "0.19.10",
@@ -40,10 +40,6 @@
40
40
  "scripts": {
41
41
  "test": "jest --verbose",
42
42
  "test:init": "jest tests/cli/init.test.js --verbose",
43
- "test:validation": "jest tests/cli/validation.test.js --verbose",
44
- "release:patch": "npm version patch && npm publish && git push origin master && git push --tags",
45
- "release:minor": "npm version minor && npm publish && git push origin master && git push --tags",
46
- "release:alpha:minor": "npm version preminor --preid alpha && npm publish --tag alpha && git push origin master && git push --tags",
47
- "release:alpha:prerelease": "npm version prerelease --preid alpha && npm publish --tag alpha && git push origin master && git push --tags"
43
+ "test:validation": "jest tests/cli/validation.test.js --verbose"
48
44
  }
49
45
  }
@@ -23,8 +23,7 @@ module.exports = class SchemaCodeGenerator {
23
23
  // APIs
24
24
  'store',
25
25
 
26
- // Basic Ethereum types
27
- 'Address',
26
+ // Basic Scalar types
28
27
  'Bytes',
29
28
  'BigInt',
30
29
  'BigDecimal',
@@ -3,14 +3,19 @@ const immutable = require('immutable')
3
3
  const tsCodegen = require('./typescript')
4
4
 
5
5
  module.exports = class DataSourceTemplateCodeGenerator {
6
- constructor(template) {
6
+ constructor(template, protocol) {
7
7
  this.template = template
8
+ this.protocolTemplateCodeGen = protocol.getTemplateCodeGen(template)
8
9
  }
9
10
 
10
11
  generateModuleImports() {
11
12
  return [
12
13
  tsCodegen.moduleImports(
13
- ['Address', 'DataSourceTemplate', 'DataSourceContext'],
14
+ [
15
+ ...this.protocolTemplateCodeGen.generateModuleImports(),
16
+ 'DataSourceTemplate',
17
+ 'DataSourceContext',
18
+ ],
14
19
  '@graphprotocol/graph-ts',
15
20
  ),
16
21
  ]
@@ -24,55 +29,8 @@ module.exports = class DataSourceTemplateCodeGenerator {
24
29
  let name = this.template.get('name')
25
30
 
26
31
  let klass = tsCodegen.klass(name, { export: true, extends: 'DataSourceTemplate' })
27
- klass.addMethod(this._generateCreateMethod())
28
- klass.addMethod(this._generateCreateWithContextMethod())
32
+ klass.addMethod(this.protocolTemplateCodeGen.generateCreateMethod())
33
+ klass.addMethod(this.protocolTemplateCodeGen.generateCreateWithContextMethod())
29
34
  return klass
30
35
  }
31
-
32
- _generateCreateMethod() {
33
- let name = this.template.get('name')
34
- let kind = this.template.get('kind')
35
-
36
- switch (kind) {
37
- case 'ethereum/contract':
38
- return tsCodegen.staticMethod(
39
- 'create',
40
- [tsCodegen.param('address', tsCodegen.namedType('Address'))],
41
- tsCodegen.namedType('void'),
42
- `
43
- DataSourceTemplate.create('${name}', [address.toHex()])
44
- `,
45
- )
46
-
47
- default:
48
- throw new Error(
49
- `Data sources with kind != 'ethereum/contract' are not supported yet`,
50
- )
51
- }
52
- }
53
-
54
- _generateCreateWithContextMethod() {
55
- let name = this.template.get('name')
56
- let kind = this.template.get('kind')
57
-
58
- switch (kind) {
59
- case 'ethereum/contract':
60
- return tsCodegen.staticMethod(
61
- 'createWithContext',
62
- [
63
- tsCodegen.param('address', tsCodegen.namedType('Address')),
64
- tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')),
65
- ],
66
- tsCodegen.namedType('void'),
67
- `
68
- DataSourceTemplate.createWithContext('${name}', [address.toHex()], context)
69
- `,
70
- )
71
-
72
- default:
73
- throw new Error(
74
- `Data sources with kind != 'ethereum/contract' are not supported yet`,
75
- )
76
- }
77
- }
78
36
  }
@@ -179,6 +179,10 @@ const klassMember = (name, type) => new ClassMember(name, type)
179
179
  const nullableType = type => new NullableType(type)
180
180
  const moduleImports = (nameOrNames, module) => new ModuleImports(nameOrNames, module)
181
181
 
182
+ const GENERATED_FILE_NOTE = `
183
+ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
184
+ `
185
+
182
186
  module.exports = {
183
187
  // Types
184
188
  NullableType,
@@ -194,4 +198,7 @@ module.exports = {
194
198
  param,
195
199
  nullableType,
196
200
  moduleImports,
201
+
202
+ // Utilities
203
+ GENERATED_FILE_NOTE,
197
204
  }
@@ -4,7 +4,10 @@ const toolbox = require('gluegun/toolbox')
4
4
  const Compiler = require('../compiler')
5
5
 
6
6
  // Helper function to construct a subgraph compiler
7
- const createCompiler = (manifest, { ipfs, outputDir, outputFormat, skipMigrations, blockIpfsMethods }) => {
7
+ const createCompiler = (
8
+ manifest,
9
+ { ipfs, outputDir, outputFormat, skipMigrations, blockIpfsMethods, protocol }
10
+ ) => {
8
11
  // Parse the IPFS URL
9
12
  let url
10
13
  try {
@@ -31,7 +34,8 @@ The IPFS URL must be of the following format: http(s)://host[:port]/[path]`)
31
34
  outputDir: outputDir,
32
35
  outputFormat: outputFormat,
33
36
  skipMigrations,
34
- blockIpfsMethods
37
+ blockIpfsMethods,
38
+ protocol,
35
39
  })
36
40
  }
37
41
 
@@ -0,0 +1,38 @@
1
+ const immutable = require('immutable')
2
+ const { loadManifest } = require('../migrations/util/load-manifest')
3
+
4
+ // Loads manifest from file path and returns all:
5
+ // - data sources
6
+ // - templates
7
+ // In a single list.
8
+ const fromFilePath = async manifestPath => {
9
+ const { dataSources = [], templates = [] } = await loadManifest(manifestPath)
10
+
11
+ return dataSources.concat(templates)
12
+ }
13
+
14
+ const extractDataSourceByType = (manifest, dataSourceType, protocol) =>
15
+ manifest
16
+ .get(dataSourceType, immutable.List())
17
+ .reduce(
18
+ (dataSources, dataSource, dataSourceIndex) =>
19
+ protocol.isValidKindName(dataSource.get('kind'))
20
+ ? dataSources.push(
21
+ immutable.Map({ path: [dataSourceType, dataSourceIndex], dataSource }),
22
+ )
23
+ : dataSources,
24
+ immutable.List(),
25
+ )
26
+
27
+ // Extracts data sources and templates from a immutable manifest data structure
28
+ const fromManifest = (manifest, protocol) => {
29
+ const dataSources = extractDataSourceByType(manifest, 'dataSources', protocol)
30
+ const templates = extractDataSourceByType(manifest, 'templates', protocol)
31
+
32
+ return dataSources.concat(templates)
33
+ }
34
+
35
+ module.exports = {
36
+ fromFilePath,
37
+ fromManifest,
38
+ }
@@ -0,0 +1,8 @@
1
+ const path = require('path')
2
+
3
+ const displayPath = p =>
4
+ path.relative(process.cwd(), p)
5
+
6
+ module.exports = {
7
+ displayPath,
8
+ }
@@ -2,6 +2,8 @@ const chalk = require('chalk')
2
2
 
3
3
  const { createCompiler } = require('../command-helpers/compiler')
4
4
  const { fixParameters } = require('../command-helpers/gluegun')
5
+ const DataSourcesExtractor = require('../command-helpers/data-sources')
6
+ const Protocol = require('../protocols')
5
7
 
6
8
  const HELP = `
7
9
  ${chalk.bold('graph build')} [options] ${chalk.bold('[<subgraph-manifest>]')}
@@ -73,11 +75,23 @@ module.exports = {
73
75
  return
74
76
  }
75
77
 
78
+ let protocol
79
+ try {
80
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
81
+
82
+ protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
83
+ } catch (e) {
84
+ print.error(e.message)
85
+ process.exitCode = 1
86
+ return
87
+ }
88
+
76
89
  let compiler = createCompiler(manifest, {
77
90
  ipfs,
78
91
  outputDir,
79
92
  outputFormat,
80
93
  skipMigrations,
94
+ protocol,
81
95
  })
82
96
 
83
97
  // Exit with an error code if the compiler couldn't be created
@@ -2,7 +2,9 @@ const chalk = require('chalk')
2
2
  const path = require('path')
3
3
 
4
4
  const TypeGenerator = require('../type-generator')
5
+ const Protocol = require('../protocols')
5
6
  const { fixParameters } = require('../command-helpers/gluegun')
7
+ const DataSourcesExtractor = require('../command-helpers/data-sources')
6
8
  const { assertManifestApiVersion, assertGraphTsVersion } = require('../command-helpers/version')
7
9
 
8
10
  const HELP = `
@@ -60,6 +62,7 @@ module.exports = {
60
62
  return
61
63
  }
62
64
 
65
+ let protocol
63
66
  try {
64
67
  // Checks to make sure codegen doesn't run against
65
68
  // older subgraphs (both apiVersion and graph-ts version).
@@ -69,6 +72,10 @@ module.exports = {
69
72
  // the wrong AssemblyScript version.
70
73
  await assertManifestApiVersion(manifest, '0.0.5')
71
74
  await assertGraphTsVersion(path.dirname(manifest), '0.22.0')
75
+
76
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
77
+
78
+ protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
72
79
  } catch (e) {
73
80
  print.error(e.message)
74
81
  process.exitCode = 1
@@ -79,6 +86,7 @@ module.exports = {
79
86
  subgraphManifest: manifest,
80
87
  outputDir: outputDir,
81
88
  skipMigrations,
89
+ protocol,
82
90
  })
83
91
 
84
92
  // Watch working directory for file updates or additions, trigger
@@ -11,8 +11,9 @@ const { withSpinner } = require('../command-helpers/spinner')
11
11
  const { validateSubgraphName } = require('../command-helpers/subgraph')
12
12
  const { DEFAULT_IPFS_URL } = require('../command-helpers/ipfs')
13
13
  const { assertManifestApiVersion, assertGraphTsVersion } = require('../command-helpers/version')
14
+ const DataSourcesExtractor = require('../command-helpers/data-sources')
14
15
  const { validateStudioNetwork } = require('../command-helpers/studio')
15
- const { loadManifest } = require('../migrations/util/load-manifest')
16
+ const Protocol = require('../protocols')
16
17
 
17
18
  const HELP = `
18
19
  ${chalk.bold('graph deploy')} [options] ${chalk.bold('<subgraph-name>')} ${chalk.bold(
@@ -128,13 +129,9 @@ module.exports = {
128
129
  : filesystem.resolve('subgraph.yaml')
129
130
 
130
131
  try {
131
- let manifestFile = await loadManifest(manifest)
132
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
132
133
 
133
- for (const { network } of manifestFile.dataSources || []) {
134
- validateStudioNetwork({ studio, product, network })
135
- }
136
-
137
- for (const { network } of manifestFile.templates || []) {
134
+ for (const { network } of dataSourcesAndTemplates) {
138
135
  validateStudioNetwork({ studio, product, network })
139
136
  }
140
137
  } catch (e) {
@@ -192,6 +189,7 @@ module.exports = {
192
189
  return
193
190
  }
194
191
 
192
+ let protocol
195
193
  try {
196
194
  // Checks to make sure deploy doesn't run against
197
195
  // older subgraphs (both apiVersion and graph-ts version).
@@ -201,6 +199,10 @@ module.exports = {
201
199
  // using the wrong AssemblyScript compiler.
202
200
  await assertManifestApiVersion(manifest, '0.0.5')
203
201
  await assertGraphTsVersion(path.dirname(manifest), '0.22.0')
202
+
203
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(manifest)
204
+
205
+ protocol = Protocol.fromDataSources(dataSourcesAndTemplates)
204
206
  } catch (e) {
205
207
  print.error(e.message)
206
208
  process.exitCode = 1
@@ -215,7 +217,8 @@ module.exports = {
215
217
  outputDir,
216
218
  outputFormat: 'wasm',
217
219
  skipMigrations,
218
- blockIpfsMethods: isStudio // Network does not support publishing subgraphs with IPFS methods
220
+ blockIpfsMethods: isStudio, // Network does not support publishing subgraphs with IPFS methods
221
+ protocol,
219
222
  })
220
223
 
221
224
  // Exit with an error code if the compiler couldn't be created
@@ -9,13 +9,14 @@ const {
9
9
  getSubgraphBasename,
10
10
  validateSubgraphName,
11
11
  } = require('../command-helpers/subgraph')
12
+ const DataSourcesExtractor = require('../command-helpers/data-sources')
12
13
  const { validateStudioNetwork } = require('../command-helpers/studio')
13
14
  const { withSpinner, step } = require('../command-helpers/spinner')
14
15
  const { fixParameters } = require('../command-helpers/gluegun')
15
16
  const { chooseNodeUrl } = require('../command-helpers/node')
16
- const { loadManifest } = require('../migrations/util/load-manifest')
17
17
  const { abiEvents, generateScaffold, writeScaffold } = require('../scaffold')
18
- const ABI = require('../abi')
18
+ // TODO: Use Protocol class to getABI
19
+ const ABI = require('../protocols/ethereum/abi')
19
20
 
20
21
  const networkChoices = [
21
22
  'mainnet',
@@ -256,16 +257,25 @@ const loadAbiFromBlockScout = async (network, address) =>
256
257
  },
257
258
  )
258
259
 
260
+ const getEtherscanLikeAPIUrl = (network) => {
261
+ switch(network){
262
+ case "mainnet": return `https://api.etherscan.io/api`;
263
+ case "bsc": return `https://api.bscscan.com/api`;
264
+ case "matic": return `https://api.polygonscan.com/api`;
265
+ case "mumbai": return `https://api-testnet.polygonscan.com/api`;
266
+ default: return `https://api-${network}.etherscan.io/api`;
267
+ }
268
+ }
269
+
259
270
  const loadAbiFromEtherscan = async (network, address) =>
260
271
  await withSpinner(
261
272
  `Fetching ABI from Etherscan`,
262
273
  `Failed to fetch ABI from Etherscan`,
263
274
  `Warnings while fetching ABI from Etherscan`,
264
275
  async spinner => {
276
+ const scanApiUrl = getEtherscanLikeAPIUrl(network);
265
277
  let result = await fetch(
266
- `https://${
267
- network === 'mainnet' ? 'api' : `api-${network}`
268
- }.etherscan.io/api?module=contract&action=getabi&address=${address}`,
278
+ `${scanApiUrl}?module=contract&action=getabi&address=${address}`,
269
279
  )
270
280
  let json = await result.json()
271
281
 
@@ -529,12 +539,26 @@ const initRepository = async (toolbox, directory) =>
529
539
  },
530
540
  )
531
541
 
542
+ // Only used for local testing / continuous integration.
543
+ //
544
+ // This requires that the command `npm link` is called
545
+ // on the root directory of this repository, as described here:
546
+ // https://docs.npmjs.com/cli/v7/commands/npm-link.
547
+ const npmLinkToLocalCli = async (toolbox, directory) => {
548
+ if (process.env.GRAPH_CLI_TESTS) {
549
+ await toolbox.system.run('npm link @graphprotocol/graph-cli', { cwd: directory })
550
+ }
551
+ }
552
+
532
553
  const installDependencies = async (toolbox, directory, installCommand) =>
533
554
  await withSpinner(
534
555
  `Install dependencies with ${toolbox.print.colors.muted(installCommand)}`,
535
556
  `Failed to install dependencies`,
536
557
  `Warnings while installing dependencies`,
537
558
  async spinner => {
559
+ // Links to local graph-cli if we're running the automated tests
560
+ await npmLinkToLocalCli(toolbox, directory)
561
+
538
562
  await toolbox.system.run(installCommand, { cwd: directory })
539
563
  return true
540
564
  },
@@ -613,13 +637,9 @@ const initSubgraphFromExample = async (
613
637
  try {
614
638
  // It doesn't matter if we changed the URL we clone the YAML,
615
639
  // we'll check it's network anyway. If it's a studio subgraph we're dealing with.
616
- let manifestFile = await loadManifest(path.join(directory, 'subgraph.yaml'))
640
+ const dataSourcesAndTemplates = await DataSourcesExtractor.fromFilePath(path.join(directory, 'subgraph.yaml'))
617
641
 
618
- for (const { network } of manifestFile.dataSources || []) {
619
- validateStudioNetwork({ studio, product, network })
620
- }
621
-
622
- for (const { network } of manifestFile.templates || []) {
642
+ for (const { network } of dataSourcesAndTemplates) {
623
643
  validateStudioNetwork({ studio, product, network })
624
644
  }
625
645
  } catch (e) {
@@ -646,6 +666,11 @@ const initSubgraphFromExample = async (
646
666
  delete pkgJson['license']
647
667
  delete pkgJson['repository']
648
668
 
669
+ // Remove example's cli in favor of the local one (added via `npm link`)
670
+ if (process.env.GRAPH_CLI_TESTS) {
671
+ delete pkgJson['devDependencies']['@graphprotocol/graph-cli']
672
+ }
673
+
649
674
  // Write package.json
650
675
  await filesystem.write(pkgJsonFilename, pkgJson, { jsonIndent: 2 })
651
676
  return true
@@ -11,6 +11,7 @@ ${chalk.dim('Options:')}
11
11
 
12
12
  -f --force Overwrite folder + file when downloading
13
13
  -h, --help Show usage information
14
+ -l, --logs Logs to the console information about the OS, CPU model and download url (debugging purposes)
14
15
  -v, --version <tag> Choose the version of the rust binary that you want to be downloaded/used
15
16
  `
16
17
 
@@ -21,12 +22,13 @@ module.exports = {
21
22
  let { print } = toolbox
22
23
 
23
24
  // Read CLI parameters
24
- let { f, force, h, help, v, version } = toolbox.parameters.options
25
+ let { f, force, h, help, l, logs, v, version } = toolbox.parameters.options
25
26
  let datasource = toolbox.parameters.first
26
27
 
27
28
  // Support both long and short option variants
28
29
  force = force || f
29
30
  help = help || h
31
+ logs = logs || l
30
32
  version = version || v
31
33
 
32
34
  // Show help text if requested
@@ -35,48 +37,56 @@ module.exports = {
35
37
  return
36
38
  }
37
39
 
38
- const platform = getPlatform();
40
+ const platform = getPlatform(logs)
39
41
  if (!version) {
40
- let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest');
41
- let json = await result.json();
42
- version = json.tag_name;
42
+ let result = await fetch('https://api.github.com/repos/LimeChain/matchstick/releases/latest')
43
+ let json = await result.json()
44
+ version = json.tag_name
43
45
  }
44
46
 
45
- const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}`;
47
+ const url = `https://github.com/LimeChain/matchstick/releases/download/${version}/${platform}`
46
48
 
47
- let binary = new Binary(platform, url, version);
48
- await binary.install(force);
49
- binary.run(datasource);
49
+ if (logs) {
50
+ console.log(`Download link: ${url}`)
51
+ }
52
+
53
+ let binary = new Binary(platform, url, version)
54
+ await binary.install(force)
55
+ datasource ? binary.run(datasource) : binary.run()
50
56
  }
51
57
  }
52
58
 
53
- function getPlatform() {
54
- const type = os.type();
55
- const arch = os.arch();
56
- const release = os.release();
57
- const cpuCore = os.cpus()[0];
58
- const majorVersion = semver.major(release);
59
- const isM1 = cpuCore.model.includes("Apple M1");
59
+ function getPlatform(logs) {
60
+ const type = os.type()
61
+ const arch = os.arch()
62
+ const release = os.release()
63
+ const cpuCore = os.cpus()[0]
64
+ const majorVersion = semver.major(release)
65
+ const isM1 = cpuCore.model.includes("Apple M1")
66
+
67
+ if (logs) {
68
+ console.log(`OS type: ${type}\nOS arch: ${arch}\nOS release: ${release}\nOS major version: ${majorVersion}\nCPU model: ${cpuCore.model}`)
69
+ }
60
70
 
61
71
  if (arch === 'x64' || (arch === 'arm64' && isM1)) {
62
72
  if (type === 'Darwin') {
63
- if (majorVersion === '19') {
64
- return 'binary-macos-10.15';
65
- } else if (majorVersion === '18') {
66
- return 'binary-macos-10.14';
73
+ if (majorVersion === 19) {
74
+ return 'binary-macos-10.15'
75
+ } else if (majorVersion === 18) {
76
+ return 'binary-macos-10.14'
67
77
  } else if (isM1) {
68
- return 'binary-macos-11-m1';
78
+ return 'binary-macos-11-m1'
69
79
  }
70
- return 'binary-macos-11';
80
+ return 'binary-macos-11'
71
81
  } else if (type === 'Linux') {
72
- if (majorVersion === '18') {
73
- return 'binary-linux-18';
82
+ if (majorVersion === 18) {
83
+ return 'binary-linux-18'
74
84
  }
75
- return 'binary-linux-20';
85
+ return 'binary-linux-20'
76
86
  } else if (type === 'Windows_NT') {
77
- return 'binary-windows';
87
+ return 'binary-windows'
78
88
  }
79
89
  }
80
90
 
81
- throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`);
91
+ throw new Error(`Unsupported platform: ${type} ${arch} ${majorVersion}`)
82
92
  }