Skip to content

Commit

Permalink
refactor: better logging and argument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
amarinkovic committed Jun 23, 2023
1 parent 7da18f5 commit 5954ddc
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions cli-tools/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ const dotenv = require("dotenv");

dotenv.config();

if (process.argv.length <= 3) {
console.error(chalk.red(`Must provide deployment operation and target network!`));

if (process.argv.length < 4) {
console.error(chalk.red(`Must provide deployment action and target network!`));
console.log(`Allowed actions are: ${chalk.green("deploy")} and ${chalk.green("upgrade")}`);
process.exit(1);
}

const [operation, networkId, ...otherArgs] = process.argv.slice(2);
const [action, networkId, ...otherArgs] = process.argv.slice(2);

const flags = new Set(["--fork", "--dry-run"]);
if (!otherArgs.every((a) => flags.has(a))) {
console.log(`Allowed flags are only: ${chalk.green("--fork")} and ${chalk.green("--dry-run")}`);
process.exit(1);
}

const fork = otherArgs.includes("--fork");
const dryRun = otherArgs.includes("--dry-run");
Expand All @@ -25,7 +33,7 @@ const systemAdminAddress =
? "0xE6aD24478bf7E1C0db07f7063A4019C83b1e5929" // mainnet sysAdminB
: Wallet.fromMnemonic(mnemonic, `m/44'/60'/0'/0/0`).address; // acc1

if (operation === "deploy") {
if (action === "deploy") {
console.log(`[ ${chalk.green(networkId + (fork ? "-fork" : ""))} ] Deploying new diamond`);

console.log(`\n[ ${chalk.green("Deploying contracts")} ]\n`);
Expand All @@ -51,7 +59,7 @@ if (operation === "deploy") {
console.log(`\n[ ${chalk.green("Doing upgrade")} ]\n`);
const upgradeCmd = upgrade(rpcUrl, networkId, ownerAddress, systemAdminAddress);
execute(upgradeCmd);
} else if (operation === "upgrade") {
} else if (action === "upgrade") {
const addressesRaw = fs.readFileSync("deployedAddresses.json");
const addresses = JSON.parse(addressesRaw);

Expand Down Expand Up @@ -110,7 +118,7 @@ if (operation === "deploy") {
execute(diamondCutCmd);
}
} else {
console.log(chalk.red("Supported operations are: 'deploy' and 'upgrade'!"));
console.log(chalk.red("Supported actions are: 'deploy' and 'upgrade'!"));
process.exit(1);
}

Expand Down

0 comments on commit 5954ddc

Please sign in to comment.