Skip to content

Commit

Permalink
normalize scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Jun 5, 2020
1 parent cbe68cf commit a6266e6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
26 changes: 12 additions & 14 deletions package.json
@@ -1,25 +1,23 @@
{
"name": "sandbox-subgraph",
"version": "0.1.0",
"scripts": {
"create-local-graph": "wait-on http-get://127.0.0.1:8000 && graph create pixowl/the-sandbox --node http://127.0.0.1:8020",
"codegen-graph": "rm -Rf generated && graph codegen",
"build-graph": "graph build",
"generate-local-abis": "node scripts/generateABIs.js ./dev_contractsInfo.json",
"generate-local-subgraph-yml": "node scripts/generateYml.js ./contractsInfo.json",
"deploy-local-graph": "graph codegen && wait-on http://127.0.0.1:5001/api/v0/version http-get://127.0.0.1:8000 && graph deploy pixowl/the-sandbox --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"generate-abis": "node scripts/generateABIs.js ./contractsInfo.json",
"generate-subgraph-yml": "node scripts/generateYml.js ./contractsInfo.json",
"deploy-graph": "dotenv -- cross-var graph deploy --access-token $THEGRAPH_TOKEN pixowl/the-sandbox --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy": "run-s generate-abis generate-subgraph-yml deploy-graph"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.16.0",
"@graphprotocol/graph-ts": "^0.16.0",
"cross-var": "^1.1.0",
"dotenv-cli": "^3.1.0",
"fs-extra": "^9.0.0",
"handlebars": "^4.7.6",
"npm-run-all": "^4.1.5",
"wait-on": "^4.0.1"
"wait-on": "^4.0.1",
"npm-run-all": "^4.1.5"
},
"scripts": {
"local:setup": "wait-on http-get://127.0.0.1:8000 && graph create pixowl/the-sandbox --node http://127.0.0.1:8020",
"codegen": "rm -Rf generated && graph codegen",
"build": "graph build",
"generate": "node scripts/generate.js",
"local:redeploy": "graph codegen && wait-on http://127.0.0.1:5001/api/v0/version http-get://127.0.0.1:8000 && graph deploy pixowl/the-sandbox --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"local:deploy": "npm-run-all \"generate -- {1} {2}\" local:redeploy --",
"mainnet:deploy": "dotenv -- cross-var graph deploy --access-token $THEGRAPH_TOKEN pixowl/the-sandbox --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug"
}
}
45 changes: 45 additions & 0 deletions scripts/generate.js
@@ -0,0 +1,45 @@
const fs = require("fs-extra");
const path = require("path");
const Handlebars = require("handlebars");

const args = process.argv.slice(2);
const pathArg = args[0];
const chainName = args[1];

if (!pathArg) {
console.error(`please provide the path to contracts info, either a directory of deployemnt or a single export file`);
}
if (!fs.existsSync(pathArg)) {
console.error(`file ${pathArg} doest not exits`);
}

const stat = fs.statSync(pathArg);
let contractInfo;
if (stat.isDirectory()) {
contractsInfo = {
contracts: {

},
chainName
};
const files = fs.readdirSync(pathArg, {withFileTypes: true});
for (const file of files) {
if (!file.isDirectory() && file.name.substr(file.name.length-5) === ".json") {
const contractName = file.name.substr(0, file.name.length-5);
contractsInfo.contracts[contractName] = JSON.parse(fs.readFileSync(path.join(pathArg, file.name)).toString());
}
}
} else {
contractsInfo = JSON.parse(fs.readFileSync(pathArg).toString());
}

const contracts = contractsInfo.contracts;
fs.emptyDirSync("./abis");
for (const contractName of Object.keys(contracts)) {
const contractInfo = contracts[contractName];
fs.writeFileSync(path.join("abis", contractName + ".json"), JSON.stringify(contractInfo.abi));
}

const template = Handlebars.compile(fs.readFileSync("./templates/subgraph.yaml").toString());
const result = template(contractsInfo);
fs.writeFileSync("./subgraph.yaml", result);
14 changes: 0 additions & 14 deletions scripts/generateABIs.js

This file was deleted.

8 changes: 0 additions & 8 deletions scripts/generateYml.js

This file was deleted.

8 changes: 2 additions & 6 deletions templates/subgraph.yaml
Expand Up @@ -10,9 +10,7 @@ dataSources:
source:
address: "{{contracts.Land.address}}"
abi: LandContract
{{#if contracts.Land.blockNumber}}
startBlock: {{contracts.Land.blockNumber}}
{{/if}}
startBlock: {{contracts.Land.receipt.blockNumber}}
mapping:
kind: ethereum/events
apiVersion: 0.0.3
Expand All @@ -32,9 +30,7 @@ dataSources:
source:
address: "{{contracts.Asset.address}}"
abi: AssetContract
{{#if contracts.Asset.blockNumber}}
startBlock: {{contracts.Asset.blockNumber}}
{{/if}}
startBlock: {{contracts.Asset.receipt.blockNumber}}
mapping:
kind: ethereum/events
apiVersion: 0.0.3
Expand Down

0 comments on commit a6266e6

Please sign in to comment.