@botim/botim-cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -11,6 +11,7 @@ import { executeWithAuthRetry } from "./utils/auth-handler.js";
11
11
  import { getConfigPath } from "./utils/config-sync.js";
12
12
  import { switchToPartner } from "./utils/partner-switch.js";
13
13
  import { fetchPartners } from "./utils/auth-api.js";
14
+ import { checkForUpdates, getUpdateCommand, runUpdate } from "./utils/update-checker.js";
14
15
  import { select } from "@inquirer/prompts";
15
16
  import chalk from "chalk";
16
17
  import fs from "fs-extra";
@@ -44,7 +45,17 @@ async function promptSelect(options) {
44
45
  process.stdin.removeListener("keypress", onKeypress);
45
46
  }
46
47
  }
47
- const version = "0.1.0";
48
+ const version = "0.1.2";
49
+ let updateInfo = null;
50
+ function displayUpdateBanner(info) {
51
+ if (!info.updateAvailable) return;
52
+ const border = chalk.yellow("\u2500".repeat(50));
53
+ console.log("");
54
+ console.log(border);
55
+ console.log(chalk.yellow(` Update available: ${chalk.gray(info.currentVersion)} \u2192 ${chalk.green.bold(info.latestVersion)}`));
56
+ console.log(chalk.yellow(` Run ${chalk.cyan(getUpdateCommand())} to update`));
57
+ console.log(border);
58
+ }
48
59
  const program = new Command();
49
60
  program.name("botim-cli").description("CLI tool to generate boilerplate code for React and Vue applications").version(version, "-v, --version", "Output the current version").option("--env <environment>", "Target environment: prod, uat, or beta (overrides default)", (value) => {
50
61
  const env = parseEnvironment(value);
@@ -670,6 +681,32 @@ program.command("clear-template-cache").description("Clear cached templates to f
670
681
  process.exit(1);
671
682
  }
672
683
  });
684
+ program.command("update").description("Update Botim CLI to the latest version").action(async () => {
685
+ console.log(chalk.cyan.bold(`
686
+ \u2B06\uFE0F Botim CLI v${version} - Update
687
+ `));
688
+ const info = updateInfo ?? await checkForUpdates();
689
+ if (!info.updateAvailable) {
690
+ console.log(chalk.green(`\u2713 You are already on the latest version (v${info.currentVersion})
691
+ `));
692
+ return;
693
+ }
694
+ console.log(chalk.yellow(`Update available: ${chalk.gray(info.currentVersion)} \u2192 ${chalk.green.bold(info.latestVersion)}
695
+ `));
696
+ console.log(chalk.gray(`Running: ${getUpdateCommand()}
697
+ `));
698
+ const success = runUpdate();
699
+ if (success) {
700
+ console.log(chalk.green(`
701
+ \u2713 Successfully updated to v${info.latestVersion}!
702
+ `));
703
+ } else {
704
+ console.log(chalk.red("\n\u274C Update failed. Try running manually:\n"));
705
+ console.log(chalk.cyan(` ${getUpdateCommand()}
706
+ `));
707
+ process.exit(1);
708
+ }
709
+ });
673
710
  program.command("logs").description("Show log file location or view recent logs").option("-t, --tail <lines>", "Show last N lines of log file", "50").action(async (options) => {
674
711
  const logPath = logger.getLogFilePath();
675
712
  const tailLines = parseInt(options.tail) || 50;
@@ -712,7 +749,11 @@ async function showMainMenu() {
712
749
  if (currentPartnerName) {
713
750
  console.log(chalk.cyan.bold(`\u2551 Team: ${chalk.white(currentPartnerName.padEnd(34))}\u2551`));
714
751
  }
715
- console.log(chalk.cyan.bold("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n"));
752
+ console.log(chalk.cyan.bold("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D"));
753
+ if (updateInfo?.updateAvailable) {
754
+ displayUpdateBanner(updateInfo);
755
+ }
756
+ console.log("");
716
757
  const loggedIn = await isLoggedIn();
717
758
  let authenticatedChoices = [];
718
759
  if (loggedIn) {
@@ -741,11 +782,13 @@ async function showMainMenu() {
741
782
  value: `auth:${cmd.name}`
742
783
  }));
743
784
  }
785
+ const updateChoice = updateInfo?.updateAvailable ? [{ name: `\u2B06\uFE0F Update available (${chalk.gray(updateInfo.currentVersion)} \u2192 ${chalk.green(updateInfo.latestVersion)})`, value: "update" }] : [];
744
786
  const unauthenticatedChoices = [
745
787
  { name: "\u{1F4F1} Create a Mini-Program Template (Local)", value: "mini-program" },
746
788
  { name: "\u{1F510} Login", value: "login" },
747
789
  { name: "\u{1F504} Switch Environment", value: "switch-env" },
748
790
  { name: "\u{1F4CA} View Status", value: "status" },
791
+ ...updateChoice,
749
792
  { name: "\u{1F4DA} View examples", value: "examples" },
750
793
  { name: "\u2753 Show help", value: "help" },
751
794
  { name: "\u{1F6AA} Exit", value: "exit" }
@@ -756,6 +799,7 @@ async function showMainMenu() {
756
799
  { name: "\u{1F504} Switch Environment", value: "switch-env" },
757
800
  { name: "\u{1F465} Switch Team", value: "switch-partner" },
758
801
  { name: "\u{1F4CA} View Status", value: "status" },
802
+ ...updateChoice,
759
803
  { name: "\u{1F6AA} Logout", value: "logout" },
760
804
  { name: "\u{1F4DA} View examples", value: "examples" },
761
805
  { name: "\u2753 Show help", value: "help" },
@@ -932,6 +976,23 @@ async function showMainMenu() {
932
976
  } else if (action === "logout") {
933
977
  await handleLogout({});
934
978
  await showMainMenu();
979
+ } else if (action === "update") {
980
+ console.log(chalk.cyan.bold(`
981
+ \u2B06\uFE0F Updating Botim CLI to v${updateInfo?.latestVersion}...
982
+ `));
983
+ const success = runUpdate();
984
+ if (success) {
985
+ console.log(chalk.green(`
986
+ \u2713 Successfully updated to v${updateInfo?.latestVersion}!
987
+ `));
988
+ console.log(chalk.gray("Please restart the CLI to use the new version.\n"));
989
+ process.exit(0);
990
+ } else {
991
+ console.log(chalk.red("\n\u274C Update failed. Try running manually:\n"));
992
+ console.log(chalk.cyan(` ${getUpdateCommand()}
993
+ `));
994
+ await showMainMenu();
995
+ }
935
996
  } else if (action === "examples") {
936
997
  displayExamples();
937
998
  await showMainMenu();
@@ -948,8 +1009,15 @@ async function showMainMenu() {
948
1009
  process.exit(1);
949
1010
  }
950
1011
  }
951
- if (!process.argv.slice(2).length) {
952
- showMainMenu();
953
- } else {
954
- program.parse(process.argv);
955
- }
1012
+ (async () => {
1013
+ updateInfo = await checkForUpdates();
1014
+ if (!process.argv.slice(2).length) {
1015
+ await showMainMenu();
1016
+ } else {
1017
+ if (updateInfo.updateAvailable) {
1018
+ displayUpdateBanner(updateInfo);
1019
+ console.log("");
1020
+ }
1021
+ program.parse(process.argv);
1022
+ }
1023
+ })();