From f2df46d9c33eb532cbdfcd7304de298405f26d25 Mon Sep 17 00:00:00 2001 From: Melvin Chia Date: Tue, 28 Oct 2025 07:08:30 +0800 Subject: [PATCH] feat(cli): add changelog command to generate weekly changelog files Former-commit-id: 9c89da5f0b1dcc1042cc320f32d718c40b7a4392 [formerly bea54deb075ec948ee9d914a98a47e826a361f7b] [formerly 200c3f74654011a8bc09ae68441d30a8969b0581 [formerly d45ad02e725dfeebe47daaa2518d2c24b8cc5508]] Former-commit-id: 882f17a5e3b0c15d407240e6baefefa9cb4b69de [formerly b6abcb9a460a8412c952d3d6b9445a14b7b751dc] Former-commit-id: a24cf100c02fed045c9b7f4902c2a8de2b242936 --- tools/forgeCLI/package.json | 1 + tools/forgeCLI/src/cli/setup.ts | 15 ++++++ .../src/commands/changelog-commands.ts | 53 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tools/forgeCLI/src/commands/changelog-commands.ts diff --git a/tools/forgeCLI/package.json b/tools/forgeCLI/package.json index 88ffd93ab..cbc154e75 100644 --- a/tools/forgeCLI/package.json +++ b/tools/forgeCLI/package.json @@ -10,6 +10,7 @@ "@types/babel__traverse": "^7.28.0", "axios": "^1.12.2", "crypto-js": "^4.2.0", + "dayjs": "^1.11.18", "dotenv": "^17.2.3", "handlebars": "^4.7.8", "openai": "^6.7.0", diff --git a/tools/forgeCLI/src/cli/setup.ts b/tools/forgeCLI/src/cli/setup.ts index 9a02767cc..61546af6c 100644 --- a/tools/forgeCLI/src/cli/setup.ts +++ b/tools/forgeCLI/src/cli/setup.ts @@ -1,6 +1,7 @@ import { program } from 'commander' import fs from 'fs' +import { createChangelogHandler } from '../commands/changelog-commands' import * as dbHandlers from '../commands/db-commands' import { devHandler, getAvailableServices } from '../commands/dev-commands' import * as moduleHandlers from '../commands/module-commands' @@ -27,6 +28,7 @@ export function setupCLI(): void { setupDevCommand() setupModulesCommand() setupDatabaseCommands() + setupChangelogCommand() } /** @@ -139,6 +141,19 @@ function setupDatabaseCommands(): void { .action(dbHandlers.generateMigrationsHandler) } +function setupChangelogCommand(): void { + const command = program + .command('changelog') + .description('Generate changelog for LifeForge releases') + + command + .command('create') + .description('Create a changelog file in the docs directory') + .argument('[year]', 'Year for the changelog, e.g., 2025') + .argument('[week]', 'Week number for the changelog, e.g., 42') + .action(createChangelogHandler) +} + /** * Parses command line arguments and runs the CLI */ diff --git a/tools/forgeCLI/src/commands/changelog-commands.ts b/tools/forgeCLI/src/commands/changelog-commands.ts new file mode 100644 index 000000000..115f0ee7c --- /dev/null +++ b/tools/forgeCLI/src/commands/changelog-commands.ts @@ -0,0 +1,53 @@ +import dayjs from 'dayjs' +import weekOfYear from 'dayjs/plugin/weekOfYear' +import fs from 'fs' + +import { CLILoggingService } from '../utils/logging' + +dayjs.extend(weekOfYear) + +const boilerPlate = `import Commit from "../../components/Commit"; +import Code from "@/components/Code"; + +### 🏗️ Infrastructure & Technical Improvements + +### 🎨 UI Components & Design System + +### 🐛 Bug Fixes & Chores + +### 📖 Documentation & Tooling +` + +const CHANGELOG_PATH = 'docs/src/contents/04.progress/versions' + +export function createChangelogHandler(year?: string, week?: string) { + const targetYear = Number(year) || dayjs().year() + + const currentWeek = Number(week) || dayjs().week() + + if (!fs.existsSync(CHANGELOG_PATH)) { + CLILoggingService.error( + `Changelog directory not found at path: ${CHANGELOG_PATH}` + ) + process.exit(1) + } + + const yearPath = `${CHANGELOG_PATH}/${targetYear}` + + if (!fs.existsSync(yearPath) || !fs.lstatSync(yearPath).isDirectory()) { + fs.mkdirSync(yearPath) + } + + const filePath = `${yearPath}/${String(currentWeek).padStart(2, '0')}.mdx` + + if (fs.existsSync(filePath)) { + CLILoggingService.error( + `Changelog file for year ${targetYear} week ${currentWeek} already exists at path: ${filePath}` + ) + process.exit(1) + } + + fs.writeFileSync(filePath, boilerPlate) + + CLILoggingService.success(`Changelog file created at path: ${filePath}`) +}