Skip to content

Commit

Permalink
feat: update modules, command log changes, installation in correct or…
Browse files Browse the repository at this point in the history
…der (#83)
  • Loading branch information
JackHamer09 authored Nov 22, 2023
1 parent 51f8384 commit 00e1b04
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 44 deletions.
34 changes: 20 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"./lib": "./bin/lib/index.js"
},
"scripts": {
"build": "cross-env NODE_ENV=development tsc -p tsconfig.build.json",
"dev": "ts-node-esm src/index.ts",
"build": "tsc -p tsconfig.build.json",
"dev": "cross-env NODE_ENV=development ts-node-esm src/index.ts",
"typecheck": "tsc -p . --noEmit",
"lint": "eslint . --ext ./src/* --fix --ignore-path .gitignore --no-error-on-unmatched-pattern --max-warnings=0",
"commitlint": "commitlint --edit"
Expand Down Expand Up @@ -44,8 +44,8 @@
"ora": "^7.0.1",
"update-notifier": "^7.0.0",
"winston": "^3.10.0",
"zkcli-block-explorer": "^1.0.2",
"zkcli-dockerized-node": "^1.0.4",
"zkcli-block-explorer": "^1.1.0",
"zkcli-dockerized-node": "^1.0.5",
"zkcli-in-memory-node": "^1.0.3",
"zkcli-portal": "^1.0.1",
"zksync-web3": "^0.14.4"
Expand Down
34 changes: 23 additions & 11 deletions src/commands/dev/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,30 @@ import configHandler from "./ConfigHandler.js";
import { ModuleCategory } from "./modules/Module.js";
import Logger from "../../utils/logger.js";

import type Module from "./modules/Module.js";
import type { ModuleNode } from "./modules/Module.js";

type LocalConfigOptions = {
node?: string;
modules?: string[];
};

const formatModuleName = (module: Module) => {
let name = `${module.name} - ${module.description}`;
if (process.env.NODE_ENV === "development") {
name += chalk.gray(` - ${module.package.name}`);
}
if (module.package.symlinked) {
name += chalk.gray(" (installed via --link)");
}
return name;
};

export const setupConfig = async (options: LocalConfigOptions = {}) => {
const modules = await configHandler.getAllModules();
if (!modules.length) {
Logger.error("No installed modules were found");
Logger.error("Run `zksync-cli dev install [module-name...]` to install modules.");
Logger.error("Run `npx zksync-cli dev install [module-name...]` to install modules.");
return;
}

Expand All @@ -31,7 +43,7 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
type: "list",
when: () => nodes.length > 0,
choices: nodes.map((node) => ({
name: `${node.name} - ${node.description}`,
name: formatModuleName(node),
short: node.name,
value: node.package.name,
})),
Expand All @@ -54,12 +66,12 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
potentialModules.map(async (module) => {
try {
return {
...module,
instance: module,
unsupported: (await module.isNodeSupported(nodeInfo)) ? false : "Module doesn't support selected node",
};
} catch (error) {
return {
...module,
instance: module,
unsupported: "Failed to check node support status",
};
}
Expand All @@ -71,11 +83,11 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
return a.unsupported ? 1 : -1;
}
// If categories are equal, compare by name.
if (a.category === b.category) {
return a.name.localeCompare(b.name);
if (a.instance.category === b.instance.category) {
return a.instance.name.localeCompare(b.instance.name);
}
// Compare by category.
return a.category.localeCompare(b.category);
return a.instance.category.localeCompare(b.instance.category);
});

const modulesAnswers: LocalConfigOptions = await inquirer.prompt(
Expand All @@ -86,9 +98,9 @@ export const setupConfig = async (options: LocalConfigOptions = {}) => {
type: "checkbox",
when: () => sortedModules.length > 0,
choices: sortedModules.map((module) => ({
name: `${module.name} - ${module.description}`,
short: module.name,
value: module.package.name,
name: formatModuleName(module.instance),
short: module.instance.name,
value: module.instance.package.name,
disabled: module.unsupported,
})),
},
Expand Down Expand Up @@ -120,7 +132,7 @@ export const handler = async (options: LocalConfigOptions = {}) => {
await setupConfig(options);

Logger.info("\nConfiguration saved successfully!", { noFormat: true });
Logger.info(`Start configured environment with \`${chalk.magentaBright("zksync-cli dev start")}\``);
Logger.info(`Start configured environment with \`${chalk.magentaBright("npx zksync-cli dev start")}\``);
} catch (error) {
Logger.error("There was an error while configuring the testing environment:");
Logger.error(error);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const handler = async (moduleNames: string[], options: { link: boolean })
if (moduleNames.length) {
Logger.info(
`\nAdd module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
"zksync-cli dev config"
"npx zksync-cli dev config"
)}\``
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const handler = async () => {
const modules = await configHandler.getConfigModules();
if (!modules.length) {
Logger.warn("There are no configured modules");
Logger.info("You can configure them with: `zksync-cli dev config");
Logger.info("You can configure them with: `npx zksync-cli dev config");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const handler = async () => {
const modules = await configHandler.getAllModules();
if (!modules.length) {
Logger.warn("There are no modules installed");
Logger.info("You can install modules with: `zksync-cli dev install [module-name...]");
Logger.info("You can install modules with: `npx zksync-cli dev install [module-name...]");
return;
}

Expand Down
24 changes: 13 additions & 11 deletions src/commands/dev/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const installModules = async (modules: Module[]) => {

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

const stopOtherNodes = async (currentModules: Module[]) => {
Expand Down Expand Up @@ -56,13 +55,13 @@ const checkForUpdates = async (modules: Module[]) => {
if (currentVersion) {
str += chalk.gray(` (current: ${currentVersion})`);
}
str += chalk.gray(` - zksync-cli dev update ${module.package.name}`);
str += chalk.gray(` - npx zksync-cli dev update ${module.package.name}`);
Logger.info(str);
}
if (modulesRequiringUpdates.length > 1) {
Logger.info(
chalk.gray(
`Update all modules: zksync-cli dev update ${modulesRequiringUpdates
`Update all modules: npx zksync-cli dev update ${modulesRequiringUpdates
.map(({ module }) => module.package.name)
.join(" ")}`
)
Expand Down Expand Up @@ -93,21 +92,24 @@ export const handler = async () => {
try {
if (!configHandler.configExists) {
await setupConfig();
Logger.info("");
Logger.info(`You can change the config later with ${chalk.blueBright("`npx zksync-cli dev config`")}\n`, {
noFormat: true,
});
}

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

await installModules(modules);
await stopOtherNodes(modules);
await startModules(modules);
await checkForUpdates(modules);
await showStartupInfo(modules);
const sortedModules = [...modules.filter((e) => !e.startAfterNode), ...modules.filter((e) => e.startAfterNode)];
await installModules(sortedModules);
await stopOtherNodes(sortedModules);
await startModules(sortedModules);
await checkForUpdates(sortedModules);
await showStartupInfo(sortedModules);
} catch (error) {
Logger.error("There was an error while starting the testing environment:");
Logger.error(error);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const handler = async (moduleNames: string[], options: ModuleUpdateOption
}
}

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

0 comments on commit 00e1b04

Please sign in to comment.