Skip to content

Commit a535d5e

Browse files
authored
feat: block explorer module, command improvements (#65)
1 parent fc28a0b commit a535d5e

17 files changed

+327
-39
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Or you can install the CLI globally with `npm i -g zksync-cli` and run the comma
2727
## 💻 Commands
2828

2929
### Local development commands
30-
`zksync-cli dev` - Manage local zkSync development environment. It allows to easily start zkSync stack locally, for example: local Ethereum and zkSync nodes, Wallet and Bridge.
30+
`zksync-cli dev` - Manage local zkSync development environment. It allows to easily start zkSync stack locally, for example: local Ethereum and zkSync nodes, Block Explorer, Wallet and Bridge.
3131

3232
**General:**
3333
- `zksync-cli dev start` - start local development environment (will ask to configure if starting for the first time)

package-lock.json

+198-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"ethers": "5.7.2",
4343
"inquirer": "^8.1.4",
4444
"winston": "^3.10.0",
45-
"zkcli-dockerized-node": "^1.0.2",
45+
"zkcli-block-explorer": "^1.0.2",
46+
"zkcli-dockerized-node": "^1.0.4",
4647
"zkcli-in-memory-node": "^1.0.3",
4748
"zkcli-portal": "^1.0.1",
4849
"zksync-web3": "^0.14.4"

src/commands/dev/clean.ts

+20-4
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,30 @@ export const cleanModule = async (module: Module) => {
1010
if (!isInstalled) {
1111
return;
1212
}
13-
module.removeDataDir();
1413
await module.clean();
14+
module.removeDataDir();
1515
} catch (error) {
1616
Logger.error(`There was an error while cleaning module "${module.name}":`);
1717
Logger.error(error);
1818
}
1919
};
2020

21-
export const handler = async () => {
21+
export const handler = async (modulePackageNames: string[]) => {
2222
try {
23-
const modules = await configHandler.getConfigModules();
23+
const modules = [];
24+
if (modulePackageNames.length) {
25+
const allModules = await configHandler.getAllModules();
26+
for (const moduleName of modulePackageNames) {
27+
const module = allModules.find((m) => m.package.name === moduleName);
28+
if (!module) {
29+
throw new Error(`Module "${moduleName}" not found`);
30+
}
31+
modules.push(module);
32+
}
33+
} else {
34+
const configModules = await configHandler.getConfigModules();
35+
modules.push(...configModules);
36+
}
2437
Logger.info(`Cleaning: ${modules.map((module) => module.name).join(", ")}...`);
2538
await Promise.all(modules.map((module) => cleanModule(module)));
2639
} catch (error) {
@@ -29,4 +42,7 @@ export const handler = async () => {
2942
}
3043
};
3144

32-
Program.command("clean").description("Clean data for all config modules").action(handler);
45+
Program.command("clean")
46+
.description("Clean data for all config modules")
47+
.argument("[module...]", "NPM package names of the modules to clean")
48+
.action(handler);

src/commands/dev/install.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ import chalk from "chalk";
22
import { Option } from "commander";
33

44
import Program from "./command.js";
5-
import { modulesPath } from "./modules/Module.js";
5+
import { createModulesFolder, modulesPath } from "./modules/Module.js";
66
import { executeCommand } from "../../utils/helpers.js";
77
import Logger from "../../utils/logger.js";
88

99
const linkOption = new Option("--link", "Use `npm link` instead of `npm install` (useful during module development)");
1010

1111
export const handler = async (moduleNames: string[], options: { link: boolean }) => {
1212
try {
13+
createModulesFolder();
14+
1315
const command = options.link ? "npm link" : "npm install";
1416
const fullCommand = `${command}${moduleNames.length ? ` ${moduleNames.join(" ")}` : ""}`;
1517
await executeCommand(fullCommand, { cwd: modulesPath });
1618

1719
if (moduleNames.length) {
1820
Logger.info(
19-
`Add module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
21+
`\nAdd module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
2022
"zksync-cli dev config"
2123
)}\``
2224
);

src/commands/dev/modules/Module.ts

+10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export type DefaultModuleFields = {
2222

2323
export const modulesPath = getLocalPath("modules");
2424

25+
export const createModulesFolder = () => {
26+
if (fileOrDirExists(modulesPath)) {
27+
return;
28+
}
29+
fs.mkdirSync(modulesPath, { recursive: true });
30+
};
31+
2532
type ModuleConfigDefault = Record<string, unknown>;
2633
abstract class Module<TModuleConfig = ModuleConfigDefault> {
2734
configHandler: ConfigHandler;
@@ -44,6 +51,9 @@ abstract class Module<TModuleConfig = ModuleConfigDefault> {
4451
abstract install(): Promise<void>;
4552

4653
abstract isRunning(): Promise<boolean>;
54+
get startAfterNode(): boolean {
55+
return false;
56+
}
4757
abstract start(): Promise<void>;
4858
getStartupInfo(): LogEntry[] | Promise<LogEntry[]> {
4959
return [];

src/commands/dev/modules/utils/packages.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "fs";
22
import { createRequire } from "module";
33
import path from "path";
4+
import ModuleBlockExplorer from "zkcli-block-explorer";
45
import ModuleDockerizedNode from "zkcli-dockerized-node";
56
import ModuleInMemoryNode from "zkcli-in-memory-node";
67
import ModulePortal from "zkcli-portal";
@@ -101,6 +102,7 @@ export const findDefaultModules = async (): Promise<Package[]> => {
101102
const packages = {
102103
"zkcli-in-memory-node": require("zkcli-in-memory-node/package.json") as PackageJSON,
103104
"zkcli-dockerized-node": require("zkcli-dockerized-node/package.json") as PackageJSON,
105+
"zkcli-block-explorer": require("zkcli-block-explorer/package.json") as PackageJSON,
104106
"zkcli-portal": require("zkcli-portal/package.json") as PackageJSON,
105107
} as const;
106108

@@ -115,6 +117,11 @@ export const findDefaultModules = async (): Promise<Package[]> => {
115117
name: packages["zkcli-dockerized-node"].name,
116118
version: packages["zkcli-dockerized-node"].version,
117119
},
120+
{
121+
module: ModuleBlockExplorer as unknown as Module,
122+
name: packages["zkcli-block-explorer"].name,
123+
version: packages["zkcli-block-explorer"].version,
124+
},
118125
{
119126
module: ModulePortal as unknown as Module,
120127
name: packages["zkcli-portal"].name,

0 commit comments

Comments
 (0)