install-rynude 1.0.1 → 1.0.3
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/index.js +49 -27
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,22 +28,32 @@ async function run() {
|
|
|
28
28
|
|
|
29
29
|
await checkRequirements();
|
|
30
30
|
|
|
31
|
+
let hasBackup = false;
|
|
32
|
+
const backupDir = path.join(os.homedir(), '.rynude_backup_tmp');
|
|
33
|
+
const dbPath = path.join(INSTALL_DIR, 'database', 'database.sqlite');
|
|
34
|
+
const envPath = path.join(INSTALL_DIR, '.env');
|
|
35
|
+
|
|
31
36
|
if (fs.existsSync(INSTALL_DIR)) {
|
|
32
37
|
const response = await prompts({
|
|
33
38
|
type: 'confirm',
|
|
34
39
|
name: 'overwrite',
|
|
35
|
-
message: `
|
|
36
|
-
initial:
|
|
40
|
+
message: `Aplikasi Rynude AI sudah terinstal. Apakah Anda ingin melakukan UPDATE ke versi terbaru? (Data obrolan & API Key Anda akan aman)`,
|
|
41
|
+
initial: true
|
|
37
42
|
});
|
|
38
43
|
|
|
39
44
|
if (!response.overwrite) {
|
|
40
|
-
console.log(chalk.yellow('
|
|
45
|
+
console.log(chalk.yellow('Update dibatalkan.'));
|
|
41
46
|
process.exit(0);
|
|
42
47
|
}
|
|
43
48
|
|
|
44
|
-
const spinner = ora('
|
|
49
|
+
const spinner = ora('Mem-backup data Anda (Database & Konfigurasi)...').start();
|
|
50
|
+
fs.ensureDirSync(backupDir);
|
|
51
|
+
if (fs.existsSync(dbPath)) fs.copySync(dbPath, path.join(backupDir, 'database.sqlite'));
|
|
52
|
+
if (fs.existsSync(envPath)) fs.copySync(envPath, path.join(backupDir, '.env'));
|
|
53
|
+
hasBackup = true;
|
|
54
|
+
|
|
45
55
|
fs.removeSync(INSTALL_DIR);
|
|
46
|
-
spinner.succeed('
|
|
56
|
+
spinner.succeed('Data lama dibackup dan siap diupdate.');
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
console.log(chalk.gray(`\nMenginstal Rynude AI ke folder tersembunyi: ${INSTALL_DIR}`));
|
|
@@ -80,21 +90,29 @@ async function run() {
|
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
// 4. ENV Setup
|
|
83
|
-
const envSpinner = ora('Menyiapkan
|
|
93
|
+
const envSpinner = ora('Menyiapkan konfigurasi & database...').start();
|
|
84
94
|
try {
|
|
85
|
-
fs.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
if (hasBackup && fs.existsSync(path.join(backupDir, '.env')) && fs.existsSync(path.join(backupDir, 'database.sqlite'))) {
|
|
96
|
+
// Restore from backup
|
|
97
|
+
fs.copySync(path.join(backupDir, '.env'), path.join(INSTALL_DIR, '.env'));
|
|
98
|
+
fs.ensureDirSync(path.join(INSTALL_DIR, 'database'));
|
|
99
|
+
fs.copySync(path.join(backupDir, 'database.sqlite'), path.join(INSTALL_DIR, 'database', 'database.sqlite'));
|
|
100
|
+
fs.removeSync(backupDir); // clean up tmp
|
|
101
|
+
|
|
102
|
+
execSync('php artisan migrate --force', { cwd: INSTALL_DIR, stdio: 'ignore' });
|
|
103
|
+
envSpinner.succeed('Konfigurasi dan database lama Anda berhasil dipulihkan (Aman!).');
|
|
104
|
+
} else {
|
|
105
|
+
// Fresh Install
|
|
106
|
+
fs.copySync(path.join(INSTALL_DIR, '.env.example'), path.join(INSTALL_DIR, '.env'));
|
|
107
|
+
let envContent = fs.readFileSync(path.join(INSTALL_DIR, '.env'), 'utf-8');
|
|
108
|
+
envContent = envContent.replace(/DB_CONNECTION=.*/, 'DB_CONNECTION=sqlite');
|
|
109
|
+
fs.writeFileSync(path.join(INSTALL_DIR, '.env'), envContent);
|
|
110
|
+
|
|
111
|
+
fs.ensureFileSync(path.join(INSTALL_DIR, 'database', 'database.sqlite'));
|
|
112
|
+
execSync('php artisan key:generate', { cwd: INSTALL_DIR, stdio: 'ignore' });
|
|
113
|
+
execSync('php artisan migrate:fresh --seed', { cwd: INSTALL_DIR, stdio: 'ignore' });
|
|
114
|
+
envSpinner.succeed('Konfigurasi dan database siap.');
|
|
115
|
+
}
|
|
98
116
|
} catch (e) {
|
|
99
117
|
envSpinner.fail('Gagal menyiapkan database.');
|
|
100
118
|
console.error(chalk.red(e.message));
|
|
@@ -113,16 +131,20 @@ async function run() {
|
|
|
113
131
|
// Auto add to PATH for Mac/Linux
|
|
114
132
|
const bashrcPath = path.join(os.homedir(), '.bashrc');
|
|
115
133
|
const zshrcPath = path.join(os.homedir(), '.zshrc');
|
|
134
|
+
const zprofilePath = path.join(os.homedir(), '.zprofile');
|
|
116
135
|
const pathExport = `\nexport PATH="$HOME/.local/bin:$PATH"\n`;
|
|
117
136
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
137
|
+
[bashrcPath, zshrcPath, zprofilePath].forEach(profilePath => {
|
|
138
|
+
try {
|
|
139
|
+
fs.ensureFileSync(profilePath);
|
|
140
|
+
const content = fs.readFileSync(profilePath, 'utf8');
|
|
141
|
+
if (!content.includes('.local/bin')) {
|
|
142
|
+
fs.appendFileSync(profilePath, pathExport);
|
|
143
|
+
}
|
|
144
|
+
} catch (err) {
|
|
145
|
+
// ignore if permission denied
|
|
146
|
+
}
|
|
147
|
+
});
|
|
126
148
|
}
|
|
127
149
|
globalSpinner.succeed('Global command berhasil diatur.');
|
|
128
150
|
} catch (e) {
|