Commit c19eebab authored by Kelvin Fichter's avatar Kelvin Fichter

feat: make contracts package browser compatible

parent 3f9941e3
src/contract-artifacts.ts
...@@ -39,13 +39,14 @@ ...@@ -39,13 +39,14 @@
"lint:fix": "yarn lint:check --fix", "lint:fix": "yarn lint:check --fix",
"lint:contracts": "yarn solhint -f table contracts/optimistic-ethereum/**/*.sol", "lint:contracts": "yarn solhint -f table contracts/optimistic-ethereum/**/*.sol",
"clean": "rm -rf ./dist ./artifacts ./artifacts-ovm ./cache ./cache-ovm ./tsconfig.build.tsbuildinfo", "clean": "rm -rf ./dist ./artifacts ./artifacts-ovm ./cache ./cache-ovm ./tsconfig.build.tsbuildinfo",
"deploy": "ts-node \"./bin/deploy.ts\" && yarn generate-markdown", "deploy": "ts-node \"./bin/deploy.ts\" && yarn generate:markdown",
"serve": "./bin/serve_dump.sh", "serve": "./bin/serve_dump.sh",
"prepublishOnly": "yarn copyfiles -u 2 \"contracts/optimistic-ethereum/**/*\" ./", "prepublishOnly": "yarn copyfiles -u 2 \"contracts/optimistic-ethereum/**/*\" ./",
"postpublish": "rimraf OVM iOVM libraries mockOVM", "postpublish": "rimraf OVM iOVM libraries mockOVM",
"prepack": "yarn prepublishOnly", "prepack": "yarn prepublishOnly",
"postpack": "yarn postpublish", "postpack": "yarn postpublish",
"generate-markdown": "node \"./scripts/generate-markdown.js\"", "generate:markdown": "node \"./scripts/generate-markdown.js\"",
"generate:artifacts": "node \"./scripts/generate-artifacts.js\"",
"pre-commit": "lint-staged" "pre-commit": "lint-staged"
}, },
"dependencies": { "dependencies": {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
set -e set -e
yarn build:typescript &
yarn build:contracts yarn build:contracts
yarn build:contracts:ovm yarn build:contracts:ovm
yarn generate:artifacts
yarn build:typescript
#!/usr/bin/env node
const path = require('path')
const glob = require('glob')
const fs = require('fs')
;(async () => {
console.log(`writing contract artifacts typescript file`)
const getContractJsonFiles = (artifactsFolder) => {
return glob.sync(`${artifactsFolder}/**/*.json`).filter((match) => {
return !match.endsWith('.dbg.json')
})
}
const evmArtifactPaths = getContractJsonFiles(
path.resolve(__dirname, `../artifacts/contracts`)
)
const ovmArtifactPaths = getContractJsonFiles(
path.resolve(__dirname, `../artifacts-ovm/contracts`)
)
const content = `
/* eslint-disable @typescript-eslint/no-var-requires, no-empty */
/*
THIS FILE IS AUTOMATICALLY GENERATED.
DO NOT EDIT.
*/
${ovmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
const relPath = path.relative(__dirname, artifactPath)
return `
let ovm__${artifact.contractName}
try {
ovm__${artifact.contractName} = require('${relPath}')
} catch {}
`
})
.join('\n')}
${evmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
const relPath = path.relative(__dirname, artifactPath)
return `
let ${artifact.contractName}
try {
${artifact.contractName} = require('${relPath}')
} catch {}
`
})
.join('\n')}
export const getContractArtifact = (name: string, ovm: boolean): any => {
if (ovm) {
return {
${ovmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
return `${artifact.contractName}: ovm__${artifact.contractName}`
})
.join(',\n')}
}[name]
} else {
return {
${evmArtifactPaths
.map((artifactPath) => {
const artifact = require(artifactPath)
return `${artifact.contractName}: ${artifact.contractName}`
})
.join(',\n')}
}[name]
}
}
`
fs.writeFileSync(`./src/contract-artifacts.ts`, content)
})().catch(console.error)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment