gitshift 1.0.1 → 1.0.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/package.json +2 -1
- package/src/commands/add.js +8 -1
- package/src/server.js +123 -62
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitshift",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "GitHub Account Switcher CLI",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"type": "module",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inquirer/prompts": "^8.5.1",
|
|
19
|
+
"axios": "^1.16.1",
|
|
19
20
|
"chalk": "^5.6.2",
|
|
20
21
|
"commander": "^15.0.0",
|
|
21
22
|
"conf": "^15.1.0",
|
package/src/commands/add.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import ora from "ora";
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
+
getProfile,
|
|
9
10
|
saveProfile,
|
|
10
11
|
} from "../services/profile.js";
|
|
11
12
|
|
|
@@ -22,6 +23,12 @@ export async function addCommand() {
|
|
|
22
23
|
message: "Profile Name",
|
|
23
24
|
});
|
|
24
25
|
|
|
26
|
+
if (getProfile(name)) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Profile "${name}" already exists`
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
const username = await input({
|
|
26
33
|
message: "GitHub Username",
|
|
27
34
|
});
|
|
@@ -61,6 +68,6 @@ export async function addCommand() {
|
|
|
61
68
|
});
|
|
62
69
|
|
|
63
70
|
success(
|
|
64
|
-
`Profile "${name}"
|
|
71
|
+
`Profile "${name}" saved locally`
|
|
65
72
|
);
|
|
66
73
|
}
|
package/src/server.js
CHANGED
|
@@ -1,69 +1,130 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import axios from "axios";
|
|
4
|
+
import chalk from "chalk";
|
|
3
5
|
import { Command } from "commander";
|
|
4
|
-
|
|
6
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
5
7
|
import { addCommand } from "./commands/add.js";
|
|
6
|
-
|
|
7
|
-
import { listCommand } from "./commands/list.js";
|
|
8
|
-
|
|
9
8
|
import { currentCommand } from "./commands/current.js";
|
|
10
|
-
|
|
11
|
-
import { useCommand } from "./commands/use.js";
|
|
12
|
-
|
|
13
|
-
import { removeCommand } from "./commands/remove.js";
|
|
14
|
-
|
|
15
9
|
import { doctorCommand } from "./commands/doctor.js";
|
|
10
|
+
import { listCommand } from "./commands/list.js";
|
|
11
|
+
import { removeCommand } from "./commands/remove.js";
|
|
12
|
+
import { useCommand } from "./commands/use.js";
|
|
16
13
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
14
|
+
const { name, version } = packageJson;
|
|
15
|
+
|
|
16
|
+
function printBanner() {
|
|
17
|
+
const logo = String.raw`
|
|
18
|
+
██████╗ ██╗████████╗███████╗██╗ ██╗██╗███████╗████████╗
|
|
19
|
+
██╔════╝ ██║╚══██╔══╝██╔════╝██║ ██║██║██╔════╝╚══██╔══╝
|
|
20
|
+
██║ ███╗██║ ██║ ███████╗███████║██║█████╗ ██║
|
|
21
|
+
██║ ██║██║ ██║ ╚════██║██╔══██║██║██╔══╝ ██║
|
|
22
|
+
╚██████╔╝██║ ██║ ███████║██║ ██║██║██║ ██║
|
|
23
|
+
╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝╚═╝╚═╝ ╚═╝
|
|
24
|
+
`;
|
|
25
|
+
console.log(chalk.cyanBright(logo));
|
|
26
|
+
console.log(chalk.bold("GitShift CLI"));
|
|
27
|
+
console.log(
|
|
28
|
+
chalk.dim("Manage and switch GitHub accounts effortlessly\n")
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function compareVersions(currentVersion, latestVersion) {
|
|
33
|
+
const currentParts = currentVersion.split(".").map(Number);
|
|
34
|
+
const latestParts = latestVersion.split(".").map(Number);
|
|
35
|
+
|
|
36
|
+
for (let index = 0; index < 3; index += 1) {
|
|
37
|
+
const currentPart = currentParts[index] || 0;
|
|
38
|
+
const latestPart = latestParts[index] || 0;
|
|
39
|
+
|
|
40
|
+
if (currentPart > latestPart) return 1;
|
|
41
|
+
if (currentPart < latestPart) return -1;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function checkForUpdates() {
|
|
48
|
+
try {
|
|
49
|
+
const response = await axios.get(
|
|
50
|
+
`https://registry.npmjs.org/${name}/latest`,
|
|
51
|
+
{
|
|
52
|
+
timeout: 3000,
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const latestVersion = response.data.version;
|
|
57
|
+
|
|
58
|
+
if (latestVersion && compareVersions(version, latestVersion) < 0) {
|
|
59
|
+
console.log(
|
|
60
|
+
`A new version of ${name} is available: ${version} -> ${latestVersion}`,
|
|
61
|
+
);
|
|
62
|
+
console.log(`Run: npm install -g ${name}`);
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
// Ignore version check failures so the CLI still starts offline.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function main() {
|
|
70
|
+
printBanner();
|
|
71
|
+
await checkForUpdates();
|
|
72
|
+
|
|
73
|
+
const program = new Command();
|
|
74
|
+
|
|
75
|
+
program
|
|
76
|
+
.name("gitshift")
|
|
77
|
+
.description(
|
|
78
|
+
"GitHub Account Switcher"
|
|
79
|
+
)
|
|
80
|
+
.version(version);
|
|
81
|
+
|
|
82
|
+
program
|
|
83
|
+
.command("add")
|
|
84
|
+
.description(
|
|
85
|
+
"Create local profile"
|
|
86
|
+
)
|
|
87
|
+
.action(addCommand);
|
|
88
|
+
|
|
89
|
+
program
|
|
90
|
+
.command("list")
|
|
91
|
+
.description(
|
|
92
|
+
"List profiles"
|
|
93
|
+
)
|
|
94
|
+
.action(listCommand);
|
|
95
|
+
|
|
96
|
+
program
|
|
97
|
+
.command("current")
|
|
98
|
+
.description(
|
|
99
|
+
"Show active profile"
|
|
100
|
+
)
|
|
101
|
+
.action(currentCommand);
|
|
102
|
+
|
|
103
|
+
program
|
|
104
|
+
.command("use <profile>")
|
|
105
|
+
.description(
|
|
106
|
+
"Switch profile and update git config"
|
|
107
|
+
)
|
|
108
|
+
.action(useCommand);
|
|
109
|
+
|
|
110
|
+
program
|
|
111
|
+
.command("remove <profile>")
|
|
112
|
+
.description(
|
|
113
|
+
"Delete profile"
|
|
114
|
+
)
|
|
115
|
+
.action(removeCommand);
|
|
116
|
+
|
|
117
|
+
program
|
|
118
|
+
.command("doctor")
|
|
119
|
+
.description(
|
|
120
|
+
"System health check"
|
|
121
|
+
)
|
|
122
|
+
.action(doctorCommand);
|
|
123
|
+
|
|
124
|
+
await program.parseAsync(process.argv);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main().catch((error) => {
|
|
128
|
+
console.error(error);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
});
|