From 8f0d90c6e445c0aae0500a8ea726c0bee2852116 Mon Sep 17 00:00:00 2001 From: Joram van den Boezem Date: Fri, 2 Jun 2023 12:44:29 +0200 Subject: [PATCH] feat: recursive reload (#180) --- action.yml | 2 +- packages/cli/src/commands/reinstall.ts | 3 ++- packages/cli/src/commands/reload.ts | 27 +++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index c1ed753d..c5fc3b3c 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ description: Reload moker plugins runs: using: "composite" steps: - - run: yarn dlx moker reload + - run: yarn dlx moker reload --recursive shell: bash branding: icon: refresh-cw diff --git a/packages/cli/src/commands/reinstall.ts b/packages/cli/src/commands/reinstall.ts index a2652708..d9455f57 100644 --- a/packages/cli/src/commands/reinstall.ts +++ b/packages/cli/src/commands/reinstall.ts @@ -5,6 +5,7 @@ import { installPluginTask, isMonorepo, loadAllPlugins, + loadPluginsTask, task, updateDependenciesTask, warning, @@ -33,7 +34,7 @@ export const reinstall = command("reinstall") }); } - await task(`Load plugins`, () => loadAllPlugins({ directory })); + await loadPluginsTask({ directory }); if (recursive && (await isMonorepo({ directory }))) { const workspaces = await getWorkspaces({ directory }); diff --git a/packages/cli/src/commands/reload.ts b/packages/cli/src/commands/reload.ts index 91fb418e..fce5e2d3 100644 --- a/packages/cli/src/commands/reload.ts +++ b/packages/cli/src/commands/reload.ts @@ -1,6 +1,10 @@ import { formatTask, + getWorkspaces, + isMonorepo, + loadAllPlugins, loadPluginsTask, + task, updateDependenciesTask, } from "@mokr/core"; import { command } from "bandersnatch"; @@ -8,15 +12,36 @@ import { resolve } from "node:path"; export const reload = command("reload") .description("Reload plugins in repo or workspace") + .option("recursive", { + type: "boolean", + description: "Also reinstalls plugins of all workspaces in a monorepo", + }) .option("cwd", { description: "Directory to use as the current working directory", default: process.cwd(), }) - .action(async ({ cwd }) => { + .action(async ({ recursive, cwd }) => { const directory = resolve(cwd); await loadPluginsTask({ directory }); + if (recursive && (await isMonorepo({ directory }))) { + const workspaces = await getWorkspaces({ directory }); + + for (const workspace of workspaces) { + const workspaceDirectory = resolve(directory, workspace.location); + + // Skip root + if (workspaceDirectory === directory) { + continue; + } + + await task(`Load plugins of ${workspace.name}`, () => + loadAllPlugins({ directory: workspaceDirectory }) + ); + } + } + await updateDependenciesTask({ directory }); await formatTask({ directory });