git-userhub 3.0.6 → 3.0.7
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/bin/git-user.js +114 -40
- package/package.json +6 -14
- package/packages/checksums.txt +0 -6
- package/packages/git-userhub-darwin-arm64/README.md +0 -4
- package/packages/git-userhub-darwin-arm64/bin/git-user +0 -0
- package/packages/git-userhub-darwin-arm64/package.json +0 -19
- package/packages/git-userhub-darwin-x64/README.md +0 -4
- package/packages/git-userhub-darwin-x64/bin/git-user +0 -0
- package/packages/git-userhub-darwin-x64/package.json +0 -19
- package/packages/git-userhub-linux-arm64/README.md +0 -4
- package/packages/git-userhub-linux-arm64/bin/git-user +0 -0
- package/packages/git-userhub-linux-arm64/package.json +0 -19
- package/packages/git-userhub-linux-x64/README.md +0 -4
- package/packages/git-userhub-linux-x64/bin/git-user +0 -0
- package/packages/git-userhub-linux-x64/package.json +0 -19
- package/packages/git-userhub-windows-x64/README.md +0 -4
- package/packages/git-userhub-windows-x64/bin/git-user.exe +0 -0
- package/packages/git-userhub-windows-x64/package.json +0 -19
package/bin/git-user.js
CHANGED
|
@@ -4,21 +4,19 @@ const { spawn } = require('child_process');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const os = require('os');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const crypto = require('crypto');
|
|
9
|
+
const tar = require('tar');
|
|
10
|
+
const PKG_JSON = require('../package.json');
|
|
11
|
+
|
|
12
|
+
const REPO = 'divyo-argha/git-user';
|
|
13
|
+
const VERSION = `v${PKG_JSON.version}`;
|
|
7
14
|
|
|
8
|
-
// Detect platform and architecture
|
|
9
15
|
const platform = os.platform();
|
|
10
16
|
const arch = os.arch();
|
|
11
17
|
|
|
12
|
-
const platformMap = {
|
|
13
|
-
|
|
14
|
-
'linux': 'linux',
|
|
15
|
-
'win32': 'windows'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const archMap = {
|
|
19
|
-
'x64': 'amd64',
|
|
20
|
-
'arm64': 'arm64'
|
|
21
|
-
};
|
|
18
|
+
const platformMap = { 'darwin': 'darwin', 'linux': 'linux', 'win32': 'windows' };
|
|
19
|
+
const archMap = { 'x64': 'x86_64', 'arm64': 'arm64' };
|
|
22
20
|
|
|
23
21
|
const osName = platformMap[platform];
|
|
24
22
|
const archName = archMap[arch];
|
|
@@ -29,38 +27,114 @@ if (!osName || !archName) {
|
|
|
29
27
|
process.exit(1);
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
const finalBinaryName = `git-user-${platform}-${arch}${ext}`;
|
|
31
|
+
const finalBinaryPath = path.join(__dirname, finalBinaryName);
|
|
32
|
+
const assetName = `git-user_${osName}_${archName}.tar.gz`;
|
|
33
|
+
|
|
34
|
+
function runBinary() {
|
|
35
|
+
const child = spawn(finalBinaryPath, process.argv.slice(2), {
|
|
36
|
+
stdio: 'inherit',
|
|
37
|
+
shell: false
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
child.on('exit', (code) => {
|
|
41
|
+
process.exit(code || 0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
child.on('error', (err) => {
|
|
45
|
+
console.error('❌ Failed to start git-user:', err.message);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
});
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
process.exit(1);
|
|
50
|
+
if (fs.existsSync(finalBinaryPath)) {
|
|
51
|
+
runBinary();
|
|
52
|
+
return;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
//
|
|
54
|
-
|
|
55
|
-
stdio: 'inherit',
|
|
56
|
-
shell: false
|
|
57
|
-
});
|
|
55
|
+
// FIRST RUN: Download binary
|
|
56
|
+
console.log(`[git-user] First run detected. Downloading native binary for ${platform}-${arch} (~8MB)...`);
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
58
|
+
function fetchJson(url) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
https.get(url, { headers: { 'User-Agent': 'node' } }, (res) => {
|
|
61
|
+
if (res.statusCode !== 200) return reject(new Error(`API Error ${res.statusCode}`));
|
|
62
|
+
let data = '';
|
|
63
|
+
res.on('data', c => data += c);
|
|
64
|
+
res.on('end', () => resolve(JSON.parse(data)));
|
|
65
|
+
}).on('error', reject);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
62
68
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
function fetchFile(url, dest) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
https.get(url, { headers: { 'User-Agent': 'node' } }, (res) => {
|
|
72
|
+
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
73
|
+
return fetchFile(res.headers.location, dest).then(resolve).catch(reject);
|
|
74
|
+
}
|
|
75
|
+
if (res.statusCode !== 200) return reject(new Error(`Download Error ${res.statusCode}`));
|
|
76
|
+
const file = fs.createWriteStream(dest);
|
|
77
|
+
res.pipe(file);
|
|
78
|
+
file.on('finish', () => { file.close(); resolve(); });
|
|
79
|
+
}).on('error', reject);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function verifyHash(file, expected) {
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const hash = crypto.createHash('sha256');
|
|
86
|
+
const stream = fs.createReadStream(file);
|
|
87
|
+
stream.on('data', d => hash.update(d));
|
|
88
|
+
stream.on('end', () => {
|
|
89
|
+
if (hash.digest('hex') !== expected) reject(new Error("Checksum mismatch!"));
|
|
90
|
+
else resolve();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function install() {
|
|
96
|
+
try {
|
|
97
|
+
const release = await fetchJson(`https://api.github.com/repos/${REPO}/releases/tags/${VERSION}`);
|
|
98
|
+
const checksumAsset = release.assets.find(a => a.name.endsWith('checksums.txt'));
|
|
99
|
+
const binAsset = release.assets.find(a => a.name === assetName);
|
|
100
|
+
|
|
101
|
+
if (!checksumAsset || !binAsset) {
|
|
102
|
+
throw new Error("Could not find required assets on GitHub Release");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const checksumPath = path.join(__dirname, 'checksums.txt');
|
|
106
|
+
const archivePath = path.join(__dirname, assetName);
|
|
107
|
+
|
|
108
|
+
await fetchFile(checksumAsset.browser_download_url, checksumPath);
|
|
109
|
+
const checksums = fs.readFileSync(checksumPath, 'utf8');
|
|
110
|
+
const hashLine = checksums.split('\n').find(l => l.endsWith(assetName));
|
|
111
|
+
if (!hashLine) throw new Error("Checksum missing in txt file");
|
|
112
|
+
const expectedHash = hashLine.split(/\s+/)[0];
|
|
113
|
+
|
|
114
|
+
await fetchFile(binAsset.browser_download_url, archivePath);
|
|
115
|
+
await verifyHash(archivePath, expectedHash);
|
|
116
|
+
|
|
117
|
+
const binaryNameInArchive = platform === 'win32' ? 'git-user.exe' : 'git-user';
|
|
118
|
+
await tar.extract({
|
|
119
|
+
file: archivePath,
|
|
120
|
+
cwd: __dirname,
|
|
121
|
+
filter: (p) => p.replace(/^\.\//, '') === binaryNameInArchive
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const extractedPath = path.join(__dirname, binaryNameInArchive);
|
|
125
|
+
fs.renameSync(extractedPath, finalBinaryPath);
|
|
126
|
+
|
|
127
|
+
if (platform !== 'win32') fs.chmodSync(finalBinaryPath, 0o755);
|
|
128
|
+
|
|
129
|
+
fs.unlinkSync(archivePath);
|
|
130
|
+
fs.unlinkSync(checksumPath);
|
|
131
|
+
|
|
132
|
+
console.log(`[git-user] Installation complete.\n`);
|
|
133
|
+
runBinary();
|
|
134
|
+
} catch (err) {
|
|
135
|
+
console.error(`\n❌ git-user installation failed: ${err.message}`);
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
install();
|
package/package.json
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "git-userhub",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Switch Git accounts in one command. No config editing. No SSH key chaos.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"git-user": "bin/git-user.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
|
-
"test": "echo \"No tests yet\" && exit 0"
|
|
10
|
-
"release": "node scripts/release.js"
|
|
11
|
-
},
|
|
12
|
-
"optionalDependencies": {
|
|
13
|
-
"git-userhub-darwin-arm64": "3.0.6",
|
|
14
|
-
"git-userhub-darwin-x64": "3.0.6",
|
|
15
|
-
"git-userhub-linux-arm64": "3.0.6",
|
|
16
|
-
"git-userhub-linux-x64": "3.0.6",
|
|
17
|
-
"git-userhub-windows-x64": "3.0.6"
|
|
18
|
-
},
|
|
19
|
-
"devDependencies": {
|
|
20
|
-
"tar": "^7.4.3"
|
|
9
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
21
10
|
},
|
|
22
11
|
"keywords": [
|
|
23
12
|
"git",
|
|
@@ -54,5 +43,8 @@
|
|
|
54
43
|
],
|
|
55
44
|
"config": {
|
|
56
45
|
"repo": "divyo-argha/git-user"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"tar": "^7.5.16"
|
|
57
49
|
}
|
|
58
|
-
}
|
|
50
|
+
}
|
package/packages/checksums.txt
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
228e32fdccc3b553ddcefad445a75548c9df5ca03190879d7050008128449742 git-user_darwin_arm64.tar.gz
|
|
2
|
-
5191fda6093bf66946a53504bb3ef0accf776d74d9b3467e36c9cd2c8d7df1a1 git-user_darwin_x86_64.tar.gz
|
|
3
|
-
e43a1171aeedc8f3bd92ddeb38e2b50fbabe5058c5874874c6295f8ea6ca716e git-user_linux_arm64.tar.gz
|
|
4
|
-
fd97690f902462b0f68ab930dd5e6c63ba33a1d5999851787091cf745fcbec60 git-user_linux_x86_64.tar.gz
|
|
5
|
-
3b5ad0b0bfaeb0f2464b123d764cd5da9db2a3f496676e5d27c2ff8fc6957f75 git-user_windows_arm64.tar.gz
|
|
6
|
-
2a15ecc32d0ae3d419f541477aff8687463cd3ab600807d96ed44ec50ecc7503 git-user_windows_x86_64.tar.gz
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "git-userhub-darwin-arm64",
|
|
3
|
-
"version": "3.0.6",
|
|
4
|
-
"description": "The darwin arm64 binary for git-userhub",
|
|
5
|
-
"os": [
|
|
6
|
-
"darwin"
|
|
7
|
-
],
|
|
8
|
-
"cpu": [
|
|
9
|
-
"arm64"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"git-user": "bin/git-user"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT"
|
|
19
|
-
}
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "git-userhub-darwin-x64",
|
|
3
|
-
"version": "3.0.6",
|
|
4
|
-
"description": "The darwin x64 binary for git-userhub",
|
|
5
|
-
"os": [
|
|
6
|
-
"darwin"
|
|
7
|
-
],
|
|
8
|
-
"cpu": [
|
|
9
|
-
"x64"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"git-user": "bin/git-user"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT"
|
|
19
|
-
}
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "git-userhub-linux-arm64",
|
|
3
|
-
"version": "3.0.6",
|
|
4
|
-
"description": "The linux arm64 binary for git-userhub",
|
|
5
|
-
"os": [
|
|
6
|
-
"linux"
|
|
7
|
-
],
|
|
8
|
-
"cpu": [
|
|
9
|
-
"arm64"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"git-user": "bin/git-user"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT"
|
|
19
|
-
}
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "git-userhub-linux-x64",
|
|
3
|
-
"version": "3.0.6",
|
|
4
|
-
"description": "The linux x64 binary for git-userhub",
|
|
5
|
-
"os": [
|
|
6
|
-
"linux"
|
|
7
|
-
],
|
|
8
|
-
"cpu": [
|
|
9
|
-
"x64"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"git-user": "bin/git-user"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT"
|
|
19
|
-
}
|
|
Binary file
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "git-userhub-windows-x64",
|
|
3
|
-
"version": "3.0.6",
|
|
4
|
-
"description": "The win32 x64 binary for git-userhub",
|
|
5
|
-
"os": [
|
|
6
|
-
"win32"
|
|
7
|
-
],
|
|
8
|
-
"cpu": [
|
|
9
|
-
"x64"
|
|
10
|
-
],
|
|
11
|
-
"bin": {
|
|
12
|
-
"git-user": "bin/git-user.exe"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
17
|
-
},
|
|
18
|
-
"license": "MIT"
|
|
19
|
-
}
|