Skip to content

Commit 6c4da95

Browse files
committed
init: Move package.json generation to Scaffold class
1 parent 47e7d83 commit 6c4da95

File tree

2 files changed

+42
-41
lines changed

2 files changed

+42
-41
lines changed

src/old-scaffold.js

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
11
const fs = require('fs-extra')
22
const path = require('path')
33
const prettier = require('prettier')
4-
const pkginfo = require('pkginfo')(module)
54

6-
const { getSubgraphBasename } = require('./command-helpers/subgraph')
75
const { step } = require('./command-helpers/spinner')
86
const Scaffold = require('./scaffold')
97

10-
const graphCliVersion = process.env.GRAPH_CLI_TESTS
11-
// JSON.stringify should remove this key, we will install the local
12-
// graph-cli for the tests using `npm link` instead of fetching from npm.
13-
? undefined
14-
// For scaffolding real subgraphs
15-
: `${module.exports.version}`
16-
17-
// package.json
18-
19-
const generatePackageJson = ({ subgraphName, node }) =>
20-
prettier.format(
21-
JSON.stringify({
22-
name: getSubgraphBasename(subgraphName),
23-
license: 'UNLICENSED',
24-
scripts: {
25-
codegen: 'graph codegen',
26-
build: 'graph build',
27-
deploy:
28-
`graph deploy ` +
29-
`--node ${node} ` +
30-
subgraphName,
31-
'create-local': `graph create --node http://localhost:8020/ ${subgraphName}`,
32-
'remove-local': `graph remove --node http://localhost:8020/ ${subgraphName}`,
33-
'deploy-local':
34-
`graph deploy ` +
35-
`--node http://localhost:8020/ ` +
36-
`--ipfs http://localhost:5001 ` +
37-
subgraphName,
38-
},
39-
dependencies: {
40-
'@graphprotocol/graph-cli': graphCliVersion,
41-
'@graphprotocol/graph-ts': `0.24.1`,
42-
},
43-
}),
44-
{ parser: 'json' },
45-
)
46-
478
const tsConfig = prettier.format(
489
JSON.stringify({
4910
extends: '@graphprotocol/graph-ts/types/tsconfig.base.json',
@@ -67,8 +28,6 @@ const generateScaffold = async (
6728
) => {
6829
step(spinner, 'Generate subgraph')
6930

70-
let packageJson = generatePackageJson({ subgraphName, node })
71-
7231
let scaffold = new Scaffold({
7332
protocol: protocolInstance,
7433
abi,
@@ -77,8 +36,10 @@ const generateScaffold = async (
7736
network,
7837
contractName,
7938
subgraphName,
39+
node,
8040
})
8141

42+
let packageJson = scaffold.generatePackageJson()
8243
let manifest = scaffold.generateManifest()
8344
let schema = scaffold.generateSchema()
8445
let mapping = scaffold.generateMapping()

src/scaffold/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
const prettier = require('prettier')
2+
const pkginfo = require('pkginfo')(module)
3+
4+
const GRAPH_CLI_VERSION = process.env.GRAPH_CLI_TESTS
5+
// JSON.stringify should remove this key, we will install the local
6+
// graph-cli for the tests using `npm link` instead of fetching from npm.
7+
? undefined
8+
// For scaffolding real subgraphs
9+
: `${module.exports.version}`
10+
211
const {
312
abiEvents,
413
generateEventType,
514
generateExampleEntityType,
615
} = require('./schema')
716
const { generateEventIndexingHandlers } = require('./mapping')
17+
const { getSubgraphBasename } = require('../command-helpers/subgraph')
818

919
module.exports = class Scaffold {
1020
constructor(options = {}) {
@@ -15,6 +25,36 @@ module.exports = class Scaffold {
1525
this.network = options.network
1626
this.contractName = options.contractName
1727
this.subgraphName = options.subgraphName
28+
this.node = options.node
29+
}
30+
31+
generatePackageJson() {
32+
return prettier.format(
33+
JSON.stringify({
34+
name: getSubgraphBasename(this.subgraphName),
35+
license: 'UNLICENSED',
36+
scripts: {
37+
codegen: 'graph codegen',
38+
build: 'graph build',
39+
deploy:
40+
`graph deploy ` +
41+
`--node ${this.node} ` +
42+
this.subgraphName,
43+
'create-local': `graph create --node http://localhost:8020/ ${this.subgraphName}`,
44+
'remove-local': `graph remove --node http://localhost:8020/ ${this.subgraphName}`,
45+
'deploy-local':
46+
`graph deploy ` +
47+
`--node http://localhost:8020/ ` +
48+
`--ipfs http://localhost:5001 ` +
49+
this.subgraphName,
50+
},
51+
dependencies: {
52+
'@graphprotocol/graph-cli': GRAPH_CLI_VERSION,
53+
'@graphprotocol/graph-ts': `0.24.1`,
54+
},
55+
}),
56+
{ parser: 'json' },
57+
)
1858
}
1959

2060
generateManifest() {

0 commit comments

Comments
 (0)