From 893c8bc731bb3c44d3cb5c87f83035f7b3efc3a4 Mon Sep 17 00:00:00 2001 From: Yusuke Hirao Date: Wed, 7 Jan 2026 18:06:50 +0900 Subject: [PATCH 1/3] feat(kamado): add --config CLI option to specify config file path --- packages/kamado/src/config/load.ts | 5 +++-- packages/kamado/src/index.ts | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/kamado/src/config/load.ts b/packages/kamado/src/config/load.ts index 871436c..785218f 100644 --- a/packages/kamado/src/config/load.ts +++ b/packages/kamado/src/config/load.ts @@ -11,10 +11,11 @@ const explorer = cosmiconfig('kamado'); /** * Gets configuration from config file * Searches for kamado config file (kamado.config.js, kamado.config.json, etc.) and merges with defaults + * @param configPath - Optional path to a specific config file. If provided, loads from this path instead of searching. * @returns Configuration object */ -export async function getConfig(): Promise { - const res = await explorer.search(); +export async function getConfig(configPath?: string): Promise { + const res = configPath ? await explorer.load(configPath) : await explorer.search(); const config: UserConfig = res?.config ?? {}; return mergeConfig(config, path.dirname(res?.filepath ?? '')); diff --git a/packages/kamado/src/index.ts b/packages/kamado/src/index.ts index 936793b..7a327d5 100644 --- a/packages/kamado/src/index.ts +++ b/packages/kamado/src/index.ts @@ -1,5 +1,7 @@ #!/usr/bin/env node +import path from 'node:path'; + import { roar } from '@d-zero/roar'; import c from 'ansi-colors'; @@ -8,8 +10,6 @@ import { getConfig } from './config/load.js'; import { pathResolver } from './path/resolver.js'; import { start } from './server/app.js'; -const config = await getConfig(); - const cli = roar({ name: 'kamado', commands: { @@ -21,6 +21,11 @@ const cli = roar({ }, }, flags: { + config: { + type: 'string', + shortFlag: 'c', + desc: 'Path to config file', + }, verbose: { type: 'boolean', desc: 'Enable verbose logging', @@ -33,6 +38,11 @@ const cli = roar({ }, }); +const configPath = cli.flags.config + ? path.resolve(process.cwd(), cli.flags.config) + : undefined; +const config = await getConfig(configPath); + switch (cli.command) { case 'build': { await build({ From f9af335b6d11efdb6f7b624a4943efb593ae6e13 Mon Sep 17 00:00:00 2001 From: Yusuke Hirao Date: Wed, 7 Jan 2026 18:08:58 +0900 Subject: [PATCH 2/3] docs(kamado): add CLI options documentation --- packages/kamado/README.ja.md | 24 ++++++++++++++++++++++-- packages/kamado/README.md | 24 ++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/packages/kamado/README.ja.md b/packages/kamado/README.ja.md index ee0ce39..c1caa1b 100644 --- a/packages/kamado/README.ja.md +++ b/packages/kamado/README.ja.md @@ -232,7 +232,7 @@ scriptCompiler({ - `onBeforeBuild`: ビルド前に実行される関数 - `onAfterBuild`: ビルド後に実行される関数 -### ビルドコマンド +### CLIコマンド #### サイト全体のビルド @@ -248,10 +248,30 @@ kamado build "path/to/*.css" # CSSファイルのみをビルド kamado build "path/to/*.ts" # TypeScriptファイルのみをビルド ``` -### 開発サーバーの起動 +#### 開発サーバーの起動 ```bash kamado server ``` 開発サーバーが起動すると、ブラウザでアクセスしたページがオンデマンドでビルドされます。リクエストがあれば、その場で焼いて返します。 + +### CLIオプション + +すべてのコマンドで以下のオプションが利用可能です: + +| オプション | 短縮形 | 説明 | +| ----------------- | ------ | -------------------------------------------------------------------------------------------- | +| `--config ` | `-c` | 設定ファイルのパスを指定。未指定の場合、`kamado.config.js`、`kamado.config.ts`などを自動探索 | +| `--verbose` | | 詳細なログ出力を有効化 | + +#### 使用例 + +```bash +# 特定の設定ファイルを使用 +kamado build --config ./custom.config.ts +kamado server -c ./dev.config.js + +# ビルド時に詳細ログを出力 +kamado build --verbose +``` diff --git a/packages/kamado/README.md b/packages/kamado/README.md index 44b5a31..10fb6f3 100644 --- a/packages/kamado/README.md +++ b/packages/kamado/README.md @@ -232,7 +232,7 @@ scriptCompiler({ - `onBeforeBuild`: Function executed before build - `onAfterBuild`: Function executed after build -### Build Commands +### CLI Commands #### Build Entire Site @@ -248,10 +248,30 @@ kamado build "path/to/*.css" # Build only CSS files kamado build "path/to/*.ts" # Build only TypeScript files ``` -### Start Development Server +#### Start Development Server ```bash kamado server ``` When the development server starts, pages accessed via the browser are built on demand. If there is a request, it bakes it on the spot and returns it. + +### CLI Options + +The following options are available for all commands: + +| Option | Short | Description | +| ----------------- | ----- | ------------------------------------------------------------------------------------------------------------------ | +| `--config ` | `-c` | Path to a specific config file. If not specified, Kamado searches for `kamado.config.js`, `kamado.config.ts`, etc. | +| `--verbose` | | Enable verbose logging | + +#### Examples + +```bash +# Use a specific config file +kamado build --config ./custom.config.ts +kamado server -c ./dev.config.js + +# Enable verbose logging during build +kamado build --verbose +``` From 7dcbe374d307475c56d55129d348a9fd1da45dfa Mon Sep 17 00:00:00 2001 From: Yusuke Hirao Date: Wed, 7 Jan 2026 18:14:36 +0900 Subject: [PATCH 3/3] fix(kamado): add error handling for missing config file --- packages/kamado/src/config/load.ts | 10 +++++++++- packages/kamado/src/index.ts | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/kamado/src/config/load.ts b/packages/kamado/src/config/load.ts index 785218f..1ddf551 100644 --- a/packages/kamado/src/config/load.ts +++ b/packages/kamado/src/config/load.ts @@ -13,9 +13,17 @@ const explorer = cosmiconfig('kamado'); * Searches for kamado config file (kamado.config.js, kamado.config.json, etc.) and merges with defaults * @param configPath - Optional path to a specific config file. If provided, loads from this path instead of searching. * @returns Configuration object + * @throws {Error} If the specified config file does not exist */ export async function getConfig(configPath?: string): Promise { - const res = configPath ? await explorer.load(configPath) : await explorer.search(); + const res = configPath + ? await explorer.load(configPath).catch((error: NodeJS.ErrnoException) => { + if (error.code === 'ENOENT') { + throw new Error(`Config file not found: ${configPath}`); + } + throw error; + }) + : await explorer.search(); const config: UserConfig = res?.config ?? {}; return mergeConfig(config, path.dirname(res?.filepath ?? '')); diff --git a/packages/kamado/src/index.ts b/packages/kamado/src/index.ts index 7a327d5..a215141 100644 --- a/packages/kamado/src/index.ts +++ b/packages/kamado/src/index.ts @@ -41,7 +41,11 @@ const cli = roar({ const configPath = cli.flags.config ? path.resolve(process.cwd(), cli.flags.config) : undefined; -const config = await getConfig(configPath); +const config = await getConfig(configPath).catch((error: Error) => { + // eslint-disable-next-line no-console + console.error(c.bold.red(error.message)); + process.exit(1); +}); switch (cli.command) { case 'build': {