@dongnanyang/deploy-cli 0.5.0 → 0.5.2
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/bin.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const argv = process.argv.slice(2);
|
|
3
3
|
if (argv.length === 0 || argv[0] === "tui") await import("./main.js");
|
|
4
4
|
else {
|
|
5
|
-
const cli = await import("./cli-
|
|
5
|
+
const cli = await import("./cli-BHTqsfkl.js");
|
|
6
6
|
process.exitCode = await cli.main(argv);
|
|
7
7
|
}
|
|
8
8
|
//#endregion
|
|
@@ -490,6 +490,18 @@ function execFailure(cmd, args, result, note) {
|
|
|
490
490
|
const summary = result.stderr.trim().split("\n").filter((line) => line.trim() !== "").slice(0, 3).join(" ");
|
|
491
491
|
return new ExecError(`${note ? `${note}: ` : ""}命令失败: ${[cmd, ...args].join(" ")}(exit ${result.code})${summary ? `: ${summary}` : "(stderr 无输出)"}`, result);
|
|
492
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* 路径探测:sites-available 与 sites-enabled 同时存在 → sites 模式(软链);否则 conf.d 模式(无软链)。
|
|
495
|
+
* 仅凭 sites-available 存在不足以走 sites 模式:无 sites-enabled 时(nginx.conf 直接 include sites-available/*)
|
|
496
|
+
* 软链无处落地,且 .bak/.new 会被 `include ...*` 通配吸入,破坏回滚与删除的生效性。
|
|
497
|
+
*/
|
|
498
|
+
function resolveNginxPaths(exists = existsSync$1) {
|
|
499
|
+
if (exists(DEFAULT_SITES_AVAILABLE) && exists(DEFAULT_SITES_ENABLED)) return {
|
|
500
|
+
sitesAvailable: DEFAULT_SITES_AVAILABLE,
|
|
501
|
+
sitesEnabled: DEFAULT_SITES_ENABLED
|
|
502
|
+
};
|
|
503
|
+
return { sitesAvailable: DEFAULT_CONF_D };
|
|
504
|
+
}
|
|
493
505
|
/** 渲染 server 块;withSsl 时要求 certPath/keyPath(acme 需先 requestCert 取得) */
|
|
494
506
|
function renderBlock(spec, withSsl) {
|
|
495
507
|
validateSpec(spec);
|
|
@@ -525,17 +537,20 @@ function renderBlock(spec, withSsl) {
|
|
|
525
537
|
return lines.join("\n") + "\n";
|
|
526
538
|
}
|
|
527
539
|
function createNginx(runner = run, paths) {
|
|
528
|
-
const
|
|
529
|
-
const
|
|
540
|
+
const resolved = paths ?? resolveNginxPaths();
|
|
541
|
+
const sitesAvailable = resolved.sitesAvailable;
|
|
542
|
+
const sitesEnabled = resolved.sitesEnabled;
|
|
530
543
|
const confName = (slug) => `${CONF_PREFIX}${slug}${CONF_SUFFIX}`;
|
|
544
|
+
const tmpName = (slug) => `.${confName(slug)}.new`;
|
|
545
|
+
const bakName = (slug) => `.${confName(slug)}.bak`;
|
|
531
546
|
/**
|
|
532
|
-
*
|
|
547
|
+
* 写盘/回滚流程:新内容写隐藏 .conf.new → 旧 conf 备份隐藏 .bak → .new 原子改名 → 建 sites-enabled 软链 → nginx -t;
|
|
533
548
|
* 失败:恢复 .bak(或删新文件)、移除本次新建的软链、抛 ExecError;成功:nginx -s reload、清 .bak。
|
|
534
549
|
*/
|
|
535
550
|
async function writeSite(slug, content) {
|
|
536
551
|
const conf = join$1(sitesAvailable, confName(slug));
|
|
537
|
-
const tmp =
|
|
538
|
-
const bak =
|
|
552
|
+
const tmp = join$1(sitesAvailable, tmpName(slug));
|
|
553
|
+
const bak = join$1(sitesAvailable, bakName(slug));
|
|
539
554
|
writeFileSync$1(tmp, content, "utf-8");
|
|
540
555
|
const existed = pathExists(conf);
|
|
541
556
|
if (existed) renameSync(conf, bak);
|
|
@@ -609,7 +624,7 @@ function createNginx(runner = run, paths) {
|
|
|
609
624
|
validateSlug(slug);
|
|
610
625
|
const conf = join$1(sitesAvailable, confName(slug));
|
|
611
626
|
if (!pathExists(conf)) throw new Error(`未找到站点配置: ${conf}`);
|
|
612
|
-
const bak =
|
|
627
|
+
const bak = join$1(sitesAvailable, bakName(slug));
|
|
613
628
|
const link = sitesEnabled ? join$1(sitesEnabled, confName(slug)) : void 0;
|
|
614
629
|
const hadLink = link ? pathExists(link) : false;
|
|
615
630
|
renameSync(conf, bak);
|