Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recursive reload #180

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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