feat: 构建输出按日期命名
添加 dailyVersioning Vite 插件,将构建输出从 index.html 改为 grandclaw-archtype-YYYYMMDD.html 格式
This commit is contained in:
26
openspec/specs/build-output-naming/spec.md
Normal file
26
openspec/specs/build-output-naming/spec.md
Normal file
@@ -0,0 +1,26 @@
|
||||
### Requirement: 构建输出文件命名
|
||||
|
||||
系统 SHALL 在执行 `pnpm build` 时,将输出文件命名为 `grandclaw-archtype-YYYYMMDD.html` 格式,其中 YYYYMMDD 为构建当天的本地日期。
|
||||
|
||||
#### Scenario: 标准构建输出
|
||||
- **WHEN** 执行 `pnpm build` 命令
|
||||
- **THEN** dist 目录中生成文件名为 `grandclaw-archtype-YYYYMMDD.html` 的单文件 HTML
|
||||
- **AND** 文件名为当天本地日期(如 2026年3月28日 构建则输出 `grandclaw-archtype-20260328.html`)
|
||||
|
||||
#### Scenario: 同日多次构建
|
||||
- **WHEN** 同一天内多次执行 `pnpm build`
|
||||
- **THEN** 每次构建输出覆盖同一天的文件
|
||||
- **AND** dist 目录中只存在一个文件
|
||||
|
||||
#### Scenario: 跨天构建
|
||||
- **WHEN** 不同日期执行 `pnpm build`
|
||||
- **THEN** 每次构建生成当天日期命名的文件
|
||||
- **AND** 历史文件被清空(Vite 默认行为,emptyOutDir: true)
|
||||
|
||||
### Requirement: 零额外依赖
|
||||
|
||||
构建输出命名功能 SHALL 通过自定义 Vite 插件实现,不引入额外的 npm 依赖。
|
||||
|
||||
#### Scenario: 依赖检查
|
||||
- **WHEN** 查看 package.json 的 dependencies 和 devDependencies
|
||||
- **THEN** 不存在为文件命名功能新增的依赖项
|
||||
@@ -1,9 +1,32 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import { viteSingleFile } from 'vite-plugin-singlefile'
|
||||
import { renameSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
function dailyVersioning() {
|
||||
return {
|
||||
name: 'daily-versioning',
|
||||
enforce: 'post',
|
||||
writeBundle(options, bundle) {
|
||||
const now = new Date()
|
||||
const date = now.getFullYear()
|
||||
+ String(now.getMonth() + 1).padStart(2, '0')
|
||||
+ String(now.getDate()).padStart(2, '0')
|
||||
|
||||
const oldPath = join(options.dir || 'dist', 'index.html')
|
||||
const newName = `grandclaw-archtype-${date}.html`
|
||||
const newPath = join(options.dir || 'dist', newName)
|
||||
|
||||
if (bundle['index.html']) {
|
||||
renameSync(oldPath, newPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [react(), viteSingleFile()],
|
||||
plugins: [react(), viteSingleFile(), dailyVersioning()],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user