Skip to content

Commit

Permalink
feat: recursive reload (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongaar authored Jun 2, 2023
1 parent d80ac8a commit 8f0d90c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/reinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
installPluginTask,
isMonorepo,
loadAllPlugins,
loadPluginsTask,
task,
updateDependenciesTask,
warning,
Expand Down Expand Up @@ -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 });
Expand Down
27 changes: 26 additions & 1 deletion packages/cli/src/commands/reload.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,47 @@
import {
formatTask,
getWorkspaces,
isMonorepo,
loadAllPlugins,
loadPluginsTask,
task,
updateDependenciesTask,
} from "@mokr/core";
import { command } from "bandersnatch";
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 });
Expand Down

0 comments on commit 8f0d90c

Please sign in to comment.