@botim/botim-cli 0.0.9 → 0.1.0
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 +40 -45
- package/dist/cli.mjs +2 -2
- package/dist/index.js +1 -0
- package/package.json +4 -2
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
{
|
|
3
|
-
const origEmit = process.emit;
|
|
4
|
-
process.emit = function(name, data, ...args) {
|
|
5
|
-
if (name === "warning" && data && data.name === "DeprecationWarning") {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
return origEmit.call(process, name, data, ...args);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
2
|
+
{const _origEmit=process.emit;process.emit=function(n,d,...a){if(n==='warning'&&d&&d.name==='DeprecationWarning')return false;return _origEmit.call(process,n,d,...a);};}
|
|
11
3
|
import { Command } from "commander";
|
|
12
4
|
import { createReactApp, createVueApp, handleLogin, handleLogout, handleQRCode } from "./commands/index.js";
|
|
13
5
|
import { showMenuOrRequireAuth } from "./commands/auth/index.js";
|
|
@@ -52,7 +44,7 @@ async function promptSelect(options) {
|
|
|
52
44
|
process.stdin.removeListener("keypress", onKeypress);
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
|
-
const version = "0.0
|
|
47
|
+
const version = "0.1.0";
|
|
56
48
|
const program = new Command();
|
|
57
49
|
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) => {
|
|
58
50
|
const env = parseEnvironment(value);
|
|
@@ -136,7 +128,7 @@ program.command("status").description("Show login status for all environments").
|
|
|
136
128
|
const prodActive = currentEnv === "production" ? chalk.cyan(" (active)") : "";
|
|
137
129
|
console.log(` ${prodIndicator} Production${prodActive}`);
|
|
138
130
|
if (prodStatus.loggedIn && prodStatus.partnerName) {
|
|
139
|
-
console.log(chalk.gray(`
|
|
131
|
+
console.log(chalk.gray(` Team: ${prodStatus.partnerName}${prodStatus.partnerId ? ` (${prodStatus.partnerId})` : ""}`));
|
|
140
132
|
} else if (!prodStatus.loggedIn) {
|
|
141
133
|
console.log(chalk.gray(" Not logged in"));
|
|
142
134
|
}
|
|
@@ -146,7 +138,7 @@ program.command("status").description("Show login status for all environments").
|
|
|
146
138
|
const uatActive = currentEnv === "uat" ? chalk.cyan(" (active)") : "";
|
|
147
139
|
console.log(` ${uatIndicator} UAT${uatActive}`);
|
|
148
140
|
if (uatStatus.loggedIn && uatStatus.partnerName) {
|
|
149
|
-
console.log(chalk.gray(`
|
|
141
|
+
console.log(chalk.gray(` Team: ${uatStatus.partnerName}${uatStatus.partnerId ? ` (${uatStatus.partnerId})` : ""}`));
|
|
150
142
|
} else if (!uatStatus.loggedIn) {
|
|
151
143
|
console.log(chalk.gray(" Not logged in"));
|
|
152
144
|
}
|
|
@@ -156,14 +148,14 @@ program.command("status").description("Show login status for all environments").
|
|
|
156
148
|
const betaActive = currentEnv === "beta" ? chalk.cyan(" (active)") : "";
|
|
157
149
|
console.log(` ${betaIndicator} Beta${betaActive}`);
|
|
158
150
|
if (betaStatus.loggedIn && betaStatus.partnerName) {
|
|
159
|
-
console.log(chalk.gray(`
|
|
151
|
+
console.log(chalk.gray(` Team: ${betaStatus.partnerName}${betaStatus.partnerId ? ` (${betaStatus.partnerId})` : ""}`));
|
|
160
152
|
} else if (!betaStatus.loggedIn) {
|
|
161
153
|
console.log(chalk.gray(" Not logged in"));
|
|
162
154
|
}
|
|
163
155
|
console.log("");
|
|
164
156
|
console.log(chalk.gray("Tips:"));
|
|
165
157
|
console.log(chalk.gray(" Switch environment: botim-cli config set env uat"));
|
|
166
|
-
console.log(chalk.gray(" Switch
|
|
158
|
+
console.log(chalk.gray(" Switch team: botim-cli switch-partner"));
|
|
167
159
|
console.log(chalk.gray(" One-time override: botim-cli --env beta <command>"));
|
|
168
160
|
console.log(chalk.gray(" Login to beta: botim-cli --env beta login\n"));
|
|
169
161
|
});
|
|
@@ -388,7 +380,7 @@ program.command("debug-mp-app").description("Debug MP app (requires authenticati
|
|
|
388
380
|
process.exit(1);
|
|
389
381
|
}
|
|
390
382
|
});
|
|
391
|
-
program.command("switch-partner [partner-id]").description("Switch to a different
|
|
383
|
+
program.command("switch-partner [partner-id]").description("Switch to a different team without re-login").alias("sp").action(async (partnerId) => {
|
|
392
384
|
try {
|
|
393
385
|
const currentEnv = await getCurrentEnvironment();
|
|
394
386
|
const envDisplay = getEnvironmentDisplayName(currentEnv);
|
|
@@ -401,31 +393,31 @@ program.command("switch-partner [partner-id]").description("Switch to a differen
|
|
|
401
393
|
}
|
|
402
394
|
const userToken = await getUserToken(currentEnv);
|
|
403
395
|
if (!userToken) {
|
|
404
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F No user token available. Please login again to enable
|
|
396
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F No user token available. Please login again to enable team switching.\n"));
|
|
405
397
|
console.log(chalk.gray("Run: botim-cli login\n"));
|
|
406
398
|
process.exit(1);
|
|
407
399
|
}
|
|
408
400
|
let selectedPartnerId = partnerId;
|
|
409
401
|
if (!selectedPartnerId) {
|
|
410
402
|
const ora = (await import("ora")).default;
|
|
411
|
-
const spinner = ora("Fetching
|
|
403
|
+
const spinner = ora("Fetching team list...").start();
|
|
412
404
|
let partnerList;
|
|
413
405
|
try {
|
|
414
406
|
partnerList = await fetchPartners({ userToken, env: currentEnv });
|
|
415
|
-
spinner.succeed("
|
|
407
|
+
spinner.succeed("Team list fetched");
|
|
416
408
|
} catch (error) {
|
|
417
|
-
spinner.fail("Failed to fetch
|
|
418
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F Could not fetch
|
|
409
|
+
spinner.fail("Failed to fetch team list");
|
|
410
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F Could not fetch team list. Your session may have expired.\n"));
|
|
419
411
|
console.log(chalk.gray("Run: botim-cli login\n"));
|
|
420
412
|
process.exit(1);
|
|
421
413
|
}
|
|
422
414
|
if (!partnerList || partnerList.length === 0) {
|
|
423
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F No
|
|
415
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F No teams found for your account.\n"));
|
|
424
416
|
process.exit(1);
|
|
425
417
|
}
|
|
426
418
|
const currentPartnerId2 = await getPartnerId(currentEnv);
|
|
427
419
|
const selected = await promptSelect({
|
|
428
|
-
message: "Select a
|
|
420
|
+
message: "Select a team:",
|
|
429
421
|
choices: partnerList.map((p) => ({
|
|
430
422
|
name: `${p.partnerInfo?.company_name || p.partner_id} (${p.partner_id})${p.partner_id === currentPartnerId2 ? chalk.cyan(" \u2190 current") : ""}`,
|
|
431
423
|
value: p.partner_id
|
|
@@ -443,18 +435,18 @@ program.command("switch-partner [partner-id]").description("Switch to a differen
|
|
|
443
435
|
if (selectedPartnerId === currentPartnerId) {
|
|
444
436
|
const currentPartnerName = await getPartnerName(currentEnv);
|
|
445
437
|
console.log(chalk.gray(`
|
|
446
|
-
Already using
|
|
438
|
+
Already using team: ${currentPartnerName || selectedPartnerId}
|
|
447
439
|
`));
|
|
448
440
|
return;
|
|
449
441
|
}
|
|
450
442
|
const result = await switchToPartner(selectedPartnerId, currentEnv);
|
|
451
443
|
if (result.success) {
|
|
452
444
|
console.log(chalk.green(`
|
|
453
|
-
\u2713 Switched to
|
|
445
|
+
\u2713 Switched to team: ${result.partnerName}
|
|
454
446
|
`));
|
|
455
447
|
} else if (result.error === "partner-not-found") {
|
|
456
448
|
console.log(chalk.red(`
|
|
457
|
-
\u274C
|
|
449
|
+
\u274C Team ${selectedPartnerId} not found in your team list.
|
|
458
450
|
`));
|
|
459
451
|
process.exit(1);
|
|
460
452
|
} else if (result.error === "no-user-token" || result.error === "user-token-expired") {
|
|
@@ -462,12 +454,12 @@ Already using partner: ${currentPartnerName || selectedPartnerId}
|
|
|
462
454
|
console.log(chalk.gray("Run: botim-cli login\n"));
|
|
463
455
|
process.exit(1);
|
|
464
456
|
} else {
|
|
465
|
-
console.log(chalk.red("\n\u274C Failed to switch
|
|
457
|
+
console.log(chalk.red("\n\u274C Failed to switch team. Please try logging in again.\n"));
|
|
466
458
|
process.exit(1);
|
|
467
459
|
}
|
|
468
460
|
} catch (error) {
|
|
469
461
|
logger.error("switch-partner command failed", error);
|
|
470
|
-
displayErrorSync(error, "Switch
|
|
462
|
+
displayErrorSync(error, "Switch team failed");
|
|
471
463
|
process.exit(1);
|
|
472
464
|
}
|
|
473
465
|
});
|
|
@@ -718,7 +710,7 @@ async function showMainMenu() {
|
|
|
718
710
|
console.log(chalk.cyan.bold(`\u2551 v${version.padEnd(32)}\u2551`));
|
|
719
711
|
console.log(chalk.cyan.bold(`\u2551 Environment: ${envColor(envDisplay.padEnd(27))}\u2551`));
|
|
720
712
|
if (currentPartnerName) {
|
|
721
|
-
console.log(chalk.cyan.bold(`\u2551
|
|
713
|
+
console.log(chalk.cyan.bold(`\u2551 Team: ${chalk.white(currentPartnerName.padEnd(34))}\u2551`));
|
|
722
714
|
}
|
|
723
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"));
|
|
724
716
|
const loggedIn = await isLoggedIn();
|
|
@@ -729,12 +721,15 @@ async function showMainMenu() {
|
|
|
729
721
|
const currentDir = process.cwd();
|
|
730
722
|
const configFilePath = getConfigPath(currentDir, currentEnv);
|
|
731
723
|
const hasConfigFile = await fs.pathExists(configFilePath);
|
|
724
|
+
const { findAvailableConfigs } = await import("./utils/config-sync.js");
|
|
725
|
+
const availableConfigs = await findAvailableConfigs(currentDir);
|
|
726
|
+
const hasAnyConfigFile = availableConfigs.length > 0;
|
|
732
727
|
const filteredCommands = commands.filter((cmd) => {
|
|
733
728
|
if (cmd.hideFromMenu) {
|
|
734
729
|
return false;
|
|
735
730
|
}
|
|
736
731
|
if (cmd.name === "deploy-mp-app" || cmd.name === "debug-mp-app") {
|
|
737
|
-
return
|
|
732
|
+
return hasAnyConfigFile;
|
|
738
733
|
}
|
|
739
734
|
if (cmd.name === "create-mp-app" || cmd.name === "register-mp-app") {
|
|
740
735
|
return !hasConfigFile;
|
|
@@ -747,7 +742,7 @@ async function showMainMenu() {
|
|
|
747
742
|
}));
|
|
748
743
|
}
|
|
749
744
|
const unauthenticatedChoices = [
|
|
750
|
-
{ name: "\u{1F4F1} Create a Mini-Program (Local)", value: "mini-program" },
|
|
745
|
+
{ name: "\u{1F4F1} Create a Mini-Program Template (Local)", value: "mini-program" },
|
|
751
746
|
{ name: "\u{1F510} Login", value: "login" },
|
|
752
747
|
{ name: "\u{1F504} Switch Environment", value: "switch-env" },
|
|
753
748
|
{ name: "\u{1F4CA} View Status", value: "status" },
|
|
@@ -757,9 +752,9 @@ async function showMainMenu() {
|
|
|
757
752
|
];
|
|
758
753
|
authenticatedChoices = [
|
|
759
754
|
...authenticatedChoices,
|
|
760
|
-
{ name: "\u{1F4F1} Create a Mini-Program (Local)", value: "mini-program" },
|
|
755
|
+
{ name: "\u{1F4F1} Create a Mini-Program Template (Local)", value: "mini-program" },
|
|
761
756
|
{ name: "\u{1F504} Switch Environment", value: "switch-env" },
|
|
762
|
-
{ name: "\u{
|
|
757
|
+
{ name: "\u{1F465} Switch Team", value: "switch-partner" },
|
|
763
758
|
{ name: "\u{1F4CA} View Status", value: "status" },
|
|
764
759
|
{ name: "\u{1F6AA} Logout", value: "logout" },
|
|
765
760
|
{ name: "\u{1F4DA} View examples", value: "examples" },
|
|
@@ -848,30 +843,30 @@ async function showMainMenu() {
|
|
|
848
843
|
} else if (action === "switch-partner") {
|
|
849
844
|
const userToken = await getUserToken(currentEnv);
|
|
850
845
|
if (!userToken) {
|
|
851
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F No user token available. Please login again to enable
|
|
846
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F No user token available. Please login again to enable team switching.\n"));
|
|
852
847
|
await showMainMenu();
|
|
853
848
|
return;
|
|
854
849
|
}
|
|
855
850
|
const ora = (await import("ora")).default;
|
|
856
|
-
const spinner = ora("Fetching
|
|
851
|
+
const spinner = ora("Fetching team list...").start();
|
|
857
852
|
let partnerList;
|
|
858
853
|
try {
|
|
859
854
|
partnerList = await fetchPartners({ userToken, env: currentEnv });
|
|
860
|
-
spinner.succeed("
|
|
855
|
+
spinner.succeed("Team list fetched");
|
|
861
856
|
} catch {
|
|
862
|
-
spinner.fail("Failed to fetch
|
|
863
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F Could not fetch
|
|
857
|
+
spinner.fail("Failed to fetch team list");
|
|
858
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F Could not fetch team list. Your session may have expired.\n"));
|
|
864
859
|
await showMainMenu();
|
|
865
860
|
return;
|
|
866
861
|
}
|
|
867
862
|
if (!partnerList || partnerList.length === 0) {
|
|
868
|
-
console.log(chalk.yellow("\n\u26A0\uFE0F No
|
|
863
|
+
console.log(chalk.yellow("\n\u26A0\uFE0F No teams found for your account.\n"));
|
|
869
864
|
await showMainMenu();
|
|
870
865
|
return;
|
|
871
866
|
}
|
|
872
867
|
const currentPartnerId = await getPartnerId(currentEnv);
|
|
873
868
|
const selectedPartnerId = await promptSelect({
|
|
874
|
-
message: "Select a
|
|
869
|
+
message: "Select a team:",
|
|
875
870
|
choices: partnerList.map((p) => ({
|
|
876
871
|
name: `${p.partnerInfo?.company_name || p.partner_id} (${p.partner_id})${p.partner_id === currentPartnerId ? chalk.cyan(" \u2190 current") : ""}`,
|
|
877
872
|
value: p.partner_id
|
|
@@ -880,18 +875,18 @@ async function showMainMenu() {
|
|
|
880
875
|
if (selectedPartnerId === null) {
|
|
881
876
|
await showMainMenu();
|
|
882
877
|
} else if (selectedPartnerId === currentPartnerId) {
|
|
883
|
-
console.log(chalk.gray("\nAlready using this
|
|
878
|
+
console.log(chalk.gray("\nAlready using this team.\n"));
|
|
884
879
|
await showMainMenu();
|
|
885
880
|
} else {
|
|
886
881
|
const result = await switchToPartner(selectedPartnerId, currentEnv);
|
|
887
882
|
if (result.success) {
|
|
888
883
|
console.log(chalk.green(`
|
|
889
|
-
\u2713 Switched to
|
|
884
|
+
\u2713 Switched to team: ${result.partnerName}
|
|
890
885
|
`));
|
|
891
886
|
} else if (result.error === "no-user-token" || result.error === "user-token-expired") {
|
|
892
887
|
console.log(chalk.yellow("\n\u26A0\uFE0F Your session has expired. Please login again.\n"));
|
|
893
888
|
} else {
|
|
894
|
-
console.log(chalk.red("\n\u274C Failed to switch
|
|
889
|
+
console.log(chalk.red("\n\u274C Failed to switch team.\n"));
|
|
895
890
|
}
|
|
896
891
|
await showMainMenu();
|
|
897
892
|
}
|
|
@@ -907,21 +902,21 @@ async function showMainMenu() {
|
|
|
907
902
|
const prodActive = currentEnv === "production" ? chalk.cyan(" (active)") : "";
|
|
908
903
|
console.log(` ${prodIndicator} Production${prodActive}`);
|
|
909
904
|
if (prodStatus.loggedIn && prodStatus.partnerName) {
|
|
910
|
-
console.log(chalk.gray(`
|
|
905
|
+
console.log(chalk.gray(` Team: ${prodStatus.partnerName}${prodStatus.partnerId ? ` (${prodStatus.partnerId})` : ""}`));
|
|
911
906
|
}
|
|
912
907
|
const uatStatus = allStatus.uat;
|
|
913
908
|
const uatIndicator = uatStatus.loggedIn ? chalk.green("\u2713") : chalk.red("\u2717");
|
|
914
909
|
const uatActive = currentEnv === "uat" ? chalk.cyan(" (active)") : "";
|
|
915
910
|
console.log(` ${uatIndicator} UAT${uatActive}`);
|
|
916
911
|
if (uatStatus.loggedIn && uatStatus.partnerName) {
|
|
917
|
-
console.log(chalk.gray(`
|
|
912
|
+
console.log(chalk.gray(` Team: ${uatStatus.partnerName}${uatStatus.partnerId ? ` (${uatStatus.partnerId})` : ""}`));
|
|
918
913
|
}
|
|
919
914
|
const betaStatus = allStatus.beta;
|
|
920
915
|
const betaIndicator = betaStatus.loggedIn ? chalk.green("\u2713") : chalk.red("\u2717");
|
|
921
916
|
const betaActive = currentEnv === "beta" ? chalk.cyan(" (active)") : "";
|
|
922
917
|
console.log(` ${betaIndicator} Beta${betaActive}`);
|
|
923
918
|
if (betaStatus.loggedIn && betaStatus.partnerName) {
|
|
924
|
-
console.log(chalk.gray(`
|
|
919
|
+
console.log(chalk.gray(` Team: ${betaStatus.partnerName}${betaStatus.partnerId ? ` (${betaStatus.partnerId})` : ""}`));
|
|
925
920
|
}
|
|
926
921
|
console.log("");
|
|
927
922
|
await showMainMenu();
|