-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-env.js
More file actions
executable file
·83 lines (67 loc) · 2.83 KB
/
setup-env.js
File metadata and controls
executable file
·83 lines (67 loc) · 2.83 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
#!/usr/bin/env node
// Helper script to set up environment variables in secure locations
import { getSecureEnvPath, getConfigEnvPath, ensureConfigDirectories } from './lib/config.js';
import fs from 'fs';
import readline from 'readline';
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function prompt(question) {
return new Promise((resolve) => {
rl.question(question, resolve);
});
}
async function setupEnvironment() {
console.log('🔧 MAIASS Environment Setup');
console.log('===============================\n');
ensureConfigDirectories();
const secureEnvPath = getSecureEnvPath();
const configEnvPath = getConfigEnvPath();
console.log(`Secure variables will be stored in: ${secureEnvPath}`);
console.log(`General config will be stored in: ${configEnvPath}\n`);
// Check if files already exist
const secureExists = fs.existsSync(secureEnvPath);
const configExists = fs.existsSync(configEnvPath);
if (secureExists || configExists) {
console.log('⚠️ Configuration files already exist:');
if (secureExists) console.log(` - ${secureEnvPath}`);
if (configExists) console.log(` - ${configEnvPath}`);
const overwrite = await prompt('\nDo you want to update them? (y/N): ');
if (overwrite.toLowerCase() !== 'y') {
console.log('Setup cancelled.');
rl.close();
return;
}
}
// Collect sensitive variables
console.log('\n📝 Setting up sensitive variables (stored securely):');
const maiassKey = await prompt('MAIASS API Key (optional): ');
// Collect general config
console.log('\n⚙️ Setting up general configuration:');
const defaultBranch = await prompt('Default branch name (default: main): ') || 'main';
const developBranch = await prompt('Development branch name (default: develop): ') || 'develop';
// Write secure env file
if (maiassKey.trim()) {
const secureContent = `# Sensitive environment variables for MAIASS
# This file is stored in a secure OS-specific location
MAIASS_API_KEY=${maiassKey.trim()}
`;
fs.writeFileSync(secureEnvPath, secureContent, { mode: 0o600 }); // Secure permissions
console.log(`✅ Secure variables saved to: ${secureEnvPath}`);
}
// Write general config file
const configContent = `# General configuration for MAIASS
# This file contains non-sensitive settings
DEFAULT_BRANCH=${defaultBranch}
DEVELOP_BRANCH=${developBranch}
MAIASS_VERSION=0.2.0
`;
fs.writeFileSync(configEnvPath, configContent);
console.log(`✅ General config saved to: ${configEnvPath}`);
console.log('\n🎉 Environment setup complete!');
console.log('\nYou can also create project-specific .env files in your working directories.');
console.log('Priority order: .env (cwd) > ~/.maiass.env > config.env > secure.env');
rl.close();
}
setupEnvironment().catch(console.error);