Skip to content

Commit

Permalink
feat(cli): prompt to update all Refine dependencies (#5947)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemir authored and BatuhanW committed Jun 4, 2024
1 parent 8d9ce12 commit 429009d
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 180 deletions.
9 changes: 9 additions & 0 deletions .changeset/brave-chicken-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@refinedev/cli": patch
"@refinedev/devtools-server": patch
"@refinedev/devtools-ui": patch
---

fix: capitalize Refine

Capitalized "Refine" in the user-facing texts
7 changes: 7 additions & 0 deletions .changeset/poor-adults-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@refinedev/cli": patch
---

feat(cli): prompt to update all in `update` command

Previously, if users doesn't provide `--all` option, `update` command will display an interactive prompt to pick which packages to update. Now, before displaying the prompt, it will ask if users want to update all packages.
5 changes: 2 additions & 3 deletions packages/cli/ANNOUNCEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ hidden: false

---

refine Devtools beta version is out! To install in your project, just run `npm run refine devtools init`. https://s.refine.dev/devtools-beta
---
## Refine Devtools beta version is out! To install in your project, just run `npm run refine devtools init`. https://s.refine.dev/devtools-beta

---announcement
hidden: false

---

Hello from refine team! Hope you enjoy! Join our Discord community to get help and discuss with other users. https://discord.gg/refine
Hello from Refine team! Hope you enjoy! Join our Discord community to get help and discuss with other users. https://discord.gg/refine

---
10 changes: 5 additions & 5 deletions packages/cli/src/commands/check-updates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import semverDiff from "semver-diff";
const load = (program: Command) => {
return program
.command("check-updates")
.description("Check all installed `refine` packages are up to date")
.description("Check all installed `Refine` packages are up to date")
.action(action);
};

const action = async () => {
const packages = await spinner(isRefineUptoDate, "Checking for updates...");
if (!packages.length) {
console.log("All `refine` packages are up to date 🎉\n");
console.log("All `Refine` packages are up to date 🎉\n");
return;
}

Expand All @@ -28,9 +28,9 @@ const action = async () => {

/**
*
* @returns `refine` packages that have updates.
* @returns `[]` if no refine package found.
* @returns `[]` if all `refine` packages are up to date.
* @returns `Refine` packages that have updates.
* @returns `[]` if no Refine package found.
* @returns `[]` if all `Refine` packages are up to date.
*/
export const isRefineUptoDate = async () => {
const refinePackages = await getOutdatedRefinePackages();
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/src/commands/devtools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const load = (program: Command) => {
return program
.command("devtools")
.description(
"Start or install refine's devtools server; it starts on port 5001.",
"Start or install Refine Devtools server; it starts on port 5001.",
)
.addArgument(
new Argument("[command]", "devtools related commands")
Expand All @@ -38,8 +38,8 @@ const load = (program: Command) => {
"after",
`
Commands:
start Start refine's devtools server
init Install refine's devtools client and adds it to your project
start Start Refine Devtools server
init Install Refine Devtools client and adds it to your project
`,
)
.action(action);
Expand All @@ -64,7 +64,7 @@ const devtoolsInstaller = async () => {
"Checking if devtools is installed...",
);
if (isInstalled) {
console.log("🎉 refine devtools is already installed");
console.log("🎉 Refine Devtools is already installed");
return;
}

Expand All @@ -75,15 +75,15 @@ const devtoolsInstaller = async () => {
return;
}

console.log("🌱 Installing refine devtools...");
console.log("🌱 Installing Refine Devtools...");
const packagesToInstall = ["@refinedev/devtools@latest"];
// we should update core package if it is lower than minRefineCoreVersionForDevtools
if (
!corePackage ||
semver.lt(corePackage.version, minRefineCoreVersionForDevtools)
) {
packagesToInstall.push("@refinedev/core@latest");
console.log("🌱 refine core package is being updated for devtools...");
console.log("🌱 Refine core package is being updated for devtools...");
}
await installPackagesSync(packagesToInstall);

Expand All @@ -94,13 +94,13 @@ const devtoolsInstaller = async () => {
console.log("🌱 Adding devtools component to your project....");
await addDevtoolsComponent();
console.log(
"✅ refine devtools package and components added to your project",
"✅ Refine Devtools package and components added to your project",
);
// if core package is updated, we should show the updated version
if (packagesToInstall.includes("@refinedev/core@latest")) {
const updatedCorePackage = await getRefineCorePackage();
console.log(
`✅ refine core package updated from ${
`✅ Refine core package updated from ${
corePackage?.version ?? "unknown"
} to ${updatedCorePackage?.version ?? "unknown"}`,
);
Expand Down Expand Up @@ -176,7 +176,7 @@ export const devtoolsRunner = async ({

if (semver.lt(corePackage.version, minRefineCoreVersionForDevtools)) {
console.log(
`🚨 You're using an old version of refine(${corePackage.version}). refine version should be @4.42.0 or higher to use devtools.`,
`🚨 You're using an old version of Refine(${corePackage.version}). Refine version should be @4.42.0 or higher to use devtools.`,
);
const pm = await getPreferedPM();
console.log(
Expand Down Expand Up @@ -217,9 +217,9 @@ export const validateCorePackageIsNotDeprecated = async ({
}) => {
if (pkg.name === "@pankod/refine-core" || semver.lt(pkg.version, "4.0.0")) {
console.log(
`🚨 You're using an old version of refine(${pkg.version}). refine version should be @4.42.0 or higher to use devtools.`,
`🚨 You're using an old version of Refine(${pkg.version}). Refine version should be @4.42.0 or higher to use devtools.`,
);
console.log("You can follow migration guide to update refine.");
console.log("You can follow migration guide to update Refine.");
console.log(
chalk.blue("https://refine.dev/docs/migration-guide/3x-to-4x/"),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/runner/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const dev = (program: Command) => {
.addOption(
new Option(
"-d, --devtools <devtools>",
"Start refine's devtools server",
"Start Refine Devtools server",
).default("true", "true if devtools is installed"),
)
.argument("[args...]")
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/runner/projectScripts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProjectTypes } from "@definitions/projectTypes";

/**
* Map `refine` cli commands to project script
* Map `Refine` cli commands to project script
*/
export const projectScripts = {
[ProjectTypes.REACT_SCRIPT]: {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/swizzle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const swizzle = (program: Command) => {
.command("swizzle")
.description(
`Export a component or a function from ${chalk.bold(
"refine",
"Refine",
)} packages to customize it in your project`,
)
.action(action);
Expand Down Expand Up @@ -86,7 +86,7 @@ const action = async (_options: OptionValues) => {
);

if (packagesWithConfig.length === 0) {
console.log("No refine packages found with swizzle configuration.");
console.log("No Refine packages found with swizzle configuration.");
return;
}

Expand All @@ -95,7 +95,7 @@ const action = async (_options: OptionValues) => {
`Found ${chalk.blueBright(
packagesWithConfig.length,
)} installed ${chalk.blueBright.bold(
"refine",
"Refine",
)} packages with swizzle configuration.`,
{
padding: 1,
Expand Down
55 changes: 45 additions & 10 deletions packages/cli/src/commands/update/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import inquirer from "inquirer";
import center from "center-align";
import { Command, Option } from "commander";
import { isRefineUptoDate } from "@commands/check-updates";
import spinner from "@utils/spinner";
import { isRefineUptoDate } from "@commands/check-updates";
import { getPreferedPM, installPackages, pmCommands } from "@utils/package";
import { promptInteractiveRefineUpdate } from "@commands/update/interactive";
import { RefinePackageInstalledVersionData } from "@definitions/package";
import { getVersionTable } from "@components/version-table";

enum Tag {
Wanted = "wanted",
Expand All @@ -21,7 +24,7 @@ const load = (program: Command) => {
return program
.command("update")
.description(
"Interactively select and update all `refine` packages to selected version. To skip the interactive mode, use the `--all` option.",
"Interactively select and update all `Refine` packages to selected version. To skip the interactive mode, use the `--all` option.",
)
.addOption(
new Option("-t, --tag [tag]", "Select version to update to.")
Expand All @@ -33,7 +36,7 @@ const load = (program: Command) => {
)
.option(
"-a, --all",
"Update all `refine` packages to the selected `tag`. If `tag` is not provided, version ranges in the `package.json` will be installed. This option skips the interactive mode.",
"Update all `Refine` packages to the selected `tag`. If `tag` is not provided, version ranges in the `package.json` will be installed. This option skips the interactive mode.",
false,
)
.option(
Expand All @@ -49,13 +52,45 @@ const action = async (options: OptionValues) => {

const packages = await spinner(isRefineUptoDate, "Checking for updates...");
if (!packages?.length) {
console.log("All `refine` packages are up to date 🎉");
console.log("All `Refine` packages are up to date 🎉");
return;
}

const selectedPackages = all
? runAll(tag, packages)
: await promptInteractiveRefineUpdate(packages);
let selectedPackages: string[] | null | undefined = null;

if (all) {
runAll(tag, packages);
} else {
const { table, width } = getVersionTable(packages) ?? "";

console.log(center("Available Updates", width));
console.log(table);

const { allByPrompt } = await inquirer.prompt<{ allByPrompt: boolean }>([
{
type: "list",
name: "allByPrompt",
message:
"Do you want to update all Refine packages for minor and patch versions?",
choices: [
{
name: "Yes (Recommended)",
value: true,
},
{
name: "No, use interactive mode",
value: false,
},
],
},
]);

if (allByPrompt) {
selectedPackages = runAll(tag, packages);
} else {
selectedPackages = await promptInteractiveRefineUpdate(packages);
}
}

if (!selectedPackages) return;

Expand All @@ -74,7 +109,7 @@ const runAll = (tag: Tag, packages: RefinePackageInstalledVersionData[]) => {
);
if (isAllPackagesAtWantedVersion) {
console.log(
"All `refine` packages are up to date with the wanted version 🎉",
"All `Refine` packages are up to date with the wanted version 🎉",
);
return null;
}
Expand All @@ -95,8 +130,8 @@ const printInstallCommand = async (packages: string[]) => {
};

const pmInstall = (packages: string[]) => {
console.log("Updating `refine` packages...");
console.log(packages);
console.log("Updating `Refine` packages...");
console.log(packages.map((pkg) => ` - ${pkg}`).join("\n"));
installPackages(packages);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/update/interactive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const promptInteractiveRefineUpdate = async (
) => {
const uiGroup = createUIGroup(packages);
if (!uiGroup) {
console.log("All `refine` packages are up to date. 🎉");
console.log("All `Refine` packages are up to date. 🎉");
return;
}

Expand Down

0 comments on commit 429009d

Please sign in to comment.