起きたこと
新規に作成した html-share.config.yaml(content.pages がまだ空の、セットアップ直後の状態)に対して
html-share page add <path> --title "..."
を実行すると、最初の1件のはずが
content.pages must contain at least one page
で失敗します。YAMLファイルを手動で編集して1件足すまで、page add で最初のページを追加する手段がありません。
原因: src/cli.ts の main() が、page コマンドの分岐より先に無条件で loadConfig() を呼んでいます。
const command = process.argv[2];
if (!command || flag('--help') || flag('-h')) usage();
const config = loadConfig(option('--config')); // ← ここで 'page' コマンドも巻き込まれて例外
if (command === 'build') { ... }
...
if (command === 'page') {
const added = addPageToConfig(option('--config'), pagePath, option('--title'));
...
}
loadConfig()(src/config.ts)は content.pages.length > 0 を要求します。
if (pages.length === 0) throw new Error('content.pages must contain at least one page');
しかし page add のハンドラは実際には読み込んだ config オブジェクトを使っておらず、addPageToConfig() が生YAMLを直接読み書きするだけの実装です。そのため page add 自体には不要な検証に巻き込まれ、しかも「最初のページを追加する」という唯一の手段そのものが使えなくなっています。
修正案: page コマンドの分岐を loadConfig() 呼び出しより前に移動し、config検証を経由しないようにする。
async function main(): Promise<void> {
const command = process.argv[2];
if (!command || flag('--help') || flag('-h')) usage();
if (command === 'page') {
const action = process.argv[3];
const pagePath = process.argv[4];
if (action !== 'add' || !pagePath) usage();
const added = addPageToConfig(option('--config'), pagePath, option('--title'));
console.log(JSON.stringify({ ok: true, added, path: pagePath }));
return;
}
const config = loadConfig(option('--config'));
// 以降の他コマンドは変更なし
}
自分のCloudflareバックエンド版fork(joelmitz/html-share@f1ca1f6)でこの修正と回帰テストを検証済みです。よろしければPRも出せますし、こちらのdiffを直接採用いただいても構いません。
再現手順
content.pages: [] の状態で html-share.config.yaml を用意する(新規セットアップ直後を想定)
html-share page add pages/demo.html --title "デモ" を実行する
content.pages must contain at least one page で失敗する
バージョン
0.1.0(commit HEAD時点。cli.ts/config.tsのこの箇所は変更なく現行mainに存在)
実行環境
Node.js 22 / OS問わず(CLIロジックのみが原因)
起きたこと
新規に作成した
html-share.config.yaml(content.pagesがまだ空の、セットアップ直後の状態)に対してを実行すると、最初の1件のはずが
で失敗します。YAMLファイルを手動で編集して1件足すまで、
page addで最初のページを追加する手段がありません。原因:
src/cli.tsのmain()が、pageコマンドの分岐より先に無条件でloadConfig()を呼んでいます。loadConfig()(src/config.ts)はcontent.pages.length > 0を要求します。しかし
page addのハンドラは実際には読み込んだconfigオブジェクトを使っておらず、addPageToConfig()が生YAMLを直接読み書きするだけの実装です。そのためpage add自体には不要な検証に巻き込まれ、しかも「最初のページを追加する」という唯一の手段そのものが使えなくなっています。修正案:
pageコマンドの分岐をloadConfig()呼び出しより前に移動し、config検証を経由しないようにする。自分のCloudflareバックエンド版fork(joelmitz/html-share@f1ca1f6)でこの修正と回帰テストを検証済みです。よろしければPRも出せますし、こちらのdiffを直接採用いただいても構いません。
再現手順
content.pages: []の状態でhtml-share.config.yamlを用意する(新規セットアップ直後を想定)html-share page add pages/demo.html --title "デモ"を実行するcontent.pages must contain at least one pageで失敗するバージョン
0.1.0(commit HEAD時点。cli.ts/config.tsのこの箇所は変更なく現行mainに存在)
実行環境
Node.js 22 / OS問わず(CLIロジックのみが原因)