@openfactu/cli 0.0.3 → 0.0.4
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/dist/src/commands/install.js +33 -15
- package/dist/src/index.js +1 -1
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ const ora_1 = __importDefault(require("ora"));
|
|
|
9
9
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
11
|
const https_1 = __importDefault(require("https"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
12
13
|
const fs_1 = __importDefault(require("fs"));
|
|
13
14
|
const path_1 = __importDefault(require("path"));
|
|
14
15
|
const logger_1 = require("../utils/logger");
|
|
@@ -156,7 +157,7 @@ function registerInstallCommand(program) {
|
|
|
156
157
|
type: 'input',
|
|
157
158
|
name: 'dir',
|
|
158
159
|
message: 'Directorio de instalación:',
|
|
159
|
-
default: path_1.default.join(
|
|
160
|
+
default: path_1.default.join(os_1.default.homedir(), 'openfactu'),
|
|
160
161
|
},
|
|
161
162
|
]);
|
|
162
163
|
targetDir = dir;
|
|
@@ -182,27 +183,44 @@ function registerInstallCommand(program) {
|
|
|
182
183
|
}
|
|
183
184
|
logger_1.log.info(`Directorio: ${chalk_1.default.dim(targetDir)}`);
|
|
184
185
|
logger_1.log.blank();
|
|
185
|
-
// 4.
|
|
186
|
+
// 4. Crear directorio si no existe (con sudo si hace falta)
|
|
187
|
+
if (!fs_1.default.existsSync(targetDir)) {
|
|
188
|
+
try {
|
|
189
|
+
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
190
|
+
}
|
|
191
|
+
catch (mkdirErr) {
|
|
192
|
+
if (mkdirErr.code === 'EACCES') {
|
|
193
|
+
logger_1.log.warn('Sin permisos. Creando directorio con sudo...');
|
|
194
|
+
try {
|
|
195
|
+
const user = process.env.USER || process.env.USERNAME || 'root';
|
|
196
|
+
(0, child_process_1.execSync)(`sudo mkdir -p "${targetDir}" && sudo chown -R ${user}:${user} "${targetDir}"`, {
|
|
197
|
+
stdio: 'inherit',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
logger_1.log.error(`No se pudo crear ${targetDir}. Ejecuta con sudo o elige otro directorio.`);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
throw mkdirErr;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// 5. Clonar repositorio
|
|
186
211
|
const cloneSpinner = (0, ora_1.default)('Descargando OpenFactu...').start();
|
|
187
212
|
const isTag = releases.some((r) => r.tag_name === ref);
|
|
213
|
+
const cloneCmd = isTag
|
|
214
|
+
? `git clone --depth 1 --branch ${ref} ${repoUrl} "${targetDir}"`
|
|
215
|
+
: `git clone --branch ${ref} ${repoUrl} "${targetDir}"`;
|
|
188
216
|
try {
|
|
189
|
-
|
|
190
|
-
// Para tags: clonar y luego checkout al tag
|
|
191
|
-
(0, child_process_1.execSync)(`git clone --depth 1 --branch ${ref} ${repoUrl} "${targetDir}"`, { stdio: 'pipe', timeout: 120000 });
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
// Para branches: clonar la branch directamente
|
|
195
|
-
(0, child_process_1.execSync)(`git clone --branch ${ref} ${repoUrl} "${targetDir}"`, { stdio: 'pipe', timeout: 120000 });
|
|
196
|
-
}
|
|
217
|
+
(0, child_process_1.execSync)(cloneCmd, { stdio: 'pipe', timeout: 120000 });
|
|
197
218
|
cloneSpinner.succeed('Código descargado');
|
|
198
219
|
}
|
|
199
220
|
catch (err) {
|
|
200
221
|
// Fallback: clonar todo y checkout
|
|
201
222
|
try {
|
|
202
223
|
cloneSpinner.text = 'Descargando (método alternativo)...';
|
|
203
|
-
if (!fs_1.default.existsSync(targetDir)) {
|
|
204
|
-
fs_1.default.mkdirSync(targetDir, { recursive: true });
|
|
205
|
-
}
|
|
206
224
|
(0, child_process_1.execSync)(`git clone ${repoUrl} "${targetDir}"`, { stdio: 'pipe', timeout: 180000 });
|
|
207
225
|
(0, child_process_1.execSync)(`git checkout ${ref}`, { cwd: targetDir, stdio: 'pipe' });
|
|
208
226
|
cloneSpinner.succeed('Código descargado');
|
|
@@ -212,14 +230,14 @@ function registerInstallCommand(program) {
|
|
|
212
230
|
return;
|
|
213
231
|
}
|
|
214
232
|
}
|
|
215
|
-
//
|
|
233
|
+
// 6. Copiar .env.example a .env
|
|
216
234
|
const envExample = path_1.default.join(targetDir, '.env.example');
|
|
217
235
|
const envFile = path_1.default.join(targetDir, '.env');
|
|
218
236
|
if (fs_1.default.existsSync(envExample) && !fs_1.default.existsSync(envFile)) {
|
|
219
237
|
fs_1.default.copyFileSync(envExample, envFile);
|
|
220
238
|
logger_1.log.success('Archivo .env creado desde .env.example');
|
|
221
239
|
}
|
|
222
|
-
//
|
|
240
|
+
// 7. Preguntar modo de instalación
|
|
223
241
|
const hasDocker = checkDocker();
|
|
224
242
|
if (!hasDocker) {
|
|
225
243
|
logger_1.log.warn('Docker no detectado. OpenFactu requiere Docker para funcionar.');
|
package/dist/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function createCLI() {
|
|
|
15
15
|
program
|
|
16
16
|
.name('openfactu')
|
|
17
17
|
.description('CLI para gestionar OpenFactu')
|
|
18
|
-
.version('0.0.
|
|
18
|
+
.version('0.0.4');
|
|
19
19
|
(0, version_1.registerVersionCommand)(program);
|
|
20
20
|
(0, migrate_1.registerMigrateCommand)(program);
|
|
21
21
|
(0, tenant_1.registerTenantCommand)(program);
|