Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
frank committed Dec 24, 2024
0 parents commit 6221c06
Show file tree
Hide file tree
Showing 47 changed files with 7,461 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
39 changes: 39 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy to GitHub Pages

on:
workflow_dispatch: # 允许手动触发
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20 # Node.js 版本
cache: 'pnpm' # 缓存 pnpm

- name: Install dependencies
run: pnpm install

- name: Build Project
run: pnpm run build

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist # 构建输出目录
130 changes: 130 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Create Release Tag

on:
push:
tags:
- "**/v*"
- "v*"
workflow_dispatch: # 允许手动触发

jobs:
build:
name: 创建发布
runs-on: ubuntu-latest

steps:
- name: 检出代码
uses: actions/checkout@v4

- name: 获取当前和上一个标签
id: get_tags
run: |
git fetch --prune --unshallow
# tags=($(git tag -l --sort=-version:refname))
# 获取所有标签并按标签创建时间降序排序
tags=($(git tag -l --sort=-creatordate))
current_tag=${tags[0]}
previous_tag=${tags[1]}
echo "::set-output name=current_tag::$current_tag"
echo "::set-output name=previous_tag::$previous_tag"
- name: 提取并分类提交消息
id: extract_commit_messages
run: |
set -e
current_tag="${{ steps.get_tags.outputs.current_tag }}"
previous_tag="${{ steps.get_tags.outputs.previous_tag }}"
# 提取标签前缀
current_prefix=$(echo "$current_tag" | sed 's/\(.*\)\/.*/\1/')
previous_prefix=$(echo "$previous_tag" | sed 's/\(.*\)\/.*/\1/')
# 检查标签前缀是否相同
if [ "$current_prefix" != "$previous_prefix" ]; then
echo "Tags have different prefixes, using initial commit."
previous_tag=$(git rev-list --max-parents=0 HEAD)
fi
if [ -z "$previous_tag" ]; then
echo "No previous tag found, using initial commit."
previous_tag=$(git rev-list --max-parents=0 HEAD)
fi
messages=$(git log --pretty=format:"%s %h" "$previous_tag".."$current_tag")
commit_messages=$(echo "$messages" | grep -E 'feat|fix|docs|perf' || true)
feat_messages=$(echo "$commit_messages" | grep 'feat' || true)
fix_messages=$(echo "$commit_messages" | grep 'fix' || true)
docs_messages=$(echo "$commit_messages" | grep 'docs' || true)
perf_messages=$(echo "$commit_messages" | grep 'perf' || true)
feat_messages=("${feat_messages[@]//\`/\\\`}")
fix_messages=("${fix_messages[@]//\`/\\\`}")
docs_messages=("${docs_messages[@]//\`/\\\`}")
perf_messages=("${perf_messages[@]//\`/\\\`}")
echo "::set-output name=feat_messages::${feat_messages[@]}"
echo "::set-output name=fix_messages::${fix_messages[@]}"
echo "::set-output name=docs_messages::${docs_messages[@]}"
echo "::set-output name=perf_messages::${perf_messages[@]}"
- name: 获取当前分支名
id: get_branch_name
run: |
branch_name=$(git rev-parse --abbrev-ref HEAD)
echo "::set-output name=branch_name::$branch_name"
- name: 发布说明
id: generate_release_notes
run: |
# 提取提交消息分类
feat_messages=("${{ steps.extract_commit_messages.outputs.feat_messages }}")
fix_messages=("${{ steps.extract_commit_messages.outputs.fix_messages }}")
docs_messages=("${{ steps.extract_commit_messages.outputs.docs_messages }}")
perf_messages=("${{ steps.extract_commit_messages.outputs.perf_messages }}")
# 生成发布说明的Markdown字符串
release_notes="> 请查看 [更新日志](./CHANGELOG.md) 获取所有变更详情。 \n## 更新内容: \n"
if [[ -n "$feat_messages" ]]; then
release_notes="$release_notes\n### ✨ Features | 新功能: \n"
for message in "${feat_messages[@]}"; do
release_notes="$release_notes\n- $message"
done
fi
if [[ -n "$fix_messages" ]]; then
release_notes="$release_notes\n### 🐛 Bug Fixes | Bug 修复: \n"
for message in "${fix_messages[@]}"; do
release_notes="$release_notes\n- $message"
done
fi
if [[ -n "$docs_messages" ]]; then
release_notes="$release_notes\n### ✏️ Documentation | 文档: \n"
for message in "${docs_messages[@]}"; do
release_notes="$release_notes\n- $message"
done
fi
if [[ -n "$perf_messages" ]]; then
release_notes="$release_notes\n### ⚡ Performance Improvements | 性能优化: \n"
for message in "${perf_messages[@]}"; do
release_notes="$release_notes\n- $message"
done
fi
release_notes=("${release_notes[@]//\`/\\\`}")
echo "::set-output name=release_notes::${release_notes[@]}"
- name: 写入生成的发布说明到 changelog.md
run: |
echo -e "${{ steps.generate_release_notes.outputs.release_notes }}" > changelog.md
cat changelog.md
- name: 创建标签的发布
id: release_tag
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.get_tags.outputs.current_tag }}
generateReleaseNotes: "false" # 禁用自动生成发布说明
bodyFile: changelog.md
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
!.vscode/settings.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict = true # 严格要求 package.json 中的 engines 字段规定的版本范围
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["Vue.volar"]
}
15 changes: 15 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"editor.fontFamily": "Monaco, 'Apple Color Emoji', 'Courier New', monospace",
"terminal.integrated.fontFamily": "Monaco, 'Apple Color Emoji', 'Courier New', monospace",
// "editor.fontFamily": "'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback', 'Noto Color Emoji'",
// "terminal.integrated.fontFamily": "'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback', 'Noto Color Emoji'",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"vite.config.*": "pages.config.*, manifest.config.*, uno.config.*, volar.config.*, *.env, .env.*",
"env.d.*": "shims.d.*, uni-pages.d.*, components.d.*, auto-imports.d*, manifest.json, pages.json, theme.json",
"package.json": "pnpm-*.yaml, .gitignore, .gitattributes, .npmrc, .nvmrc",
"biome.json": "biome.json, commitlint.config.ts, lefthook.yml"
},
"typescript.tsdk": "node_modules\\typescript\\lib",
"vue.server.hybridMode": "typeScriptPluginOnly",
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Vue 3 + TypeScript + Vite

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
38 changes: 38 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"formatWithErrors": true,
"ignore": [],
"attributePosition": "auto",
"indentStyle": "space",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"useImportType": "warn",
"noParameterAssign": "off"
},
"suspicious": {
"noExplicitAny": "off"
},
"complexity": {
"noStaticOnlyClass": "warn",
"noBannedTypes": "off",
"noThisInStatic": "off"
}
}
},
"files": {
"include": ["packages/**/*.ts", "src/**/*.ts"],
"ignore": ["**/node_modules/**", "**/dist/**"]
}
}
42 changes: 42 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { PromptConfig, UserConfig } from "@commitlint/types";
import _enum_types_ from "./scripts/githooks/_enum_types_.json";

