Skip to content

Commit

Permalink
fix: create modules path before running npm commands
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Oct 11, 2023
1 parent 395f0e0 commit 3d8bccc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/commands/dev/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from "chalk";
import { Option } from "commander";

import Program from "./command.js";
import { modulesPath } from "./modules/Module.js";
import { createModulesFolder, modulesPath } from "./modules/Module.js";
import { track } from "../../utils/analytics.js";
import { executeCommand } from "../../utils/helpers.js";
import Logger from "../../utils/logger.js";
Expand All @@ -11,13 +11,15 @@ const linkOption = new Option("--link", "Use `npm link` instead of `npm install`

export const handler = async (moduleNames: string[], options: { link: boolean }) => {
try {
createModulesFolder();

const command = options.link ? "npm link" : "npm install";
const fullCommand = `${command}${moduleNames.length ? ` ${moduleNames.join(" ")}` : ""}`;
await executeCommand(fullCommand, { cwd: modulesPath });

if (moduleNames.length) {
Logger.info(
`Add module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
`\nAdd module${moduleNames.length > 1 ? "s" : ""} to your configuration with \`${chalk.magentaBright(
"zksync-cli dev config"
)}\``
);
Expand Down
7 changes: 7 additions & 0 deletions src/commands/dev/modules/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export type DefaultModuleFields = {

export const modulesPath = getLocalPath("modules");

export const createModulesFolder = () => {
if (fileOrDirExists(modulesPath)) {
return;
}
fs.mkdirSync(modulesPath, { recursive: true });
};

type ModuleConfigDefault = Record<string, unknown>;
abstract class Module<TModuleConfig = ModuleConfigDefault> {
configHandler: ConfigHandler;
Expand Down
4 changes: 3 additions & 1 deletion src/commands/dev/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Option } from "commander";
import { cleanModule } from "./clean.js";
import Program from "./command.js";
import configHandler from "./ConfigHandler.js";
import { modulesPath } from "./modules/Module.js";
import { createModulesFolder, modulesPath } from "./modules/Module.js";
import { findDefaultModules } from "./modules/utils/packages.js";
import { track } from "../../utils/analytics.js";
import { executeCommand } from "../../utils/helpers.js";
Expand All @@ -27,6 +27,8 @@ export const handler = async (moduleNames: string[], options: { unlink: boolean
const modules = await configHandler.getAllModules();
await Promise.all(modules.filter((e) => moduleNames.includes(e.package.name)).map((module) => cleanModule(module)));

createModulesFolder();

const command = options.unlink ? "npm unlink" : "npm uninstall";
const fullCommand = `${command}${moduleNames.length ? ` ${moduleNames.join(" ")}` : ""}`;

Expand Down
4 changes: 3 additions & 1 deletion src/commands/dev/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Option } from "commander";

import Program from "./command.js";
import configHandler from "./ConfigHandler.js";
import { modulesPath } from "./modules/Module.js";
import { createModulesFolder, modulesPath } from "./modules/Module.js";
import { track } from "../../utils/analytics.js";
import { executeCommand } from "../../utils/helpers.js";
import Logger from "../../utils/logger.js";
Expand All @@ -19,6 +19,8 @@ type ModuleUpdateOptions = {
export const handler = async (moduleNames: string[], options: ModuleUpdateOptions = {}) => {
try {
if (options.package) {
createModulesFolder();

Logger.info(`Updating NPM packages: ${moduleNames.join(", ")}`);
const fullCommand = `npm update${moduleNames.length ? ` ${moduleNames.join(" ")}` : ""}`;

Expand Down

0 comments on commit 3d8bccc

Please sign in to comment.