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}`) +}