Skip to content

Commit

Permalink
yarn workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ly0va committed Nov 3, 2020
1 parent dd6428f commit 47d1e22
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 890 deletions.
4 changes: 2 additions & 2 deletions bin/zk
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

if [ -z "$1" ]; then
cd $ZKSYNC_HOME/infrastructure/zk
yarn && yarn build
cd $ZKSYNC_HOME
yarn && yarn zk build
else
# can't start this with yarn since it has quirks with `--` as an argument
node $ZKSYNC_HOME/infrastructure/zk/build/index.js "$@"
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/zk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"printWidth": 120,
"parser": "typescript",
"singleQuote": true,
"trailingComma": "none"
"trailingComma": "none",
"bracketSpacing": true
},
"scripts": {
"build": "tsc",
Expand Down
8 changes: 4 additions & 4 deletions infrastructure/zk/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function build() {
await utils.confirmAction();
prepareVerify();
await utils.spawn('cargo run --release --bin gen_token_add_contract');
await utils.spawn('yarn --cwd contracts build');
await utils.spawn('yarn contracts build');
}

async function prepareTestContracts() {
Expand Down Expand Up @@ -95,17 +95,17 @@ export async function buildDev() {
await utils.confirmAction();
prepareVerify();
await prepareTestContracts();
await utils.spawn('yarn --cwd contracts build-dev');
await utils.spawn('yarn contracts build-dev');
}

export async function publish() {
await utils.spawn('yarn --cwd contracts publish-sources');
await utils.spawn('yarn contracts publish-sources');
}

export async function deploy() {
await utils.confirmAction();
console.log('Deploying contracts, results will be inserted into the db');
await utils.spawn('yarn --cwd contracts deploy-no-build | tee deploy.log');
await utils.spawn('yarn contracts deploy-no-build | tee deploy.log');
const deployLog = fs.readFileSync('deploy.log').toString();
const envVars = [
'GOVERNANCE_TARGET_ADDR',
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/zk/src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function dockerCommand(command: 'push' | 'build', image: string) {

async function _build(image: string) {
if (image == 'nginx') {
await utils.spawn('yarn --cwd infrastructure/explorer build');
await utils.spawn('yarn explorer build');
}
if (image == 'server' || image == 'prover') {
await contract.build();
Expand Down
40 changes: 22 additions & 18 deletions infrastructure/zk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ import { command as docker } from './docker';
import { command as completion } from './completion';
import * as env from './env';

const COMMANDS = [
server,
up,
down,
db,
contract,
dummyProver,
init,
kube,
prover,
run,
test,
docker,
env.command,
completion(program as Command)
];

async function main() {
const cwd = process.cwd();
const ZKSYNC_HOME = process.env.ZKSYNC_HOME;
Expand All @@ -29,24 +46,11 @@ async function main() {

env.load();

program
.version('0.1.0')
.name('zk')
.description('zksync workflow tools')
.addCommand(server)
.addCommand(up)
.addCommand(down)
.addCommand(db)
.addCommand(contract)
.addCommand(dummyProver)
.addCommand(kube)
.addCommand(init)
.addCommand(prover)
.addCommand(run)
.addCommand(test)
.addCommand(docker)
.addCommand(env.command)
.addCommand(completion(program as Command));
program.version('0.1.0').name('zk').description('zksync workflow tools');

for (const command of COMMANDS) {
program.addCommand(command);
}

// f command is special-cased because it is necessary
// for it to run from $PWD and not from $ZKSYNC_HOME
Expand Down
15 changes: 5 additions & 10 deletions infrastructure/zk/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@ export async function init() {
}

async function checkEnv() {
await utils.exec('which node');
const tools = ['node', 'yarn', 'docker', 'docker-compose', 'cargo', 'psql', 'pg_isready', 'diesel', 'solc'];
for (const tool of tools) {
await utils.exec(`which ${tool}`);
}
await utils.exec('cargo sqlx --version');
const { stdout: version } = await utils.exec('node --version');
if ('v14' >= version) {
throw new Error('Error, node.js version 14 or higher is required');
}
await utils.exec('which yarn');
await utils.exec('which docker');
await utils.exec('which docker-compose');
await utils.exec('which cargo');
await utils.exec('cargo sqlx --version');
await utils.exec('which psql');
await utils.exec('which pg_isready');
await utils.exec('which diesel');
await utils.exec('which solc');
}

export const command = new Command('init')
Expand Down
22 changes: 7 additions & 15 deletions infrastructure/zk/src/run/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,31 @@ export { verifyKeys, dataRestore };

export async function deployERC20(command: 'dev' | 'new', name?: string, symbol?: string, decimals?: string) {
if (command == 'dev') {
await utils.spawn(`yarn --silent --cwd contracts deploy-erc20 add-multi '
await utils.spawn(`yarn --silent contracts deploy-erc20 add-multi '
[
{ "name": "DAI", "symbol": "DAI", "decimals": 18 },
{ "name": "wBTC", "symbol": "wBTC", "decimals": 8 },
{ "name": "BAT", "symbol": "BAT", "decimals": 18 },
{ "name": "MLTT", "symbol": "MLTT", "decimals": 18 }
]' > ./etc/tokens/localhost.json`);
} else if (command == 'new') {
await utils.spawn(
`yarn --cwd contracts deploy-erc20 add --name ${name} --symbol ${symbol} --decimals ${decimals}`
);
await utils.spawn(`yarn contracts deploy-erc20 add --name ${name} --symbol ${symbol} --decimals ${decimals}`);
}
}

// installs all dependencies and builds our js packages
export async function yarn() {
await utils.spawn('yarn --cwd sdk/zksync.js');
await utils.spawn('yarn --cwd sdk/zksync.js build');
await utils.spawn('yarn --cwd contracts');
await utils.spawn('yarn --cwd core/tests/ts-tests');
await utils.spawn('yarn --cwd infrastructure/explorer');
await utils.spawn('yarn --cwd infrastructure/fee-seller');
await utils.spawn('yarn --cwd infrastructure/zcli');
await utils.spawn('yarn --cwd infrastructure/analytics');
await utils.spawn('yarn');
await utils.spawn('yarn zksync build');
}

export async function deployTestkit(genesisRoot: string, prodContracts: boolean = false) {
const option = prodContracts ? '--prodContracts' : '';
await utils.spawn(`yarn --cwd contracts deploy-testkit --genesisRoot ${genesisRoot} ${option}`);
await utils.spawn(`yarn contracts deploy-testkit --genesisRoot ${genesisRoot} ${option}`);
}

export async function testUpgrade(contract: string, gatekeeper: string) {
await utils.spawn(`yarn --cwd contracts ts-node scripts/test-upgrade-franklin.ts ${contract} ${gatekeeper}`);
await utils.spawn(`yarn contracts ts-node scripts/test-upgrade-franklin.ts ${contract} ${gatekeeper}`);
}

export async function plonkSetup(powers?: number[]) {
Expand All @@ -65,7 +57,7 @@ export async function revertReason(txHash: string, web3url?: string) {
}

export async function explorer() {
await utils.spawn('yarn --cwd infrastructure/explorer serve');
await utils.spawn('yarn explorer serve');
}

export async function exitProof(...args: string[]) {
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/zk/src/test/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ export async function all() {
}

export async function api() {
await utils.spawn('yarn --cwd core/tests/ts-tests api-test');
await utils.spawn('yarn ts-tests api-test');
}

export async function zcli() {
await utils.spawn('yarn --cwd infrastructure/zcli test');
await utils.spawn('yarn zcli test');
}

export async function server() {
await utils.spawn('yarn --cwd core/tests/ts-tests test');
await utils.spawn('yarn ts-tests test');
}

export async function testkit(command: string) {
Expand Down
6 changes: 3 additions & 3 deletions infrastructure/zk/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function db(reset: boolean) {

export async function contracts() {
await contract.build();
await utils.spawn('yarn --cwd contracts unit-test');
await utils.spawn('yarn contracts unit-test');
}

export async function circuit(threads: number = 1, testName?: string, ...args: string[]) {
Expand All @@ -34,8 +34,8 @@ export async function prover() {
}

export async function js() {
await utils.spawn('yarn --cwd sdk/zksync.js tests');
await utils.spawn('yarn --cwd infrastructure/fee-seller tests');
await utils.spawn('yarn zksync tests');
await utils.spawn('yarn fee-seller tests');
}

export async function rust() {
Expand Down
Loading

0 comments on commit 47d1e22

Please sign in to comment.