-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
832 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { readFileSync } from 'fs'; | ||
import { dirname } from 'path'; | ||
import handlebars from 'handlebars'; | ||
import { createFileSync, createFolder, isFileOrFolderExists } from '@compass-aiden/helpers/cjs'; | ||
|
||
/** | ||
* @description 使用handlebars批量编译模板 | ||
* @param temps 模板的源路径与目标路径 | ||
* @param tempData 模板的上下文数据 | ||
*/ | ||
export default async function batchCompileTemplates(temps: [string, string][], tempData: Record<string, any>) { | ||
const tasks = temps.map(async (temp) => { | ||
if (temp && temp[0] && temp[1]) { | ||
const compileTemp = handlebars.compile(readFileSync(temp[0], 'utf-8')); | ||
const targetDirPath = dirname(temp[1]); | ||
if (!isFileOrFolderExists(targetDirPath)) { | ||
await createFolder(targetDirPath); | ||
} | ||
createFileSync(temp[1], compileTemp(tempData)); | ||
} | ||
}); | ||
await Promise.all(tasks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
parserOptions: { | ||
project: ['./tsconfig.*.json'], | ||
}, | ||
ignorePatterns: ['.eslintrc.cjs', 'dist', 'types'], | ||
extends: [ | ||
// typescript使用此配置 | ||
'@compass-aiden/eslint-config/ts', | ||
{{#if enabledPrettier}} | ||
'plugin:prettier/recommended', | ||
{{/if}} | ||
], | ||
}; |
59 changes: 59 additions & 0 deletions
59
templates/utils/.github/workflows/lint-and-test.yml.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Lint and test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '**' | ||
|
||
jobs: | ||
lint: | ||
name: Lint and test code | ||
runs-on: ubuntu-latest | ||
steps: | ||
# 签出分支 | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 2 | ||
|
||
# 设置node环境 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
# 设置pnpm | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8.7.1 | ||
|
||
# 设置 pnpm 缓存文件 | ||
- name: Cache pnpm | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
key: pnpm-cache-$\{{ runner.os }}-$\{{ hashFiles('pnpm-lock.yaml') }} | ||
|
||
# 恢复项目依赖 | ||
- name: Install | ||
env: | ||
# HUSKY: 0 | ||
SKIP_INSTALL_SIMPLE_GIT_HOOKS: 1 | ||
SKIP_SIMPLE_GIT_HOOKS: 1 | ||
run: | | ||
pnpm install | ||
|
||
{{#if enabledEslint}} | ||
# 检查项目 | ||
- name: Run lint | ||
run: | | ||
pnpm lint | ||
{{/if}} | ||
|
||
{{#if enabledJest}} | ||
# 测试项目 | ||
- name: Run test | ||
run: | | ||
pnpm test | ||
{{/if}} |
110 changes: 110 additions & 0 deletions
110
templates/utils/.github/workflows/publish-and-deploy.yml.handlebars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
name: Publish and deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
permissions: | ||
contents: write | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: 'deploy' | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
lint: | ||
name: Publish and deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
# 签出分支 | ||
- uses: actions/checkout@v4 | ||
|
||
# 设置 git | ||
- name: Setup git | ||
run: | | ||
git config --local user.email github_bot@users.noreply.github.com | ||
git config --local user.name github_bot | ||
|
||
# 设置node环境 | ||
- name: Setup node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
# 设置pnpm | ||
- uses: pnpm/action-setup@v2 | ||
with: | ||
version: 8.7.1 | ||
|
||
# 设置 pnpm 缓存文件 | ||
- name: Cache pnpm | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
node_modules | ||
key: pnpm-cache-$\{{ runner.os }}-$\{{ hashFiles('pnpm-lock.yaml') }} | ||
|
||
# 恢复项目依赖 | ||
- name: Install | ||
env: | ||
# HUSKY: 0 | ||
SKIP_INSTALL_SIMPLE_GIT_HOOKS: 1 | ||
SKIP_SIMPLE_GIT_HOOKS: 1 | ||
run: | | ||
pnpm install --frozen-lockfile | ||
|
||
# 同步版本及推送标签 | ||
- name: Bump version and push tag | ||
id: tag_version | ||
uses: mathieudutour/github-tag-action@v6.2 | ||
with: | ||
github_token: $\{{ secrets.GITHUB_TOKEN }} | ||
|
||
# 更新npm版本 | ||
- name: Updated version | ||
run: | | ||
npm pkg set version=$\{{ steps.tag_version.outputs.new_version }} | ||
git add -A | ||
git commit -m "chore: published tag $\{{ steps.tag_version.outputs.new_tag }}" | ||
|
||
# 构建项目 | ||
- name: Run build | ||
env: | ||
NODE_ENV: production | ||
run: | | ||
pnpm build | ||
{{#if enabledTypedoc}} | ||
pnpm build:doc | ||
{{/if}} | ||
|
||
# 创建Github release | ||
- name: Create a GitHub release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: $\{{ steps.tag_version.outputs.new_tag }} | ||
name: Release $\{{ steps.tag_version.outputs.new_tag }} | ||
body: $\{{ steps.tag_version.outputs.changelog }} | ||
|
||
# 发布npm包 | ||
- name: Publish | ||
uses: JS-DevTools/npm-publish@v3 | ||
with: | ||
token: $\{{ secrets.NPM_AUTH_TOKEN }} | ||
|
||
# 推送变更至仓库 | ||
- name: Push changes | ||
uses: ad-m/github-push-action@master | ||
with: | ||
github_token: $\{{ secrets.GITHUB_TOKEN }} | ||
branch: $\{{ github.ref }} | ||
|
||
{{#if enabledTypedoc}} | ||
# 部署文档 | ||
- name: Deploy GitHub Pages site | ||
uses: JamesIves/github-pages-deploy-action@v4 | ||
with: | ||
folder: ./docs | ||
{{/if}} |
Oops, something went wrong.