Download src/cli/onboard.ts from agenthinkmesh/sane-assistant: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/cli/onboard.ts
- Command line
-
hf download hf://agenthinkmesh/sane-assistant/src/cli/onboard.ts
-
curl -L -o onboard.ts https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/cli/onboard.ts
2.43 kB
| import * as fs from 'fs'; | |
| import * as path from 'path'; | |
| import inquirer from 'inquirer'; | |
| import chalk from 'chalk'; | |
| import { ar } from '../i18n'; | |
| import { GCC_LOCATIONS } from '../config'; | |
| const envPath = path.resolve(process.cwd(), '.env'); | |
| async function runOnboarding() { | |
| console.log(chalk.bold.cyan(ar.onboardingStart)); | |
| const answers = await inquirer.prompt([ | |
| { | |
| type: 'input', | |
| name: 'userName', | |
| message: ar.askName, | |
| default: process.env.SANE_USER_NAME || '', | |
| }, | |
| { | |
| type: 'list', | |
| name: 'location', | |
| message: ar.askLocation, | |
| choices: Object.entries(GCC_LOCATIONS).map(([key, value]) => ({ | |
| name: `${value.nameAr} (${value.name})`, | |
| value: key, | |
| })), | |
| default: process.env.SANE_LOCATION || 'kuwait_city', | |
| }, | |
| { | |
| type: 'list', | |
| name: 'language', | |
| message: ar.askLanguage, | |
| choices: [ | |
| { name: 'العربية', value: 'ar' }, | |
| { name: 'English', value: 'en' }, | |
| ], | |
| default: process.env.SANE_LANGUAGE || 'ar', | |
| }, | |
| ]); | |
| // Create or update the .env file | |
| let envContent = ''; | |
| if (fs.existsSync(envPath)) { | |
| envContent = fs.readFileSync(envPath, 'utf-8'); | |
| } | |
| const updates = { | |
| SANE_USER_NAME: answers.userName, | |
| SANE_LOCATION: answers.location, | |
| SANE_LANGUAGE: answers.language, | |
| SANE_TIMEZONE: GCC_LOCATIONS[answers.location as keyof typeof GCC_LOCATIONS].timezone, | |
| }; | |
| for (const [key, value] of Object.entries(updates)) { | |
| if (envContent.includes(`${key}=`)) { | |
| envContent = envContent.replace(new RegExp(`${key}=.*`), `${key}=${value}`); | |
| } else { | |
| envContent += `\n${key}=${value}`; | |
| } | |
| } | |
| // Ensure required keys from .env.example are present | |
| const exampleEnv = fs.readFileSync(path.resolve(process.cwd(), '.env.example'), 'utf-8'); | |
| const exampleLines = exampleEnv.split('\n'); | |
| for (const line of exampleLines) { | |
| if (line.startsWith('#') || !line.includes('=')) continue; | |
| const key = line.split('=')[0]; | |
| if (!envContent.includes(`${key}=`)) { | |
| envContent += `\n${line}`; | |
| } | |
| } | |
| fs.writeFileSync(envPath, envContent.trim()); | |
| console.log(chalk.bold.green(`\n${ar.setupComplete}`)); | |
| console.log(chalk.gray(`تم حفظ الإعدادات في ملف .env`)); | |
| } | |
| runOnboarding().catch(error => { | |
| console.error(chalk.red('❌ حدث خطأ أثناء الإعداد:'), error); | |
| process.exit(1); | |
| }); | |