-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
188 lines (162 loc) · 5.25 KB
/
setup.js
File metadata and controls
188 lines (162 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env node
/**
* Universal Setup Script for git-multi-ssh
* Detects OS and runs appropriate setup
* Works on Windows, macOS, and Linux
*/
import chalk from 'chalk';
import ora from 'ora';
import os from 'os';
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
const platform = process.platform;
const home = os.homedir();
// Platform detection
const isPlatform = {
windows: platform === 'win32',
macos: platform === 'darwin',
linux: platform !== 'win32' && platform !== 'darwin',
};
const platformName = isPlatform.windows ? 'Windows' : isPlatform.macos ? 'macOS' : 'Linux';
/**
* Display welcome banner
*/
function showWelcome() {
console.clear();
console.log('\n');
console.log(chalk.cyan('╔════════════════════════════════════════════════════════════╗'));
console.log(chalk.cyan('║ 🚀 git-multi-ssh Setup ║'));
console.log(chalk.cyan('║ Manage multiple Git SSH identities on one machine ║'));
console.log(chalk.cyan('╚════════════════════════════════════════════════════════════╝'));
console.log('\n');
console.log(chalk.bold(`Detected Platform: ${chalk.green(platformName)}`));
console.log(chalk.gray(`Node: ${process.version}`));
console.log(chalk.gray(`Home: ${home}`));
console.log('\n');
}
/**
* Check prerequisites
*/
function checkPrerequisites() {
const spinner = ora('Checking prerequisites...').start();
const missing = [];
try {
// Check Node.js version
const nodeVersion = process.versions.node.split('.')[0];
if (parseInt(nodeVersion) < 18) {
missing.push('Node.js 18+ (current: ' + process.version + ')');
}
// Check npm
try {
execSync('npm --version', { stdio: 'ignore' });
} catch {
missing.push('npm');
}
// Check git
try {
execSync('git --version', { stdio: 'ignore' });
} catch {
missing.push('git');
}
// Check ssh
try {
execSync('ssh -V', { stdio: 'ignore' });
} catch {
missing.push('OpenSSH (ssh, ssh-keygen, ssh-add)');
}
if (missing.length > 0) {
spinner.fail('Missing prerequisites:');
missing.forEach(item => {
console.log(chalk.red(` ✗ ${item}`));
});
console.log('\n' + chalk.yellow('Please install the missing prerequisites and try again.\n'));
process.exit(1);
}
spinner.succeed('All prerequisites met!');
} catch (error) {
spinner.fail(`Error checking prerequisites: ${error.message}`);
process.exit(1);
}
}
/**
* Install dependencies
*/
function installDependencies() {
const spinner = ora('Installing npm dependencies...').start();
try {
execSync('npm install', {
stdio: 'pipe',
cwd: process.cwd(),
});
spinner.succeed('Dependencies installed');
} catch (error) {
spinner.fail(`Failed to install dependencies: ${error.message}`);
console.log(chalk.yellow('\nTry running: npm install\n'));
process.exit(1);
}
}
/**
* Link the CLI globally
*/
function linkCLI() {
const spinner = ora('Setting up git-multi-ssh command...').start();
try {
execSync('npm link', {
stdio: 'pipe',
cwd: process.cwd(),
});
spinner.succeed('CLI linked globally');
} catch (error) {
spinner.fail(`Failed to link CLI: ${error.message}`);
console.log(chalk.yellow('\nYou may need to run: sudo npm link\n'));
// Don't exit - this might work anyway
}
}
/**
* Show setup completion message
*/
function showCompletion() {
console.log('\n');
console.log(chalk.green('✅ Setup Complete!\n'));
console.log(chalk.bold('Next steps:'));
console.log('\n');
console.log(' 1. Run the setup wizard:');
console.log(chalk.cyan(' $ git-multi-ssh\n'));
console.log(' 2. Follow the prompts to add your first account');
console.log(' 3. Enter your account details (email, folder, provider)\n');
console.log(' 4. The tool will:');
console.log(' • Generate SSH keys');
console.log(' • Configure SSH and Git');
console.log(' • Test SSH connections\n');
console.log(chalk.bold('Optional:'));
console.log(' Set up Git aliases:');
if (isPlatform.windows) {
console.log(chalk.cyan(' $ .\\setup-aliases.ps1 (PowerShell)'));
console.log(chalk.cyan(' $ setup-aliases.bat (Command Prompt)\n'));
} else {
console.log(chalk.cyan(' $ ./setup-aliases.sh\n'));
}
console.log(chalk.bold('Documentation:'));
console.log(chalk.cyan(' • QUICK_START.md - Quick reference'));
console.log(chalk.cyan(' • CROSS_PLATFORM.md - Complete guide'));
console.log(chalk.cyan(' • README.md - Feature overview\n'));
console.log(chalk.gray('Happy coding! 🚀\n'));
}
/**
* Main setup flow
*/
async function main() {
showWelcome();
console.log(chalk.bold('Prerequisites Check:'));
checkPrerequisites();
console.log(chalk.bold('\nInstallation:'));
installDependencies();
linkCLI();
showCompletion();
}
// Run setup
main().catch(error => {
console.error(chalk.red('Setup failed:'), error.message);
process.exit(1);
});