@gabortorma/mwm
Version:
Multi-repo Workspace Manager
74 lines (70 loc) • 2.3 kB
JavaScript
import { defineCommand } from 'citty';
import { consola } from 'consola';
import { getWorkspaces } from 'workspace-tools';
import { c as checkCancel } from '../shared/mwm.CyrEUDRq.mjs';
import { releaseWorkspaces } from '../commands/release/release.mjs';
import 'node:process';
import '../shared/mwm.BwrzNYCL.mjs';
import 'node:child_process';
import 'node:path';
import 'compare-versions';
function getValidWorkspaces() {
const workspaces = getWorkspaces(".");
if (workspaces.length === 0)
consola.error("There are no workspaces in this repository");
return workspaces.map((w) => w.name);
}
function getCheckedWorkspaces(workspaces, validWorkspaces) {
const workspaceSet = /* @__PURE__ */ new Set();
for (const workspace of workspaces) {
if (validWorkspaces.includes(workspace))
workspaceSet.add(workspace);
else
consola.warn(`${workspace} workspace not found. Skipping...`);
}
return workspaceSet;
}
async function getSelectedWorkspaces(filter) {
const validWorkspaces = getValidWorkspaces();
if (typeof filter === "string")
return getCheckedWorkspaces([filter], validWorkspaces);
if (Array.isArray(filter))
return getCheckedWorkspaces(filter, validWorkspaces);
const workspaces = await consola.prompt("Select workspaces", {
type: "multiselect",
options: validWorkspaces
});
checkCancel(workspaces);
return new Set(workspaces);
}
async function selectWorkspaces(filter) {
const selectedWorkspaces = await getSelectedWorkspaces(filter);
if (selectedWorkspaces.size === 0) {
consola.error("No workspace selected");
} else {
consola.info("Selected workspaces:", ...selectedWorkspaces);
}
return selectedWorkspaces;
}
const main = defineCommand({
meta: {
name: "release",
description: "Release selected workspaces"
},
args: {
filter: {
type: "string",
description: "Select workspace"
},
releaseDependencies: {
alias: ["release-dependencies", "rd"],
type: "boolean",
description: "Release all dependencies of selected workspaces"
}
},
async run({ args: { filter, releaseDependencies } }) {
const selectedWorkspaces = await selectWorkspaces(filter);
await releaseWorkspaces(selectedWorkspaces, releaseDependencies);
}
});
export { main };