forked from sushiswap/hardhat-framework
-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
127 lines (112 loc) · 4.47 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env node
const fs = require("fs")
const util = require('util');
const exec = util.promisify(require('child_process').exec);
console.log("Running Boring")
async function run(command) {
const { stdout, stderr } = await exec(command)
console.log(`stdout: ${stdout}`)
if (stderr) {
console.log(`stderr: ${stderr}`)
}
}
async function init() {
const rootPath = require.main.paths[0].split('node_modules')[0];
function makedir(dir) {
if (!fs.existsSync(rootPath + dir)){
fs.mkdirSync(rootPath + dir);
}
}
function copy(from, to, overwrite) {
if (overwrite || !fs.existsSync(rootPath + to)){
fs.copyFileSync(__dirname + from, rootPath + to)
}
}
makedir(".vscode")
makedir("contracts")
makedir("scripts")
makedir("test")
makedir("flat")
copy("/project/.vscode/settings.json", ".vscode/settings.json", false)
copy("/project/contracts/Greeter.sol", "contracts/Greeter.sol", false)
copy("/project/scripts/deploy.txt", "scripts/deploy.ts", false)
copy("/project/test/index.txt", "test/index.ts", false)
copy("/project/.eslintignore", ".eslintignore", false)
copy("/project/.eslintrc.js", ".eslintrc.js", false)
copy("/project/.gitignore", ".gitignore", false)
copy("/project/.npmignore", ".npmignore", false)
copy("/project/.prettierignore", ".prettierignore", false)
copy("/project/.prettierrc.js", ".prettierrc.js", false)
copy("/project/.solcover.js", ".solcover.js", false)
copy("/project/.solhint.json", ".solhint.json", false)
copy("/project/.solhintignore", ".solhintignore", false)
copy("/project/hardhat.config.txt", "hardhat.config.ts", false)
copy("/project/tsconfig.txt", "tsconfig.json", false)
makedir("web3")
makedir("web3/assets")
makedir("web3/components")
makedir("web3/public")
copy("/project/web3/public/favicon.ico", "web3/public/favicon.ico", false)
copy("/project/web3/assets/logo.png", "web3/assets/logo.png", false)
copy("/project/web3/components/HelloWorld.vue", "web3/components/HelloWorld.vue", false)
copy("/project/web3/App.vue", "web3/App.vue", false)
copy("/project/web3/env.d.ts", "web3/env.d.ts", false)
copy("/project/web3/main.ts", "web3/main.ts", false)
copy("/project/web3/tsconfig.json", "web3/tsconfig.json", false)
copy("/project/web3/tsconfig.node.json", "web3/tsconfig.node.json", false)
copy("/project/web3/vite.config.ts", "web3/vite.config.ts", false)
copy("/project/web3/index.html", "web3/index.html", false)
const json = require(rootPath + 'package.json');
if (!json.hasOwnProperty('scripts')) {
json.scripts = {};
}
json.scripts['compile'] = 'hardhat compile';
json.scripts['test'] = 'hardhat test';
json.scripts['coverage'] = 'hardhat coverage && open-cli ./coverage/index.html';
json.scripts['prettier'] = 'prettier --write *.js *.ts *.json test/**/*.ts contracts/**/*.sol';
json.scripts['flat'] = 'hardhat run scripts/flat.ts Greeter.sol';
json.scripts['dev'] = "vite --config web3/vite.config.ts";
json.scripts['build'] = "vue-tsc --noEmit && vite build";
json.scripts['preview'] = "vite preview";
fs.writeFileSync(rootPath + 'package.json', JSON.stringify(json, null, 4));
await run("npx husky-init")
await run('yarn husky set .husky/pre-commit "npx pretty-quick --staged"')
await run("yarn compile") // create typechain dir and files
}
async function add(name) {
const rootPath = require.main.paths[0].split('node_modules')[0];
fs.writeFileSync(rootPath + "contracts/" + name + ".sol",
`//SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
contract ` + name + ` {
constructor() {
}
}
`)
fs.writeFileSync(rootPath + "test/" + name + ".ts",
`import { expect } from "chai";
import { ethers } from "hardhat";
import { ` + name + `__factory } from "../typechain-types";
describe("` + name + `", function () {
it("Should do something", async function () {
const deployer = (await ethers.getSigners())[0]
const ` + name.toLowerCase() + ` = await new ` + name + `__factory(deployer).deploy();
await ` + name.toLowerCase() + `.deployed();
});
});
`)
}
async function main() {
if (process.argv[2] == "init") {
await init()
}
if (process.argv[2] == "add") {
await add(process.argv[3])
}
}
main()
.then(() => process.exit(process.exitCode))
.catch((error) => {
console.error(error);
process.exit(1);
});