Skip to content

Commit 00e1b04

Browse files
authored
feat: update modules, command log changes, installation in correct order (#83)
1 parent 51f8384 commit 00e1b04

File tree

8 files changed

+64
-44
lines changed

8 files changed

+64
-44
lines changed

package-lock.json

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

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"./lib": "./bin/lib/index.js"
1616
},
1717
"scripts": {
18-
"build": "cross-env NODE_ENV=development tsc -p tsconfig.build.json",
19-
"dev": "ts-node-esm src/index.ts",
18+
"build": "tsc -p tsconfig.build.json",
19+
"dev": "cross-env NODE_ENV=development ts-node-esm src/index.ts",
2020
"typecheck": "tsc -p . --noEmit",
2121
"lint": "eslint . --ext ./src/* --fix --ignore-path .gitignore --no-error-on-unmatched-pattern --max-warnings=0",
2222
"commitlint": "commitlint --edit"
@@ -44,8 +44,8 @@
4444
"ora": "^7.0.1",
4545
"update-notifier": "^7.0.0",
4646
"winston": "^3.10.0",
47-
"zkcli-block-explorer": "^1.0.2",
48-
"zkcli-dockerized-node": "^1.0.4",
47+
"zkcli-block-explorer": "^1.1.0",
48+
"zkcli-dockerized-node": "^1.0.5",
4949
"zkcli-in-memory-node": "^1.0.3",
5050
"zkcli-portal": "^1.0.1",
5151
"zksync-web3": "^0.14.4"

src/commands/dev/config.ts

+23-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@ import configHandler from "./ConfigHandler.js";
66
import { ModuleCategory } from "./modules/Module.js";
77
import Logger from "../../utils/logger.js";
88

9+
import type Module from "./modules/Module.js";
910
import type { ModuleNode } from "./modules/Module.js";
1011

1112
type LocalConfigOptions = {
1213
node?: string;
1314
modules?: string[];
1415
};
1516

17+
const formatModuleName = (module: Module) => {
18+
let name = `${module.name} - ${module.description}`;
19+
if (process.env.NODE_ENV === "development") {
20+
name += chalk.gray(` - ${module.package.name}`);
21+
}
22+
if (module.package.symlinked) {
23+
name += chalk.gray(" (installed via --link)");
24+
}
25+
return name;
26+
};
27+
1628
export const setupConfig = async (options: LocalConfigOptions = {}) => {
1729
const modules = await configHandler.getAllModules();
1830
if (!modules.length) {
1931
Logger.error("No installed modules were found");
20-
Logger.error("Run `zksync-cli dev install [module-name...]` to install modules.");
32+
Logger.error("Run `npx zksync-cli dev install [module-name...]` to install modules.");
2133
return;
2234
}
2335

@@ -31,7 +43,7 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
3143
type: "list",
3244
when: () => nodes.length > 0,
3345
choices: nodes.map((node) => ({
34-
name: `${node.name} - ${node.description}`,
46+
name: formatModuleName(node),
3547
short: node.name,
3648
value: node.package.name,
3749
})),
@@ -54,12 +66,12 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
5466
potentialModules.map(async (module) => {
5567
try {
5668
return {
57-
...module,
69+
instance: module,
5870
unsupported: (await module.isNodeSupported(nodeInfo)) ? false : "Module doesn't support selected node",
5971
};
6072
} catch (error) {
6173
return {
62-
...module,
74+
instance: module,
6375
unsupported: "Failed to check node support status",
6476
};
6577
}
@@ -71,11 +83,11 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
7183
return a.unsupported ? 1 : -1;
7284
}
7385
// If categories are equal, compare by name.
74-
if (a.category === b.category) {
75-
return a.name.localeCompare(b.name);
86+
if (a.instance.category === b.instance.category) {
87+
return a.instance.name.localeCompare(b.instance.name);
7688
}
7789
// Compare by category.
78-
return a.category.localeCompare(b.category);
90+
return a.instance.category.localeCompare(b.instance.category);
7991
});
8092

8193
const modulesAnswers: LocalConfigOptions = await inquirer.prompt(
@@ -86,9 +98,9 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
8698
type: "checkbox",
8799
when: () => sortedModules.length > 0,
88100
choices: sortedModules.map((module) => ({
89-
name: `${module.name} - ${module.description}`,
90-
short: module.name,
91-
value: module.package.name,
101+
name: formatModuleName(module.instance),
102+
short: module.instance.name,
103+
value: module.instance.package.name,
92104
disabled: module.unsupported,
93105
})),
94106
},
@@ -120,7 +132,7 @@ export const handler = async (options: LocalConfigOptions = {}) => {
120132
await setupConfig(options);
121133

122134
Logger.info("\nConfiguration saved successfully!", { noFormat: true });
123-
Logger.info(`Start configured environment with \`${chalk.magentaBright("zksync-cli dev start")}\``);
135+
Logger.info(`Start configured environment with \`${chalk.magentaBright("npx zksync-cli dev start")}\``);
124136
} catch (error) {
125137
Logger.error("There was an error while configuring the testing environment:");
126138
Logger.error(error);

src/commands/dev/install.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const handler = async (moduleNames: string[], options: { link: boolean })
1919
if (moduleNames.length) {
2020
Logger.info(
2121
`\nAdd module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
22-
"zksync-cli dev config"
22+
"npx zksync-cli dev config"
2323
)}\``
2424
);
2525
}

src/commands/dev/logs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const handler = async () => {
99
const modules = await configHandler.getConfigModules();
1010
if (!modules.length) {
1111
Logger.warn("There are no configured modules");
12-
Logger.info("You can configure them with: `zksync-cli dev config");
12+
Logger.info("You can configure them with: `npx zksync-cli dev config");
1313
return;
1414
}
1515

src/commands/dev/modules/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const handler = async () => {
99
const modules = await configHandler.getAllModules();
1010
if (!modules.length) {
1111
Logger.warn("There are no modules installed");
12-
Logger.info("You can install modules with: `zksync-cli dev install [module-name...]");
12+
Logger.info("You can install modules with: `npx zksync-cli dev install [module-name...]");
1313
return;
1414
}
1515

src/commands/dev/start.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ const installModules = async (modules: Module[]) => {
2323

2424
const startModules = async (modules: Module[]) => {
2525
Logger.info(`\nStarting: ${modules.map((m) => m.name).join(", ")}...`);
26-
await Promise.all(modules.filter((e) => !e.startAfterNode).map((m) => m.start()));
27-
await Promise.all(modules.filter((e) => e.startAfterNode).map((m) => m.start()));
26+
await Promise.all(modules.map((m) => m.start()));
2827
};
2928

3029
const stopOtherNodes = async (currentModules: Module[]) => {
@@ -56,13 +55,13 @@ const checkForUpdates = async (modules: Module[]) => {
5655
if (currentVersion) {
5756
str += chalk.gray(` (current: ${currentVersion})`);
5857
}
59-
str += chalk.gray(` - zksync-cli dev update ${module.package.name}`);
58+
str += chalk.gray(` - npx zksync-cli dev update ${module.package.name}`);
6059
Logger.info(str);
6160
}
6261
if (modulesRequiringUpdates.length > 1) {
6362
Logger.info(
6463
chalk.gray(
65-
`Update all modules: zksync-cli dev update ${modulesRequiringUpdates
64+
`Update all modules: npx zksync-cli dev update ${modulesRequiringUpdates
6665
.map(({ module }) => module.package.name)
6766
.join(" ")}`
6867
)
@@ -93,21 +92,24 @@ export const handler = async () => {
9392
try {
9493
if (!configHandler.configExists) {
9594
await setupConfig();
96-
Logger.info("");
95+
Logger.info(`You can change the config later with ${chalk.blueBright("`npx zksync-cli dev config`")}\n`, {
96+
noFormat: true,
97+
});
9798
}
9899

99100
const modules = await configHandler.getConfigModules();
100101
if (!modules.length) {
101102
Logger.warn("Config does not contain any installed modules.");
102-
Logger.warn("Run `zksync-cli dev config` to select which modules to use.");
103+
Logger.warn("Run `npx zksync-cli dev config` to select which modules to use.");
103104
return;
104105
}
105106

106-
await installModules(modules);
107-
await stopOtherNodes(modules);
108-
await startModules(modules);
109-
await checkForUpdates(modules);
110-
await showStartupInfo(modules);
107+
const sortedModules = [...modules.filter((e) => !e.startAfterNode), ...modules.filter((e) => e.startAfterNode)];
108+
await installModules(sortedModules);
109+
await stopOtherNodes(sortedModules);
110+
await startModules(sortedModules);
111+
await checkForUpdates(sortedModules);
112+
await showStartupInfo(sortedModules);
111113
} catch (error) {
112114
Logger.error("There was an error while starting the testing environment:");
113115
Logger.error(error);

src/commands/dev/update.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const handler = async (moduleNames: string[], options: ModuleUpdateOption
6464
}
6565
}
6666

67-
Logger.info(`\nTo make sure changes are applied use: \`${chalk.magentaBright("zksync-cli dev start")}\``);
67+
Logger.info(`\nTo make sure changes are applied use: \`${chalk.magentaBright("npx zksync-cli dev start")}\``);
6868
} catch (error) {
6969
Logger.error("There was an error while updating module:");
7070
Logger.error(error);

0 commit comments

Comments
 (0)