Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import fs from 'fs-extra' | ||
import path from 'path' | ||
|
||
// We use Partial<NetworkConfig> for localhost as we don't have all the information | ||
const defaultLocalhost = { | ||
chain: 'localhost', | ||
description: 'Localhost network.', | ||
featured: false, | ||
fullySubsidizedGas: true, | ||
id: 31337, | ||
isTestNetwork: true, | ||
name: 'Localhost', | ||
nativeCurrency: { | ||
coingecko: 'ethereum', | ||
decimals: 18, | ||
name: 'ETH', | ||
symbol: 'ETH', | ||
}, | ||
provider: 'http://127.0.0.1:8545', | ||
publicLockVersionToDeploy: 13, | ||
publicProvider: 'http://127.0.0.1:8545', | ||
subgraph: { | ||
endpoint: '', | ||
}, | ||
} | ||
|
||
const generateLocalhostNetworkFile = ({ | ||
unlockAddress, | ||
subgraphEnpoint = 'http://localhost:8000/subgraphs/name/testgraph', | ||
}) => { | ||
const localhost = { | ||
...defaultLocalhost, | ||
subgraph: { | ||
endpoint: subgraphEnpoint, | ||
}, | ||
unlockAddress, | ||
} | ||
|
||
// log for debug purposes | ||
console.log(localhost) | ||
|
||
// output to js file | ||
const parsed = `import { NetworkConfig } from '@unlock-protocol/types' | ||
// We use Partial<NetworkConfig> for localhost as we don't have all the information | ||
export const localhost: Partial<NetworkConfig> = ${JSON.stringify(localhost)} | ||
export default localhost | ||
` | ||
return parsed | ||
} | ||
|
||
const run = async () => { | ||
const [networkInfoPath, subgraphEnpoint] = process.argv.slice(2) | ||
|
||
const networkInfo = await fs.readJSON(networkInfoPath) | ||
const { | ||
localhost: { | ||
Unlock: { address: unlockAddress }, | ||
}, | ||
} = networkInfo | ||
|
||
console.log(networkInfo) | ||
|
||
console.log(`Creating localhost file for unlockAddress ${unlockAddress}`) | ||
|
||
if (!unlockAddress) { | ||
throw new Error('Missing unlockAddress arg') | ||
} | ||
|
||
const fileContent = generateLocalhostNetworkFile({ | ||
subgraphEnpoint, | ||
unlockAddress, | ||
}) | ||
|
||
const filePath = path.resolve('./src/networks/localhost.ts') | ||
|
||
await fs.writeFile(filePath, fileContent) | ||
} | ||
run() | ||
.then(() => console.log('done')) | ||
.catch((err) => { | ||
throw err | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters