Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/kamado/README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ scriptCompiler({
- `onBeforeBuild`: ビルド前に実行される関数
- `onAfterBuild`: ビルド後に実行される関数

### ビルドコマンド
### CLIコマンド

#### サイト全体のビルド

Expand All @@ -248,10 +248,30 @@ kamado build "path/to/*.css" # CSSファイルのみをビルド
kamado build "path/to/*.ts" # TypeScriptファイルのみをビルド
```

### 開発サーバーの起動
#### 開発サーバーの起動

```bash
kamado server
```

開発サーバーが起動すると、ブラウザでアクセスしたページがオンデマンドでビルドされます。リクエストがあれば、その場で焼いて返します。

### CLIオプション

すべてのコマンドで以下のオプションが利用可能です:

| オプション | 短縮形 | 説明 |
| ----------------- | ------ | -------------------------------------------------------------------------------------------- |
| `--config <path>` | `-c` | 設定ファイルのパスを指定。未指定の場合、`kamado.config.js`、`kamado.config.ts`などを自動探索 |
| `--verbose` | | 詳細なログ出力を有効化 |

#### 使用例

```bash
# 特定の設定ファイルを使用
kamado build --config ./custom.config.ts
kamado server -c ./dev.config.js

# ビルド時に詳細ログを出力
kamado build --verbose
```
24 changes: 22 additions & 2 deletions packages/kamado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ scriptCompiler({
- `onBeforeBuild`: Function executed before build
- `onAfterBuild`: Function executed after build

### Build Commands
### CLI Commands

#### Build Entire Site

Expand All @@ -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 <path>` | `-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
```
13 changes: 11 additions & 2 deletions packages/kamado/src/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ 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
* @throws {Error} If the specified config file does not exist
*/
export async function getConfig(): Promise<Config> {
const res = await explorer.search();
export async function getConfig(configPath?: string): Promise<Config> {
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 ?? ''));
Expand Down
18 changes: 16 additions & 2 deletions packages/kamado/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env node

import path from 'node:path';

import { roar } from '@d-zero/roar';
import c from 'ansi-colors';

Expand All @@ -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: {
Expand All @@ -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',
Expand All @@ -33,6 +38,15 @@ const cli = roar({
},
});

const configPath = cli.flags.config
? path.resolve(process.cwd(), cli.flags.config)
: undefined;
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': {
await build({
Expand Down