@_xtribe/cli 2.0.3 → 2.0.5

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/setup-path.js ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const chalk = require('chalk');
7
+
8
+ const homeDir = os.homedir();
9
+ const tribeEnvPath = path.join(homeDir, '.tribe', 'tribe-env.sh');
10
+
11
+ // Detect user's shell
12
+ function detectShell() {
13
+ const shell = process.env.SHELL || '';
14
+ if (shell.includes('zsh')) return 'zsh';
15
+ if (shell.includes('bash')) return 'bash';
16
+ if (shell.includes('fish')) return 'fish';
17
+ return 'unknown';
18
+ }
19
+
20
+ // Get shell config file
21
+ function getShellConfigFile() {
22
+ const shell = detectShell();
23
+ const configFiles = {
24
+ 'zsh': ['.zshrc', '.zprofile'],
25
+ 'bash': ['.bashrc', '.bash_profile', '.profile'],
26
+ 'fish': ['.config/fish/config.fish']
27
+ };
28
+
29
+ const candidates = configFiles[shell] || [];
30
+
31
+ // Check which config file exists
32
+ for (const file of candidates) {
33
+ const fullPath = path.join(homeDir, file);
34
+ if (fs.existsSync(fullPath)) {
35
+ return fullPath;
36
+ }
37
+ }
38
+
39
+ // If none exist, use the first candidate
40
+ if (candidates.length > 0) {
41
+ return path.join(homeDir, candidates[0]);
42
+ }
43
+
44
+ return null;
45
+ }
46
+
47
+ function setupPath() {
48
+ console.log(chalk.bold('🔧 TRIBE PATH Setup\n'));
49
+
50
+ // Check if tribe-env.sh exists
51
+ if (!fs.existsSync(tribeEnvPath)) {
52
+ console.log(chalk.red('Error: TRIBE environment script not found.'));
53
+ console.log('Please run the installer first: npx @_xtribe/cli');
54
+ process.exit(1);
55
+ }
56
+
57
+ const shellConfig = getShellConfigFile();
58
+ const shell = detectShell();
59
+
60
+ if (!shellConfig) {
61
+ console.log(chalk.yellow('Could not detect shell configuration file.'));
62
+ console.log('\nPlease manually add this line to your shell config:');
63
+ console.log(chalk.green(` source ~/.tribe/tribe-env.sh`));
64
+ return;
65
+ }
66
+
67
+ // Check if already added
68
+ try {
69
+ const content = fs.readFileSync(shellConfig, 'utf8');
70
+ if (content.includes('source ~/.tribe/tribe-env.sh') ||
71
+ content.includes('source $HOME/.tribe/tribe-env.sh') ||
72
+ content.includes('. ~/.tribe/tribe-env.sh')) {
73
+ console.log(chalk.green('✓ PATH already configured!'));
74
+ console.log('\nTo use tribe in your current session:');
75
+ console.log(chalk.green(` source ~/.tribe/tribe-env.sh`));
76
+ return;
77
+ }
78
+ } catch (e) {
79
+ // File doesn't exist yet, that's ok
80
+ }
81
+
82
+ // Add to shell config
83
+ const sourceCommand = '\n# TRIBE CLI\nsource ~/.tribe/tribe-env.sh\n';
84
+
85
+ try {
86
+ fs.appendFileSync(shellConfig, sourceCommand);
87
+ console.log(chalk.green(`✓ Added TRIBE to your ${shell} configuration!`));
88
+ console.log(` Configuration file: ${shellConfig}`);
89
+ console.log('\nTo use tribe in your current session:');
90
+ console.log(chalk.green(` source ~/.tribe/tribe-env.sh`));
91
+ console.log('\nOr open a new terminal window.');
92
+ } catch (error) {
93
+ console.log(chalk.red(`Error updating ${shellConfig}: ${error.message}`));
94
+ console.log('\nPlease manually add this line to your shell config:');
95
+ console.log(chalk.green(` source ~/.tribe/tribe-env.sh`));
96
+ }
97
+ }
98
+
99
+ // Export for use by other modules
100
+ module.exports = setupPath;
101
+
102
+ // Add to package.json bin entry
103
+ if (require.main === module) {
104
+ setupPath();
105
+ }