// 提取 PromptConfig 中 questions 的类型
type QuestionsType = NonNullable<PromptConfig["questions"]>;

// 提取单个 question 中的 enum 类型
type SingleQuestionType = NonNullable<QuestionsType[keyof QuestionsType]>;

// 提取 enum 的类型
type EnumType = NonNullable<SingleQuestionType["enum"]>;

const enumTypes: EnumType = _enum_types_;
const newEnumTypes = Object.fromEntries(
Object.entries(enumTypes).map(([key, value]) => [
key,
{
description: `${value.emoji} ${value.description}`,
emoji: value.emoji,
value: key,
},
]),
);

const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
rules: {
// 规则的严重性级别。2 表示错误,1 表示警告,0 表示关闭此规则。
"type-enum": [2, "always", Object.keys(newEnumTypes)],
},
prompt: {
questions: {
type: {
// description: "Select the type of change that you're committing:",
description: "请选择提交的类型",
enum: newEnumTypes,
},
},
},
};

export default Configuration;
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
56 changes: 56 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
#
# pre-push:
# commands:
# packages-audit:
# tags: frontend security
# run: yarn audit
# gems-audit:
# tags: backend security
# run: bundle audit
#
# pre-commit:
# parallel: true
# commands:
# eslint:
# glob: "*.{js,ts,jsx,tsx}"
# run: yarn eslint {staged_files}
# rubocop:
# tags: backend style
# glob: "*.rb"
# exclude: '(^|/)(application|routes)\.rb$'
# run: bundle exec rubocop --force-exclusion {all_files}
# govet:
# tags: backend style
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
# scripts:
# "hello.js":
# runner: node
# "any.go":
# runner: go run

# https://biomejs.dev/zh-cn/recipes/git-hooks/#lefthook
pre-commit:
commands:
check:
run: npx @biomejs/biome check --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
# glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}" # biomejs 已经处理过了,这里不需要指定
# run: npx @biomejs/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
# stage_fixed: true # 参数用于将更新的文件再次暂存。

# 推送前进行格式化和 lint
pre-push:
commands:
check:
run: npx @biomejs/biome check --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {push_files}

# 提交信息检查
commit-msg:
commands:
check:
run: npx --no-install commitlint --edit {0} && node ./scripts/githooks/commit-hook.mjs {0}
Loading

0 comments on commit 6221c06

Please sign in to comment.