gitshift 1.0.2 → 1.0.4
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/.github/workflows/ci.yml +41 -0
- package/package.json +3 -2
- package/src/commands/add.js +34 -8
- package/src/commands/doctor.js +9 -1
- package/src/server.js +3 -2
- package/src/services/profile.js +1 -1
- package/src/services/ssh.js +19 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
name: ${{ matrix.os }} / Node ${{ matrix.node-version }}
|
|
12
|
+
runs-on: ${{ matrix.os }}
|
|
13
|
+
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
os:
|
|
18
|
+
- ubuntu-latest
|
|
19
|
+
- macos-latest
|
|
20
|
+
- windows-latest
|
|
21
|
+
node-version:
|
|
22
|
+
- "20"
|
|
23
|
+
- "22"
|
|
24
|
+
|
|
25
|
+
steps:
|
|
26
|
+
- name: Check out repository
|
|
27
|
+
uses: actions/checkout@v4
|
|
28
|
+
|
|
29
|
+
- name: Set up Node.js
|
|
30
|
+
uses: actions/setup-node@v4
|
|
31
|
+
with:
|
|
32
|
+
node-version: ${{ matrix.node-version }}
|
|
33
|
+
cache: npm
|
|
34
|
+
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: npm ci
|
|
37
|
+
|
|
38
|
+
- name: CLI smoke test
|
|
39
|
+
run: |
|
|
40
|
+
node src/server.js --version
|
|
41
|
+
node src/server.js --help
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gitshift",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "GitHub Account Switcher CLI",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"start": "node src/server.js"
|
|
11
|
+
"start": "node src/server.js",
|
|
12
|
+
"doctor": "node src/server.js doctor"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [],
|
|
14
15
|
"author": "",
|
package/src/commands/add.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "../services/ssh.js";
|
|
16
16
|
|
|
17
17
|
import {
|
|
18
|
+
error,
|
|
18
19
|
success,
|
|
19
20
|
} from "../utils/logger.js";
|
|
20
21
|
|
|
@@ -24,9 +25,12 @@ export async function addCommand() {
|
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
if (getProfile(name)) {
|
|
27
|
-
|
|
28
|
+
error(
|
|
28
29
|
`Profile "${name}" already exists`
|
|
29
30
|
);
|
|
31
|
+
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
return;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
const username = await input({
|
|
@@ -50,14 +54,36 @@ export async function addCommand() {
|
|
|
50
54
|
"Generating SSH key..."
|
|
51
55
|
).start();
|
|
52
56
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
try {
|
|
58
|
+
sshKey = await generateSSHKey(
|
|
59
|
+
name,
|
|
60
|
+
email
|
|
61
|
+
);
|
|
57
62
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
spinner.succeed(
|
|
64
|
+
"SSH key generated"
|
|
65
|
+
);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
spinner.fail(
|
|
68
|
+
"Unable to generate SSH key"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
error(
|
|
72
|
+
"Could not create SSH key. Ensure OpenSSH is installed and available."
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
if (
|
|
76
|
+
err &&
|
|
77
|
+
typeof err === "object" &&
|
|
78
|
+
"shortMessage" in err &&
|
|
79
|
+
err.shortMessage
|
|
80
|
+
) {
|
|
81
|
+
error(String(err.shortMessage));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
process.exitCode = 1;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
61
87
|
}
|
|
62
88
|
|
|
63
89
|
saveProfile({
|
package/src/commands/doctor.js
CHANGED
|
@@ -34,11 +34,19 @@ export async function doctorCommand() {
|
|
|
34
34
|
"-V",
|
|
35
35
|
]);
|
|
36
36
|
|
|
37
|
-
await check(
|
|
37
|
+
const ghInstalled = await check(
|
|
38
38
|
"GitHub CLI",
|
|
39
39
|
"gh",
|
|
40
40
|
["--version"]
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
+
if (!ghInstalled) {
|
|
44
|
+
console.log();
|
|
45
|
+
console.log(
|
|
46
|
+
"Hint: Install GitHub CLI (macOS): `brew install gh`"
|
|
47
|
+
);
|
|
48
|
+
console.log("Then authenticate with: `gh auth login`");
|
|
49
|
+
}
|
|
50
|
+
|
|
43
51
|
console.log();
|
|
44
52
|
}
|
package/src/server.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import axios from "axios";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { Command } from "commander";
|
|
6
|
-
import
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
7
|
import { addCommand } from "./commands/add.js";
|
|
8
8
|
import { currentCommand } from "./commands/current.js";
|
|
9
9
|
import { doctorCommand } from "./commands/doctor.js";
|
|
@@ -11,7 +11,8 @@ import { listCommand } from "./commands/list.js";
|
|
|
11
11
|
import { removeCommand } from "./commands/remove.js";
|
|
12
12
|
import { useCommand } from "./commands/use.js";
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
const { name, version } = require("../package.json");
|
|
15
16
|
|
|
16
17
|
function printBanner() {
|
|
17
18
|
const logo = String.raw`
|
package/src/services/profile.js
CHANGED
package/src/services/ssh.js
CHANGED
|
@@ -3,14 +3,28 @@ import fs from "fs-extra";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
|
+
function toSafeKeyName(profileName) {
|
|
7
|
+
const normalized = profileName
|
|
8
|
+
.trim()
|
|
9
|
+
.replace(/[^a-zA-Z0-9._-]+/g, "-")
|
|
10
|
+
.replace(/-+/g, "-")
|
|
11
|
+
.replace(/^-|-$/g, "");
|
|
12
|
+
|
|
13
|
+
return normalized || "profile";
|
|
14
|
+
}
|
|
15
|
+
|
|
6
16
|
export async function generateSSHKey(
|
|
7
17
|
profileName,
|
|
8
18
|
email
|
|
9
19
|
) {
|
|
20
|
+
const safeProfileName = toSafeKeyName(
|
|
21
|
+
profileName
|
|
22
|
+
);
|
|
23
|
+
|
|
10
24
|
const keyPath = path.join(
|
|
11
25
|
os.homedir(),
|
|
12
26
|
".ssh",
|
|
13
|
-
`
|
|
27
|
+
`gitshift-${safeProfileName}`
|
|
14
28
|
);
|
|
15
29
|
|
|
16
30
|
const exists = await fs.pathExists(
|
|
@@ -21,6 +35,10 @@ export async function generateSSHKey(
|
|
|
21
35
|
return keyPath;
|
|
22
36
|
}
|
|
23
37
|
|
|
38
|
+
await fs.ensureDir(
|
|
39
|
+
path.dirname(keyPath)
|
|
40
|
+
);
|
|
41
|
+
|
|
24
42
|
await execa("ssh-keygen", [
|
|
25
43
|
"-t",
|
|
26
44
|
"ed25519",
|