chore: structure refactor, linting, and monorepo setup (#629)

* chore: use monorepo to manage demo, test and other applications and internal packages

* style: add eslint support and lint code

* chore: refactor project structure and add versioning package replace of fixit-releaser

* chore(deps-dev): replace husky with simple-git-hooks

* Potential fix for code scanning alert no. 13: Shell command built from environment values

* chore(deps-dev): update the final fixit-releaser version

* docs: update contributing guidelines for new structure and commands

---------

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Cell
2025-08-31 15:07:00 +08:00
committed by GitHub
parent c923116b9b
commit d8624386c7
43 changed files with 3721 additions and 304 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
name: Bug Report
description: Create a report to help us improve
title: "[Bug report] "
title: '[Bug report] '
body:
- type: markdown
attributes:
+1 -1
View File
@@ -1,6 +1,6 @@
name: Feature Request
description: Suggest an idea for this project
title: "[Feature request] "
title: '[Feature request] '
body:
- type: markdown
attributes:
+1 -1
View File
@@ -1,4 +1,4 @@
name: "CodeQL config"
name: CodeQL config
paths-ignore:
- assets/lib/**
+18 -19
View File
@@ -17,21 +17,24 @@ FixIt 是一个面向 Hugo 静态网站生成器的现代化、响应式主题
```
FixIt/
├── apps/ # 最小化站点
│ ├── demo/ # 演示站点
│ └── test/ # 测试站点
├── archetypes/ # 内容模板
├── assets/ # 主题资源文件
│ ├── css/ # SCSS 样式文件
│ ├── js/ # JavaScript 文件
│ ├── images/ # 图像资源
│ └── lib/ # 第三方库
├── demo/ # 演示站点
├── i18n/ # 国际化翻译文件
├── layouts/ # Hugo 模板文件
│ ├── _markup/ # Hugo 渲染钩子
│ ├── _partials/ # 可复用模板组件
│ └── _shortcodes/ # 自定义短代码
├── packages/ # 主题相关包
├── static/ # 静态文件
├── test/ # 测试站点内容
└── hugo.toml # 主题默认配置
├── hugo.toml # 主题默认配置
└── package.json # npm 脚本和依赖
```
## SCSS/CSS 编码规范
@@ -121,29 +124,21 @@ FixIt/
```javascript
// 使用 ES6 类
export default class Util {
/**
* 工具函数示例
* @param {String} text 要复制的文本
* @returns {Promise} 返回 Promise
*/
copyText(text) {
if (navigator.clipboard) {
return navigator.clipboard.writeText(text);
}
// 降级方案...
// ...
}
}
// 主题类组织
class FixIt {
constructor() {
this.config = window.config;
this.util = new Util();
this.config = window.config
this.util = new Util()
}
init() {
this.initTheme();
this.initComponents();
this.initTheme()
this.initComponents()
}
}
```
@@ -226,9 +221,13 @@ class FixIt {
2. **开发命令**:
```bash
pnpm dev # 启动开发服务器
pnpm test # 运行测试环境
pnpm build # 构建 Demo
pnpm dev:demo # 启动 demo 站点开发服务器
pnpm dev:test # 启动 test 站点开发服务器
pnpm dev:docs # 启动文档开发服务器(需有 fixit-docs 作为同级目录)
pnpm build:demo # 构建 demo 站点
pnpm build:test # 构建 test 站点
pnpm build # 一键构建所有站点
pnpm preview # 预览构建后的站点(需先构建)
```
### 代码质量
+29 -15
View File
@@ -5,30 +5,44 @@
version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: npm # See documentation for possible values
directory: / # Location of package manifests
schedule:
interval: "monthly"
interval: monthly
open-pull-requests-limit: 1000
assignees:
- "Lruihao"
- Lruihao
labels:
- "dependencies"
- package-ecosystem: "github-actions"
directory: "/"
- dependencies
ignore:
- dependency-name: '@types/node'
update-types:
- 'version-update:semver-major'
groups:
npm-development:
dependency-type: development
update-types:
- minor
- patch
npm-production:
dependency-type: production
update-types:
- patch
- package-ecosystem: github-actions
directory: /
schedule:
interval: "monthly"
interval: monthly
open-pull-requests-limit: 1000
assignees:
- "Lruihao"
- Lruihao
labels:
- "dependencies"
- package-ecosystem: "gitsubmodule"
directory: "/"
- dependencies
- package-ecosystem: gitsubmodule
directory: /
schedule:
interval: "weekly"
interval: weekly
open-pull-requests-limit: 1000
assignees:
- "Lruihao"
- Lruihao
labels:
- "dependencies"
- dependencies
+1 -1
View File
@@ -16,4 +16,4 @@ changelog:
- bug
- title: Other Changes
labels:
- "*"
- '*'
+3 -3
View File
@@ -9,7 +9,7 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: CodeQL
on:
push:
@@ -19,7 +19,7 @@ on:
branches:
- main
schedule:
- cron: "30 18 * * 5"
- cron: '30 18 * * 5'
jobs:
analyze:
@@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ "javascript" ]
language: [javascript]
# CodeQL supports [ "cpp", "csharp", "go", "java", "javascript", "python" ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
+2 -2
View File
@@ -31,9 +31,9 @@ jobs:
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
title: 'Update hugo-fixit component list'
title: Update hugo-fixit component list
commit-message: 'docs(readme): update hugo-fixit component list'
body: 'This PR updates the hugo-fixit component list in the README.'
body: This PR updates the hugo-fixit component list in the README.
base: main
branch: update-component-list
labels: documentation
+3 -4
View File
@@ -30,12 +30,11 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
node-version-file: .nvmrc
- name: Install dependencies and generate release notes
- name: Generate release notes
run: |
npm install
npm run release -- --starting-version ${{ github.ref_name }}
npx fixit-releaser changelog --starting-version ${{ github.ref_name }}
sed -i '1,4d' CHANGELOG.md
- name: GitHub Release
+1
View File
@@ -8,6 +8,7 @@ jsconfig.json
# NPM
node_modules/
.eslintcache
# VSCode
.vscode/*
-1
View File
@@ -1 +0,0 @@
npx fixit-releaser version --dev
+1 -1
View File
@@ -1,2 +1,2 @@
tag-version-prefix="v"
message=":bookmark: Chore(release): %s"
message="chore(release): %s"
+76 -1
View File
@@ -3,7 +3,82 @@
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"tsconfig.json": "tsconfig.*.json, env.d.ts",
"vite.config.*": "jsconfig*, vitest.config.*, cypress.config.*, playwright.config.*",
"package.json": "package-lock.json, pnpm*, .yarnrc*, yarn*, .eslint*, eslint*, .oxlint*, oxlint*, .prettier*, prettier*, .editorconfig"
},
// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,
// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{
"rule": "style/*",
"severity": "off",
"fixable": true
},
{
"rule": "format/*",
"severity": "off",
"fixable": true
},
{
"rule": "*-indent",
"severity": "off",
"fixable": true
},
{
"rule": "*-spacing",
"severity": "off",
"fixable": true
},
{
"rule": "*-spaces",
"severity": "off",
"fixable": true
},
{
"rule": "*-order",
"severity": "off",
"fixable": true
},
{
"rule": "*-dangle",
"severity": "off",
"fixable": true
},
{
"rule": "*-newline",
"severity": "off",
"fixable": true
},
{
"rule": "*quotes",
"severity": "off",
"fixable": true
},
{
"rule": "*semi",
"severity": "off",
"fixable": true
}
],
// Enable eslint for all supported languages
"eslint.validate": [
"go-html-template",
"javascript",
"html",
"markdown",
"json",
"json5",
"jsonc",
"yaml",
"toml",
"xml",
"css",
"scss"
]
}
+20 -21
View File
@@ -41,38 +41,34 @@ Here are some useful commands for development:
### Development
```bash
# Run local server with demo content
pnpm dev
# Run local server with test content
pnpm test
# Run local server with documentation (requires fixit-docs as sibling directory)
# Start demo site development server
pnpm dev:demo
# Start test site development server
pnpm dev:test
# Start documentation development server (requires fixit-docs as sibling directory)
pnpm dev:docs
```
> [!TIP]
>
> - You can run `pnpm dev -e production` or `pnpm test -e production` to check the production environment.
> - If you want to work on documentation-related theme changes, the simplest way is to have both `FixIt` and `fixit-docs` cloned as sibling directories.
> - Add `-e production` to the development command to check the production environment, e.g. `pnpm dev:test -e production`.
> - For documentation-related theme changes, it is recommended to clone both `FixIt` and `fixit-docs` as sibling directories.
### Building
```bash
# Build demo site
pnpm build
pnpm build:demo
# Build test site
pnpm build:test
# Build both demo and test sites for deployment (includes public directory reorganization)
pnpm build:vercel
# Build all sites
pnpm build
```
### Preview
```bash
# Preview the built site locally (requires build:vercel first)
# Preview the built site locally (requires build first)
pnpm preview
```
@@ -82,21 +78,24 @@ Understanding the project structure will help you contribute more effectively:
```
FixIt/
├── apps/ # Minimal sites
│ ├── demo/ # Demo site
│ └── test/ # Test site
├── archetypes/ # Content templates
├── assets/ # Theme assets (CSS, JS, images)
├── assets/ # Theme assets
│ ├── css/ # SCSS stylesheets
│ ├── js/ # JavaScript files
│ ├── images/ # Image assets
│ └── lib/ # Third-party libraries
├── demo/ # Demo site for development
├── i18n/ # Internationalization files
├── layouts/ # Hugo template files
│ ├── _markup/ # Hugo render hooks
│ ├── _partials/ # Reusable template components
│ └── _shortcodes/ # Custom shortcodes
├── packages/ # Theme-related packages
├── static/ # Static files
├── test/ # Test site content
── package.json # npm scripts and dependencies
└── hugo.toml # Default theme configuration
├── hugo.toml # Default theme configuration
── package.json # npm scripts and dependencies
```
## Development Workflow
@@ -119,4 +118,4 @@ Finally, create a new pull request at <https://github.com/hugo-fixit/FixIt/pulls
## Git Commit Guidelines
We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages. This enables automatic changelog generation using our custom template: [conventional.hbs](https://github.com/hugo-fixit/fixit-releaser/blob/main/changelog/conventional.hbs).
We follow the [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages. This enables automatic changelog generation using our custom template: [conventional.hbs](https://github.com/hugo-fixit/fixit-releaser/blob/main/src/changelog/conventional.hbs).
+4 -9
View File
@@ -25,26 +25,21 @@
> It is based on the original [LoveIt](https://github.com/dillonzq/LoveIt) Theme, [KeepIt](https://github.com/Fastbyte01/KeepIt) Theme and [LeaveIt](https://github.com/liuzc/LeaveIt) Theme.
[![Build](https://img.shields.io/github/deployments/hugo-fixit/FixIt/Production?style=flat&label=Build&logo=vercel)](https://demo.fixit.lruihao.cn/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat&label=Release&logo=github)](https://github.com/hugo-fixit/FixIt/releases)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat&label=Release&logo=github&include_prereleases)](https://github.com/hugo-fixit/FixIt/releases)
[![Hugo](https://img.shields.io/badge/Hugo-%5E0.147.7-ff4088?style=flat&logo=hugo)](https://gohugo.io/)
[![License](https://img.shields.io/github/license/hugo-fixit/FixIt?style=flat&label=License)](/LICENSE)
[![Gitee star of FixIt](https://gitee.com/lruihao/FixIt/badge/star.svg?theme=dark)](https://gitee.com/lruihao/FixIt/stargazers)
[![GitHub stars](https://img.shields.io/github/stars/hugo-fixit/FixIt?style=social)](https://github.com/hugo-fixit/FixIt)
[![Gitee star of FixIt](https://gitee.com/lruihao/FixIt/badge/star.svg)](https://gitee.com/lruihao/FixIt/stargazers)
## Live Preview
<p align="center">
💟 <a href="https://fixit.lruihao.cn">Production</a> | ❇️ <a href="https://pre.fixit.lruihao.cn">Preview</a> | 🚼 <a href="https://demo.fixit.lruihao.cn">Demo</a> | 🆕 <a href="https://hugo-fixit.github.io/hugo-fixit-starter/">Starter</a>
💟 <a href="https://fixit.lruihao.cn">Docs</a> | ❇️ <a href="https://demo.fixit.lruihao.cn/test/">Test</a> | 🚼 <a href="https://demo.fixit.lruihao.cn">Demo</a> | 🆕 <a href="https://hugo-fixit.github.io/hugo-fixit-starter/">Starter</a>
<br>
<br>
More FixIt examples <a href="https://fixit.lruihao.cn/showcase/">here</a>.
</p>
## Why choose FixIt
I don't know why 🤷.
<!-- Too lazy to write... -->
## Usage
### Documentation
+4 -9
View File
@@ -25,26 +25,21 @@
> 它的原型基于 [LoveIt](https://github.com/dillonzq/LoveIt) 主题,[KeepIt](https://github.com/Fastbyte01/KeepIt) 主题和 [LeaveIt](https://github.com/liuzc/LeaveIt) 主题。
[![Build](https://img.shields.io/github/deployments/hugo-fixit/FixIt/Production?style=flat&label=Build&logo=vercel)](https://demo.fixit.lruihao.cn/)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat&label=Release&logo=github)](https://github.com/hugo-fixit/FixIt/releases)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/hugo-fixit/FixIt?style=flat&label=Release&logo=github&include_prereleases)](https://github.com/hugo-fixit/FixIt/releases)
[![Hugo](https://img.shields.io/badge/Hugo-%5E0.147.7-ff4088?style=flat&logo=hugo)](https://gohugo.io/)
[![License](https://img.shields.io/github/license/hugo-fixit/FixIt?style=flat&label=License)](/LICENSE)
[![Gitee star of FixIt](https://gitee.com/lruihao/FixIt/badge/star.svg?theme=dark)](https://gitee.com/lruihao/FixIt/stargazers)
[![GitHub stars](https://img.shields.io/github/stars/hugo-fixit/FixIt?style=social)](https://github.com/hugo-fixit/FixIt)
[![Gitee star of FixIt](https://gitee.com/lruihao/FixIt/badge/star.svg)](https://gitee.com/lruihao/FixIt/stargazers)
## 即时预览
<p align="center">
💟 <a href="https://fixit.lruihao.cn/zh-cn/">Production</a> | ❇️ <a href="https://pre.fixit.lruihao.cn/zh-cn/">Preview</a> | 🚼 <a href="https://demo.fixit.lruihao.cn">Demo</a> | 🆕 <a href="https://hugo-fixit.github.io/hugo-fixit-starter/">Starter</a>
💟 <a href="https://fixit.lruihao.cn">Docs</a> | ❇️ <a href="https://demo.fixit.lruihao.cn/test/">Test</a> | 🚼 <a href="https://demo.fixit.lruihao.cn">Demo</a> | 🆕 <a href="https://hugo-fixit.github.io/hugo-fixit-starter/">Starter</a>
<br>
<br>
更多 FixIt 的例子参见 <a href="https://fixit.lruihao.cn/zh-cn/showcase/">这里</a>。
</p>
## 为什么选择 FixIt
我也不知道为什么 🤷。
<!-- 懒的写…… -->
## 使用指南
### 主题文档
+8
View File
@@ -0,0 +1,8 @@
{
"name": "@hugo-fixit/demo",
"private": true,
"scripts": {
"build": "hugo --themesDir ../../.. --theme $PWD/../.. --gc --minify --logLevel info",
"dev": "hugo server --themesDir ../../.. --theme $PWD/../.. -D --disableFastRender --navigateToChanged --ignoreCache -O"
}
}
@@ -11,8 +11,6 @@ tags:
- Diagrams
---
The FixIt theme supports two ways to use Mermaid: code block syntax and shortcode syntax.
## Flowchart
+8
View File
@@ -0,0 +1,8 @@
{
"name": "@hugo-fixit/test",
"private": true,
"scripts": {
"build": "hugo --themesDir ../../.. --theme $PWD/../.. --gc --minify --logLevel info",
"dev": "hugo server --themesDir ../../.. --theme $PWD/../.. -D --disableFastRender --navigateToChanged --ignoreCache -O"
}
}
-1
View File
@@ -74,4 +74,3 @@ libFiles:
walineJS: '@waline/client@3.4.1/dist/waline.umd.js'
# xxhash-wasm@1.0.2 https://github.com/jungomi/xxhash-wasm
xxhashWasmJS: xxhash-wasm@1.0.2/umd/xxhash-wasm.js
+1 -1
View File
@@ -329,7 +329,7 @@ strava:
# 042: Skype
skype:
Weight: 42
Template: "skype:"
Template: 'skype:'
Title: Skype
Icon:
Class: fa-brands fa-skype fa-fw
+16
View File
@@ -0,0 +1,16 @@
import antfu from '@antfu/eslint-config'
export default antfu({
typescript: true,
ignores: [
'node_modules/**',
'assets/lib/**',
'public/**',
'layouts/**/*.json',
'layouts/**/*.xml',
'layouts/**/*.md',
// 临时忽略
'assets/js/**',
'**/*.toml',
],
})
+1 -1
View File
@@ -1,4 +1,4 @@
{{- hugo.Store.Set "version" "v0.4.0-alpha-20250825095946-e9366b5a" -}}
{{- hugo.Store.Set "version" "v0.4.0-alpha-20250831070510-5a66a050" -}}
{{- .Store.Set "this" dict -}}
{{- partial "init/detection-env.html" . -}}
-42
View File
@@ -1,42 +0,0 @@
#!/bin/bash
# Shell script to move public directories
# Usage: ./move-public.sh
set -e # Exit on any error
# Get the script directory (where this script is located)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Moving public directories..."
# Check if demo/public exists
if [ -d "$SCRIPT_DIR/demo/public" ]; then
echo "Moving demo/public/ to public/..."
# Remove existing public directory if it exists
if [ -d "$SCRIPT_DIR/public" ]; then
echo "Removing existing public/ directory..."
rm -rf "$SCRIPT_DIR/public"
fi
# Move demo/public to public
mv "$SCRIPT_DIR/demo/public" "$SCRIPT_DIR/public"
echo "✓ Moved demo/public/ to public/"
else
echo "⚠️ demo/public/ directory not found, skipping..."
fi
# Check if test/public exists
if [ -d "$SCRIPT_DIR/test/public" ]; then
echo "Moving test/public/ to public/test/..."
# Create public/test directory if it doesn't exist
mkdir -p "$SCRIPT_DIR/public/test"
# Move test/public contents to public/test
mv "$SCRIPT_DIR/test/public"/* "$SCRIPT_DIR/public/test/" 2>/dev/null || true
# Remove empty test/public directory
rmdir "$SCRIPT_DIR/test/public" 2>/dev/null || true
echo "✓ Moved test/public/ to public/test/"
else
echo "⚠️ test/public/ directory not found, skipping..."
fi
echo "✅ Public directories moved successfully!"
+47 -30
View File
@@ -1,49 +1,66 @@
{
"name": "fixit-core",
"name": "@hugo-fixit/core",
"type": "module",
"version": "0.4.0-alpha",
"private": true,
"packageManager": "pnpm@10.5.2",
"description": "Hugo FixIt core theme component source files",
"author": {
"name": "Lruihao",
"email": "1024@lruihao.cn",
"url": "https://lruihao.cn"
},
"license": "MIT",
"homepage": "https://fixit.lruihao.cn",
"repository": {
"type": "git",
"url": "git+https://github.com/hugo-fixit/FixIt.git"
},
"bugs": {
"url": "https://github.com/hugo-fixit/FixIt/issues"
},
"keywords": [
"hugo",
"theme",
"fixit"
],
"homepage": "https://fixit.lruihao.cn",
"bugs": {
"url": "https://github.com/hugo-fixit/FixIt/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/hugo-fixit/FixIt.git"
},
"license": "MIT",
"author": "Lruihao (https://lruihao.cn)",
"type": "module",
"scripts": {
"build": "hugo --source=demo --themesDir ../.. --theme $PWD --gc --minify --logLevel info",
"build:test": "hugo --source=test --themesDir ../.. --theme $PWD --gc --minify --logLevel info",
"build:vercel": "npm run build && npm run build:test && ./move-public.sh",
"preview": "npm run build:vercel && serve public",
"dev": "hugo server --source=demo --themesDir ../.. --theme $PWD -D --disableFastRender --navigateToChanged --ignoreCache -O",
"test": "hugo server --source=test --themesDir ../.. --theme $PWD -D --disableFastRender --navigateToChanged --ignoreCache -O",
"dev:docs": "hugo server --source=../fixit-docs -D --disableFastRender --navigateToChanged --ignoreCache -O",
"version": "fixit-releaser version --prod",
"postversion": "git push && git push --tags && npm run release",
"release": "fixit-releaser changelog",
"prepare": "husky"
},
"devDependencies": {
"@hugo-fixit/fixit-releaser": "^1.3.2",
"husky": "^9.1.7",
"serve": "^14.2.4"
},
"engines": {
"node": ">=20"
},
"scripts": {
"dev:demo": "pnpm -F demo dev",
"dev:test": "pnpm -F test dev",
"dev:docs": "hugo server --source=../fixit-docs -D --disableFastRender --navigateToChanged --ignoreCache -O",
"build:demo": "pnpm -F demo build",
"build:test": "pnpm -F test build",
"build": "pnpm build:demo && pnpm build:test && pnpm -F integration start",
"preview": "serve public",
"lint": "eslint --cache .",
"version": "pnpm -F versioning start prod && pnpm changelog -p",
"postversion": "git push && git push --tags",
"changelog": "fixit-releaser changelog",
"prepare": "simple-git-hooks"
},
"devDependencies": {
"@antfu/eslint-config": "^5.2.1",
"@hugo-fixit/fixit-releaser": "^1.6.0",
"@types/node": "^24.3.0",
"eslint": "^9.34.0",
"lint-staged": "^16.1.5",
"serve": "^14.2.4",
"simple-git-hooks": "^2.13.1",
"tsx": "^4.20.5",
"typescript": "^5.9.2"
},
"pnpm": {
"overrides": {
"on-headers": ">=1.1.0"
}
},
"simple-git-hooks": {
"pre-commit": "pnpm -F versioning start dev && pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"name": "@hugo-fixit/integration",
"version": "0.1.0",
"private": true,
"description": "Integration utilities for the FixIt theme",
"author": "Lruihao",
"scripts": {
"start": "tsx src/index.ts"
},
"devDependencies": {
"@hugo-fixit/shared": "workspace:*",
"@types/fs-extra": "^11.0.4",
"fs-extra": "^11.3.1"
}
}
+9
View File
@@ -0,0 +1,9 @@
import path from 'node:path'
import { workspaceRoot } from '@hugo-fixit/shared'
import fsExtra from 'fs-extra'
const { copySync, removeSync } = fsExtra
removeSync(path.join(workspaceRoot, 'public'))
copySync(path.join(workspaceRoot, 'apps/demo/public'), path.join(workspaceRoot, 'public'), { overwrite: true })
copySync(path.join(workspaceRoot, 'apps/test/public'), path.join(workspaceRoot, 'public/test'), { overwrite: true })
+20
View File
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"jsx": "preserve",
"lib": ["DOM", "ESNext"],
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["node"],
"strict": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
+8
View File
@@ -0,0 +1,8 @@
{
"name": "@hugo-fixit/shared",
"version": "0.1.0",
"private": true,
"description": "Internal utilities shared across @hugo-fixit packages",
"author": "Lruihao",
"main": "src/index.ts"
}
+3
View File
@@ -0,0 +1,3 @@
import path from 'node:path'
export const workspaceRoot = path.resolve(__dirname, '../../../')
+20
View File
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"jsx": "preserve",
"lib": ["DOM", "ESNext"],
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["node"],
"strict": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
+13
View File
@@ -0,0 +1,13 @@
{
"name": "@hugo-fixit/versioning",
"private": true,
"description": "Versioning utilities for the FixIt theme",
"author": "Lruihao",
"main": "src/index.ts",
"scripts": {
"start": "tsx src/index.ts"
},
"devDependencies": {
"@hugo-fixit/shared": "workspace:*"
}
}
+10
View File
@@ -0,0 +1,10 @@
import process from 'node:process'
import { updateVersion } from './update-version'
const type: string = process.argv[2]
if (type !== 'dev' && type !== 'prod') {
console.error('Invalid argument. Please specify "dev" or "prod".')
process.exit(1)
}
updateVersion(type)
+78
View File
@@ -0,0 +1,78 @@
/* eslint-disable no-console */
import { execSync, execFileSync } from 'node:child_process'
import fs from 'node:fs'
import { join } from 'node:path'
import process from 'node:process'
import { workspaceRoot } from '@hugo-fixit/shared'
/**
* Update the version of the FixIt
* @param type version type
*/
export function updateVersion(type: 'dev' | 'prod') {
const branch: string = execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
const match: string[] = [
'archetypes/',
'assets/',
'i18n/',
'layouts/',
'static/',
'go.mod',
'hugo.toml',
'package.json',
'package-lock.json',
'pnpm-lock.yaml',
'theme.toml',
]
const gitDiff: string = execSync('git diff --cached --name-only').toString().trim()
if (type !== 'prod') {
// Avoid conflicts when creating a Pull Request
if (!['dev', 'main'].includes(branch)) {
console.log(`The current branch is ${branch}, no need to update the FixIt version.`)
process.exit(0)
}
if (!match.some(item => gitDiff.includes(item))) {
console.log('No need to update the FixIt version.')
process.exit(0)
}
}
const initHtmlPath: string = join(workspaceRoot, 'layouts/_partials/init/index.html')
const packageJsonPath: string = join(workspaceRoot, 'package.json')
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
const version: string = packageJson.version
// Get the short hash of the last commit (can not get this commit hash at pre-commit hook)
const shortHash: string = execSync('git rev-parse --short HEAD').toString().trim()
// Build the development version v{major}.{minor}.{patch+1}-{timestamp}-{shortHash}
// e.g. v0.3.21-20250702061540-abcdefg
const timestamp: string = new Date().toISOString().replace(/[-:TZ]/g, '').slice(0, -4)
const devVersion: string = `${version.replace(/(\d+)$/, (match, part) => (Number.parseInt(part) + 1).toString())}-${timestamp}-${shortHash}`
const initHtml: string = fs.readFileSync(initHtmlPath, 'utf8')
const latestVersion: string = type === 'prod' ? version : devVersion
const versionRegex: RegExp = /v\d+\.\d+\.\d+(-[\w.\-]+)?/
const lastVersion: string = initHtml.match(versionRegex)![0].slice(1)
const newInitHtml: string = initHtml.replace(versionRegex, `v${latestVersion}`)
if (lastVersion === version && gitDiff.includes('layouts/_partials/init/index.html')) {
// After running `npm version` or manually modifying the version number, skip the update
console.log(`The FixIt version has been updated to v${lastVersion}.`)
process.exit(0)
}
// Update the version number in layouts/_partials/init/index.html
fs.writeFileSync(initHtmlPath, newInitHtml)
// Add the updated files to the git stage
const toStageFiles: string[] = [
'layouts/_partials/init/index.html',
'package.json',
'package-lock.json',
'pnpm-lock.yaml',
]
toStageFiles.forEach((file) => {
const stageFile = join(workspaceRoot, file)
if (fs.existsSync(stageFile)) {
execFileSync('git', ['add', stageFile])
}
})
console.log(`Update the FixIt version from v${lastVersion} to v${latestVersion}.`)
}
+20
View File
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ESNext",
"jsx": "preserve",
"lib": ["DOM", "ESNext"],
"baseUrl": ".",
"module": "ESNext",
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["node"],
"strict": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
+3243 -105
View File
File diff suppressed because it is too large Load Diff
+3
View File
@@ -0,0 +1,3 @@
packages:
- apps/*
- packages/*