git-userhub 2.1.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/README.md +42 -0
- package/bin/git-user.js +18 -0
- package/install.js +163 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# git-user (npm package)
|
|
2
|
+
|
|
3
|
+
> Switch Git accounts in one command. No config editing. No SSH key chaos.
|
|
4
|
+
|
|
5
|
+
This is the npm distribution of [git-user](https://github.com/divyo-argha/git-user), a CLI tool for managing multiple Git identities.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g git-userhub
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or use without installing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx git-userhub register
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Create your first identity
|
|
23
|
+
git-user register
|
|
24
|
+
|
|
25
|
+
# Switch between identities
|
|
26
|
+
git-user switch work
|
|
27
|
+
git-user switch personal
|
|
28
|
+
|
|
29
|
+
# List all identities
|
|
30
|
+
git-user list
|
|
31
|
+
|
|
32
|
+
# Check current identity
|
|
33
|
+
git-user current
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Documentation
|
|
37
|
+
|
|
38
|
+
Full documentation available at: https://github.com/divyo-argha/git-user
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
package/bin/git-user.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// Get the binary path
|
|
7
|
+
const binaryName = process.platform === 'win32' ? 'git-user.exe' : 'git-user';
|
|
8
|
+
const binPath = path.join(__dirname, '..', 'bin', binaryName);
|
|
9
|
+
|
|
10
|
+
// Forward all arguments to the binary
|
|
11
|
+
const child = spawn(binPath, process.argv.slice(2), {
|
|
12
|
+
stdio: 'inherit',
|
|
13
|
+
shell: false
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
child.on('exit', (code) => {
|
|
17
|
+
process.exit(code || 0);
|
|
18
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const https = require('https');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const zlib = require('zlib');
|
|
9
|
+
const tar = require('tar');
|
|
10
|
+
const pkg = require('./package.json');
|
|
11
|
+
|
|
12
|
+
const REPO = 'divyo-argha/git-user';
|
|
13
|
+
const BIN_DIR = path.join(__dirname, 'bin');
|
|
14
|
+
|
|
15
|
+
// Detect platform and architecture
|
|
16
|
+
function getPlatform() {
|
|
17
|
+
const platform = os.platform();
|
|
18
|
+
const arch = os.arch();
|
|
19
|
+
|
|
20
|
+
const platformMap = {
|
|
21
|
+
'darwin': 'darwin',
|
|
22
|
+
'linux': 'linux',
|
|
23
|
+
'win32': 'windows'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const archMap = {
|
|
27
|
+
'x64': 'amd64',
|
|
28
|
+
'arm64': 'arm64'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
os: platformMap[platform],
|
|
33
|
+
arch: archMap[arch],
|
|
34
|
+
ext: platform === 'win32' ? '.exe' : ''
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Download file from URL
|
|
39
|
+
function download(url, dest) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const file = fs.createWriteStream(dest);
|
|
42
|
+
|
|
43
|
+
https.get(url, (response) => {
|
|
44
|
+
if (response.statusCode === 302 || response.statusCode === 301) {
|
|
45
|
+
// Follow redirect
|
|
46
|
+
return download(response.headers.location, dest).then(resolve).catch(reject);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (response.statusCode !== 200) {
|
|
50
|
+
reject(new Error(`Failed to download: ${response.statusCode}`));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
response.pipe(file);
|
|
55
|
+
|
|
56
|
+
file.on('finish', () => {
|
|
57
|
+
file.close();
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
}).on('error', (err) => {
|
|
61
|
+
fs.unlink(dest, () => {});
|
|
62
|
+
reject(err);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Get release info matching this npm package version.
|
|
68
|
+
function getRelease() {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const options = {
|
|
71
|
+
hostname: 'api.github.com',
|
|
72
|
+
path: `/repos/${REPO}/releases/tags/v${pkg.version}`,
|
|
73
|
+
headers: {
|
|
74
|
+
'User-Agent': 'git-user-npm-installer'
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
https.get(options, (res) => {
|
|
79
|
+
let data = '';
|
|
80
|
+
|
|
81
|
+
res.on('data', (chunk) => {
|
|
82
|
+
data += chunk;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
res.on('end', () => {
|
|
86
|
+
try {
|
|
87
|
+
const release = JSON.parse(data);
|
|
88
|
+
resolve(release);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
reject(err);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}).on('error', reject);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function install() {
|
|
98
|
+
console.log('📦 Installing git-user...');
|
|
99
|
+
|
|
100
|
+
const { os: osName, arch, ext } = getPlatform();
|
|
101
|
+
|
|
102
|
+
if (!osName || !arch) {
|
|
103
|
+
console.error('❌ Unsupported platform:', os.platform(), os.arch());
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
// Create bin directory
|
|
109
|
+
if (!fs.existsSync(BIN_DIR)) {
|
|
110
|
+
fs.mkdirSync(BIN_DIR, { recursive: true });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Get matching release
|
|
114
|
+
console.log(`🔍 Fetching release v${pkg.version}...`);
|
|
115
|
+
const release = await getRelease();
|
|
116
|
+
|
|
117
|
+
// Find the right asset
|
|
118
|
+
const assetName = `git-user_${osName}_${arch}.tar.gz`;
|
|
119
|
+
const asset = release.assets.find(a => a.name === assetName);
|
|
120
|
+
|
|
121
|
+
if (!asset) {
|
|
122
|
+
console.error('❌ No binary found for your platform');
|
|
123
|
+
console.error(` Looking for: ${assetName}`);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Download
|
|
128
|
+
console.log(`⬇️ Downloading ${asset.name}...`);
|
|
129
|
+
const archivePath = path.join(BIN_DIR, asset.name);
|
|
130
|
+
await download(asset.browser_download_url, archivePath);
|
|
131
|
+
|
|
132
|
+
// Extract
|
|
133
|
+
console.log('📂 Extracting...');
|
|
134
|
+
await tar.extract({
|
|
135
|
+
file: archivePath,
|
|
136
|
+
cwd: BIN_DIR
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Cleanup archive
|
|
140
|
+
fs.unlinkSync(archivePath);
|
|
141
|
+
|
|
142
|
+
// Make executable
|
|
143
|
+
const binaryPath = path.join(BIN_DIR, `git-user${ext}`);
|
|
144
|
+
if (fs.existsSync(binaryPath)) {
|
|
145
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
146
|
+
console.log('✅ git-user installed successfully!');
|
|
147
|
+
console.log('');
|
|
148
|
+
console.log('Quick start:');
|
|
149
|
+
console.log(' npx git-user register # Create your first identity');
|
|
150
|
+
console.log(' npx git-user switch <n> # Switch between identities');
|
|
151
|
+
console.log(' npx git-user --help # Show all commands');
|
|
152
|
+
} else {
|
|
153
|
+
console.error('❌ Binary not found after extraction');
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error('❌ Installation failed:', err.message);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
install();
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "git-userhub",
|
|
3
|
+
"version": "2.1.4",
|
|
4
|
+
"description": "Switch Git accounts in one command. No config editing. No SSH key chaos.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"git-user": "bin/git-user.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node install.js",
|
|
10
|
+
"test": "echo \"No tests yet\" && exit 0"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"tar": "^7.4.3"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"git",
|
|
17
|
+
"github",
|
|
18
|
+
"gitlab",
|
|
19
|
+
"ssh",
|
|
20
|
+
"identity",
|
|
21
|
+
"account",
|
|
22
|
+
"switch",
|
|
23
|
+
"cli",
|
|
24
|
+
"developer-tools"
|
|
25
|
+
],
|
|
26
|
+
"author": "Divyo Argha",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/divyo-argha/git-user.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/divyo-argha/git-user/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/divyo-argha/git-user#readme",
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=14.0.0"
|
|
38
|
+
},
|
|
39
|
+
"os": [
|
|
40
|
+
"darwin",
|
|
41
|
+
"linux",
|
|
42
|
+
"win32"
|
|
43
|
+
],
|
|
44
|
+
"cpu": [
|
|
45
|
+
"x64",
|
|
46
|
+
"arm64"
|
|
47
|
+
]
|
|
48
|
+
}
|