From 23484a04332edfccc69e3335aee249cc33242d26 Mon Sep 17 00:00:00 2001 From: dsh Date: Tue, 15 Sep 2026 19:49:40 +0800 Subject: [PATCH] =?UTF-8?q?new-post=20/=20new-thought=EF=BC=9A=E6=BC=8F?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=97=B6=E5=85=88=E8=AF=B4=E6=B8=85=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=EF=BC=8C=E4=B8=8D=E5=86=8D=E5=83=8F=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=B4=A9=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 无参数调用时脚本会打印用法并 exit 1(语义是对的:缺必填参数), 但 pnpm 会再补一句 "[ELIFECYCLE] Command failed with exit code 1", 看起来像脚本崩了而不是用法提示。 改成在用法前面先输出一行: 缺少正文内容,没有创建任何文件。 正确写法:pnpm new-thought "今天把树莓派的散热换掉了。" exit 码不变(无参数 1、--help 0),只是把原因说清楚。 --- scripts/new-post.mjs | 5 +++++ scripts/new-thought.mjs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/scripts/new-post.mjs b/scripts/new-post.mjs index 28e4c09..36a68be 100644 --- a/scripts/new-post.mjs +++ b/scripts/new-post.mjs @@ -24,6 +24,11 @@ function today() { const args = process.argv.slice(2) if (args.length === 0 || args[0] === "--help" || args[0] === "-h") { + // 无参数进来时先说清楚原因:下面 pnpm 还会补一句 + // "[ELIFECYCLE] Command failed with exit code 1",不点明的话很像脚本崩了 + if (args.length === 0) { + console.log('缺少文章标题,没有创建任何文件。\n正确写法:pnpm new-post "树莓派装 Docker 全程记录" --category 教程\n') + } console.log(`创建一篇新文章 用法: diff --git a/scripts/new-thought.mjs b/scripts/new-thought.mjs index 5717662..2fd8c69 100644 --- a/scripts/new-thought.mjs +++ b/scripts/new-thought.mjs @@ -33,6 +33,11 @@ function fileStamp() { const args = process.argv.slice(2) if (args.length === 0 || args[0] === "--help" || args[0] === "-h") { + // 无参数进来时先说清楚原因:下面 pnpm 还会补一句 + // "[ELIFECYCLE] Command failed with exit code 1",不点明的话很像脚本崩了 + if (args.length === 0) { + console.log('缺少正文内容,没有创建任何文件。\n正确写法:pnpm new-thought "今天把树莓派的散热换掉了。"\n') + } console.log(`创建一条新的「偶得」 用法: