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
This commit is contained in:
Melvin Chia
2025-10-28 07:08:30 +08:00
parent 390ac10cdd
commit f2df46d9c3
3 changed files with 69 additions and 0 deletions

View File

@@ -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",

View File

@@ -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
*/

View File

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