@reliverse/rse
Version:
@reliverse/rse is your all-in-one companion for bootstrapping and improving any kind of projects (especially web apps built with frameworks like Next.js) — whether you're kicking off something new or upgrading an existing app. It is also a little AI-power
59 lines (58 loc) • 1.81 kB
JavaScript
import { relinka } from "@reliverse/relinka";
import { defineCommand, selectPrompt } from "@reliverse/rempts";
import { execaCommand } from "execa";
import { cliName } from "../../libs/sdk/constants.js";
import {
getAllPkgManagers
} from "../../libs/sdk/utils/dependencies/getUserPkgManager.js";
import { getCurrentWorkingDirectory } from "../../libs/sdk/utils/terminalHelpers.js";
async function getPmOptions() {
const projectPath = getCurrentWorkingDirectory();
const detectedPMs = await getAllPkgManagers(projectPath);
const detectedPMMap = new Map(
detectedPMs.map((pm) => [pm.packageManager, pm.source])
);
const pmOptions = ["bun", "pnpm", "npm", "yarn"].map((pm) => {
const option = {
label: pm,
value: pm
};
const source = detectedPMMap.get(pm);
if (source && source !== "default") {
option.hint = "detected";
}
return option;
});
const defaultValue = [...detectedPMMap.keys()][0] ?? "npm";
return { pmOptions, defaultValue };
}
export default defineCommand({
meta: {
name: "update",
description: "Updates the CLI to the latest version",
hidden: false
},
run: async () => {
try {
const { pmOptions, defaultValue } = await getPmOptions();
const pm = await selectPrompt({
title: `Select a package manager to update the ${cliName}`,
options: pmOptions,
defaultValue
});
await execaCommand(`${pm} -g update --latest`, { stdio: "inherit" });
relinka(
"success",
"Updated successfully!",
"You can now use the latest `rse cli` version."
);
} catch (error) {
relinka(
"error",
"Failed to update @rse",
error instanceof Error ? error.message : "Unknown error"
);
}
process.exit(0);
}
});