-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.mjs
More file actions
181 lines (168 loc) · 4.85 KB
/
config.mjs
File metadata and controls
181 lines (168 loc) · 4.85 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
import fs from 'fs';
import path from 'path';
import inquirer from 'inquirer';
export const CONFIG_TEMPLATES = {
basic: {
name: 'Basic setup - VS Code + terminal',
config: {
path: '~',
maxDepth: 5,
execute: 'code .',
execute2: 'zsh',
execute3: 'bash'
}
},
nvm: {
name: 'Node.js with NVM - auto-switch Node versions (.nvmrc)',
config: {
path: '~',
maxDepth: 5,
execute: '[ -f .nvmrc ] && . ~/.nvm/nvm.sh && nvm use; code .',
execute2: '. ~/.nvm/nvm.sh && nvm use && npm start',
execute3: 'nvm use && yarn dev'
}
},
nix: {
name: 'Nix development environment - enter nix develop shell',
config: {
path: '~',
maxDepth: 5,
execute: 'nix develop -c code .',
execute2: 'nix-shell --run "code ."',
execute3: 'direnv allow && code .'
}
},
mixed: {
name: 'Mixed environments - auto-detect (Nix first, then NVM, fallback to zsh)',
config: {
path: '~',
maxDepth: 5,
execute: 'bash -c "if [ -f flake.nix ]; then nix develop; elif [ -f .nvmrc ]; then . ~/.nvm/nvm.sh && nvm use; fi; zsh"',
execute2: 'code .',
execute3: 'zsh'
}
},
cursor: {
name: 'Cursor editor - AI-powered VS Code alternative',
config: {
path: '~',
maxDepth: 5,
execute: 'cursor .',
execute2: 'zsh',
execute3: 'bash'
}
}
};
export async function createInteractiveConfig() {
// Detect CI environment and use basic setup
const isCI = process.env.CI || process.env.GITHUB_ACTIONS || process.env.JENKINS_URL;
if (isCI) {
console.log('🤖 CI environment detected - using basic configuration');
const basicConfig = CONFIG_TEMPLATES.basic.config;
const configPath = path.resolve(process.env.HOME, '.lcodeconfig');
try {
fs.writeFileSync(configPath, JSON.stringify(basicConfig, null, 2));
console.log(`✓ Configuration file created at ${configPath}`);
return true;
} catch (error) {
console.error(`✗ Failed to create configuration file: ${error.message}`);
return false;
}
}
console.log('\n🚀 Welcome to lcode configuration setup!\n');
const answers = await inquirer.prompt([
{
type: 'list',
name: 'template',
message: 'Choose a configuration template:',
choices: [
{ name: CONFIG_TEMPLATES.basic.name, value: 'basic' },
{ name: CONFIG_TEMPLATES.nvm.name, value: 'nvm' },
{ name: CONFIG_TEMPLATES.nix.name, value: 'nix' },
{ name: CONFIG_TEMPLATES.mixed.name, value: 'mixed' },
{ name: CONFIG_TEMPLATES.cursor.name, value: 'cursor' },
{ name: 'Custom setup', value: 'custom' }
]
}
]);
let config;
if (answers.template === 'custom') {
const customAnswers = await inquirer.prompt([
{
type: 'input',
name: 'path',
message: 'Default search path:',
default: '~'
},
{
type: 'input',
name: 'maxDepth',
message: 'Default search depth (1-10):',
default: '5',
validate: (input) => {
const num = parseInt(input, 10);
if (isNaN(num) || num < 1 || num > 10) {
return 'Please enter a number between 1 and 10';
}
return true;
}
},
{
type: 'input',
name: 'execute',
message: 'Primary command:',
default: 'code .'
},
{
type: 'input',
name: 'execute2',
message: 'Alternative command:',
default: 'zsh'
},
{
type: 'input',
name: 'execute3',
message: 'Third command:',
default: 'bash'
}
]);
config = {
path: customAnswers.path,
maxDepth: parseInt(customAnswers.maxDepth, 10),
execute: customAnswers.execute,
execute2: customAnswers.execute2,
execute3: customAnswers.execute3
};
} else {
config = { ...CONFIG_TEMPLATES[answers.template].config };
}
// Show preview and confirm
console.log('\n📋 Configuration preview:');
console.log(JSON.stringify(config, null, 2));
const confirm = await inquirer.prompt([
{
type: 'confirm',
name: 'save',
message: 'Save this configuration?',
default: true
}
]);
if (confirm.save) {
const dynamicConfigPath = path.resolve(process.env.HOME, '.lcodeconfig');
try {
fs.writeFileSync(dynamicConfigPath, JSON.stringify(config, null, 2));
console.log(`\n✅ Configuration saved to ${dynamicConfigPath}`);
return true;
} catch (error) {
console.error(`\n❌ Failed to save configuration: ${error.message}`);
return false;
}
} else {
console.log('\n❌ Configuration not saved');
return false;
}
}
export function configExists() {
const dynamicConfigPath = path.resolve(process.env.HOME, '.lcodeconfig');
return fs.existsSync(dynamicConfigPath);
}