easy-devops 0.2.6 → 1.0.0

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.
@@ -16,8 +16,19 @@ import ora from 'ora';
16
16
  import { run, runLive } from '../../core/shell.js';
17
17
  import { loadConfig } from '../../core/config.js';
18
18
  import { ensureNginxInclude } from '../../core/nginx-conf-generator.js';
19
+ import { isWindows } from '../../core/platform.js';
19
20
 
20
- const isWindows = process.platform === 'win32';
21
+ // ─── Helpers ────────────────────────────────────────────────────────────────
22
+ import { access } from 'fs/promises';
23
+
24
+ async function pathExists(p) {
25
+ try {
26
+ await access(p);
27
+ return true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
21
32
 
22
33
  // ─── getNginxStatus ───────────────────────────────────────────────────────────
23
34
 
@@ -55,6 +66,20 @@ async function testConfig(nginxExe, nginxDir) {
55
66
  await ensureNginxInclude(nginxDir);
56
67
  const cmd = isWindows ? `& "${nginxExe}" -t` : 'nginx -t';
57
68
  const result = await run(cmd, { cwd: nginxDir });
69
+ const PathDomain = await pathExists(`${nginxDir}\\conf\\conf.d`);
70
+ const willKnown = await pathExists(`${nginxDir}\\html\\.well-known`);
71
+
72
+ if (!PathDomain) {
73
+ console.warn(chalk.yellow(`Warning: conf.d directory not found in ${nginxDir} — creating it now...`));
74
+ await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
75
+ }
76
+
77
+ if (!willKnown) {
78
+ console.warn(chalk.yellow(`Warning: .well-known/acme-challenge directory not found in ${nginxDir} — creating it now...`));
79
+ await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\`, { recursive: true }));
80
+ await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\acme-challenge`, { recursive: true }));
81
+ }
82
+
58
83
  return {
59
84
  success: result.success,
60
85
  output: (result.stdout + '\n' + result.stderr).trim(),
@@ -106,6 +131,7 @@ async function restartNginx(nginxExe, nginxDir) {
106
131
  let result;
107
132
  if (isWindows) {
108
133
  await run('taskkill /f /IM nginx.exe', { cwd: nginxDir });
134
+ await new Promise(resolve => setTimeout(resolve, 2000));
109
135
  result = await run(`& "${nginxExe}"`, { cwd: nginxDir });
110
136
  } else {
111
137
  result = await run('systemctl restart nginx');
@@ -239,32 +265,33 @@ async function installNginx() {
239
265
 
240
266
  // ── Windows ──────────────────────────────────────────────────────────────────
241
267
  const spinner = ora('Checking for winget…').start();
268
+ //! Winget is not reliably available on all Windows versions (missing from Windows Server, and some users report it missing on Windows 10 desktop), so we'll skip it for now and go straight to the direct download method. We can revisit this in the future if winget becomes more ubiquitous.
242
269
 
243
270
  // Try winget first (available on Windows 10/11 desktop; not on Windows Server by default)
244
- const wingetCheck = await run('where.exe winget 2>$null');
245
- const hasWinget = wingetCheck.success && wingetCheck.stdout.trim().length > 0;
246
-
247
- if (hasWinget) {
248
- spinner.text = 'Installing nginx via winget…';
249
- const result = await run(
250
- 'winget install -e --id Nginx.Nginx --accept-package-agreements --accept-source-agreements',
251
- { timeout: 120000 },
252
- );
253
- if (result.success) {
254
- spinner.succeed('nginx installed successfully');
255
- return { success: true, message: 'nginx installed successfully', output: result.stdout };
256
- }
257
- spinner.fail('winget install failed');
258
- console.log(chalk.red(result.stderr || result.stdout));
259
- console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
260
- return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
261
- }
271
+ // const wingetCheck = await run('where.exe winget 2>$null');
272
+ // const hasWinget = wingetCheck.success && wingetCheck.stdout.trim().length > 0;
273
+
274
+ // if (hasWinget) {
275
+ // spinner.text = 'Installing nginx via winget…';
276
+ // const result = await run(
277
+ // 'winget install -e --id Nginx.Nginx --accept-package-agreements --accept-source-agreements',
278
+ // { timeout: 120000 },
279
+ // );
280
+ // if (result.success) {
281
+ // spinner.succeed('nginx installed successfully');
282
+ // return { success: true, message: 'nginx installed successfully', output: result.stdout };
283
+ // }
284
+ // spinner.fail('winget install failed');
285
+ // console.log(chalk.red(result.stderr || result.stdout));
286
+ // console.log(chalk.gray('\n Manual instructions: https://nginx.org/en/docs/install.html\n'));
287
+ // return { success: false, message: 'Installation failed', output: result.stderr || result.stdout };
288
+ // }
262
289
 
263
290
  // ── Fallback: direct download from nginx.org ─────────────────────────────────
264
291
  spinner.text = 'Fetching latest nginx version…';
265
292
 
266
293
  // Try to resolve the current stable version; fall back to a known-good release
267
- const FALLBACK_VERSION = '1.26.3';
294
+ const FALLBACK_VERSION = '1.29.6';
268
295
  let nginxVersion = FALLBACK_VERSION;
269
296
 
270
297
  const fetchVersionResult = await run(
@@ -311,6 +338,19 @@ async function installNginx() {
311
338
  return { success: false, message: 'nginx.exe not found after extraction' };
312
339
  }
313
340
 
341
+ // Create conf/conf.d directory for domain config files
342
+ await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\conf\\conf.d`, { recursive: true }));
343
+
344
+ await import('fs/promises').then(fs => fs.mkdir(`${nginxDir}\\html\\.well-known\\`, { recursive: true }));
345
+ // Create html/.well-known/acme-challenge directory for SSL certificate verification
346
+ await import('fs/promises').then(fs => fs.writeFile(`${nginxDir}\\html\\.well-known\\acme-challenge`, '', (err) => {
347
+ if (err) {
348
+ console.error(chalk.red(`Failed to create acme-challenge directory: ${err.message}`));
349
+ } else {
350
+ console.log(chalk.green('Created acme-challenge directory for SSL certificate verification'));
351
+ }
352
+ }));
353
+
314
354
  spinner.succeed(`nginx ${nginxVersion} installed to ${nginxDir}`);
315
355
  return { success: true, message: `nginx ${nginxVersion} installed successfully`, output: '' };
316
356
  }