From e81070597b1a19cbf27da293e427630bd539a80a Mon Sep 17 00:00:00 2001 From: Timi Date: Mon, 23 Nov 2026 20:28:05 +0800 Subject: [PATCH] feat!: publish per-component ESM entries as @timi/tdesign-pc --- .gitea/workflows/release.yml | 132 ++++++++++++++++++ README.md | 8 +- package.json | 50 +++++-- src/components/admin-layout/index.ts | 2 +- src/components/article-editor/content.ts | 2 +- src/components/article-editor/index.ts | 2 +- src/components/article-editor/index.vue | 4 +- src/components/article-editor/types.ts | 2 +- src/components/article-view/index.ts | 2 +- src/components/article-view/index.vue | 4 +- src/components/authorize-form/index.ts | 2 +- src/components/authorize-form/login.vue | 2 +- src/components/authorize-form/register.vue | 2 +- src/components/code-editor/index.ts | 2 +- src/components/code-editor/index.vue | 4 +- src/components/notify-editor/index.ts | 2 +- src/components/notify-view/index.ts | 2 +- src/components/root-layout/index.ts | 2 +- src/components/root-layout/index.vue | 2 +- .../tiptap-editor/TiptapCodeBlockButton.vue | 2 +- .../tiptap-editor/TiptapIframeButton.vue | 2 +- .../tiptap-editor/TiptapLinkButton.vue | 2 +- .../tiptap-editor/TiptapMediaButton.vue | 2 +- .../tiptap-editor/TiptapPaddingButton.vue | 2 +- .../tiptap-editor/TiptapTableButton.vue | 4 +- .../tiptap-editor/TiptapToolbar.vue | 4 +- src/components/tiptap-editor/index.ts | 6 +- src/components/tiptap-editor/index.vue | 10 +- src/components/tiptap-view/index.ts | 2 +- src/components/tiptap-view/index.vue | 2 +- src/components/user-level/index.ts | 2 +- src/components/user-profile/index.ts | 2 +- src/components/user-profile/index.vue | 2 +- src/components/user-profile/popup/index.ts | 2 +- src/index.ts | 2 - src/store/popupUser.ts | 2 +- tsconfig.json | 7 +- tsconfig.node.json | 2 +- vite.config.ts | 71 +++++++--- 39 files changed, 267 insertions(+), 91 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..3f022d2 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,132 @@ +name: Release + +# 发版规则:dev 合并到 master,且合并请求标题为 vX.X.X +# 标题不是 vX.X.X 时只做构建验证,不发布 +# 也支持手动触发,按 package.json 版本发布,用于失败后重发 +on: + pull_request: + branches: + - master + types: + - closed + workflow_dispatch: + +jobs: + release: + runs-on: act_runner_node + if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Resolve release version + id: version + run: | + pkg_version=$(node -p "require('./package.json').version") + echo "package.json 版本:$pkg_version" + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "手动触发,按 package.json 版本发布" + echo "version=$pkg_version" >> $GITHUB_OUTPUT + echo "publish=true" >> $GITHUB_OUTPUT + exit 0 + fi + title="${{ github.event.pull_request.title }}" + echo "PR 标题:$title" + if echo "$title" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then + if [ "v$pkg_version" != "$title" ]; then + echo "FAIL: 标题 $title 与 package.json 版本 $pkg_version 不一致" + exit 1 + fi + echo "version=$pkg_version" >> $GITHUB_OUTPUT + echo "publish=true" >> $GITHUB_OUTPUT + else + echo "标题不是 vX.X.X,仅做构建验证,不发布" + echo "publish=false" >> $GITHUB_OUTPUT + fi + + - name: Configure nexus auth + env: + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + run: | + if [ -z "$NEXUS_USERNAME" ] || [ -z "$NEXUS_PASSWORD" ]; then + echo "FAIL: 缺少 secrets.NEXUS_USERNAME 或 secrets.NEXUS_PASSWORD" + exit 1 + fi + auth=$(printf '%s:%s' "$NEXUS_USERNAME" "$NEXUS_PASSWORD" | base64 | tr -d '\n') + { + echo "registry=https://nexus.imyeyu.com/repository/npm-group/" + echo "//nexus.imyeyu.com/repository/npm-group/:_auth=${auth}" + echo "//nexus.imyeyu.com/repository/npm-group/:always-auth=true" + echo "//nexus.imyeyu.com/repository/npm-timi/:_auth=${auth}" + echo "//nexus.imyeyu.com/repository/npm-timi/:always-auth=true" + } > ~/.npmrc + echo "OK: nexus 认证已配置" + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Type check and build + run: pnpm run build + + - name: Ensure version not published + if: ${{ steps.version.outputs.publish == 'true' }} + run: | + if npm view "@timi/tdesign-pc@${{ steps.version.outputs.version }}" version > /dev/null 2>&1; then + echo "FAIL: @timi/tdesign-pc@${{ steps.version.outputs.version }} 已存在于 nexus,请提升 package.json 版本" + exit 1 + fi + echo "OK: 版本未占用" + + - name: Publish to nexus + if: ${{ steps.version.outputs.publish == 'true' }} + run: npm publish --registry=https://nexus.imyeyu.com/repository/npm-timi/ + + - name: Create release + if: ${{ steps.version.outputs.publish == 'true' }} + env: + GITEA_TOKEN: ${{ secrets.RUNNER_TOKEN }} + GITEA_SERVER_URL: ${{ github.server_url }} + GITEA_INTERNAL_URL: ${{ vars.TIMI_GITEA_INTERNAL_URL }} + GITEA_REPOSITORY: ${{ github.repository }} + RELEASE_TAG: v${{ steps.version.outputs.version }} + RELEASE_TARGET: ${{ github.sha }} + run: | + if [ -z "$GITEA_TOKEN" ]; then + echo "Missing secrets.RUNNER_TOKEN" + exit 1 + fi + + if [ -n "$GITEA_INTERNAL_URL" ]; then + api_base_url="$GITEA_INTERNAL_URL" + else + api_base_url="$GITEA_SERVER_URL" + fi + + api_url="$api_base_url/api/v1/repos/$GITEA_REPOSITORY/releases" + payload=$(cat </dev/null || true + echo "FAIL: 创建 release 失败" + exit 1 + fi diff --git a/README.md b/README.md index cb42981..e4d1632 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# timi-tdesign-pc +# @timi/tdesign-pc -Vue 3 PC 端通用组件库,依赖 `timi-web` 提供基础组件和编辑器能力。 +Vue 3 PC 端通用组件库,依赖 `@timi/web` 提供基础组件和编辑器能力。 -本包不依赖 `timi-web-api`。业务项目可以只安装本包使用通用组件;需要业务接口、领域类型或用户状态时,再单独安装 `timi-web-api`。 +本包不绑定业务 API 包。业务项目可以只安装本包使用通用组件;业务接口、领域类型和用户状态由应用层自行提供。 ## 文章和通知组件 -`ArticleEditor`、`ArticleView`、`NotifyEditor`、`NotifyView` 只约束对象的最小字段。`Article`、`Attachment` 和 `NotifyDetail` 支持携带业务自定义字段,不要求对象来自 `timi-web-api`。 +`ArticleEditor`、`ArticleView`、`NotifyEditor`、`NotifyView` 只约束对象的最小字段。`Article`、`Attachment` 和 `NotifyDetail` 支持携带业务自定义字段,不要求对象来自特定 API 包。 上传和附件地址由业务项目通过回调注入: diff --git a/package.json b/package.json index 65fef92..03d68a2 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,21 @@ { - "name": "timi-tdesign-pc", - "main": "./dist/timi-tdesign-pc.umd.js", - "types": "./dist/timi-tdesign-pc/src/index.d.ts", - "module": "./dist/timi-tdesign-pc.mjs", + "name": "@timi/tdesign-pc", + "type": "module", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "module": "./dist/index.js", "style": "./dist/timi-tdesign-pc.css", + "sideEffects": [ + "**/*.css" + ], "private": false, - "version": "0.0.1", + "version": "0.1.0", "license": "MIT", "scripts": { "dev": "pnpm run -C docs dev", "build": "vue-tsc --noEmit && vite build", "build:doc": "pnpm run -C docs build", - "preview:doc": "pnpm run -C docs preview", - "pub": "pnpm run build && npm publish --registry=https://nexus.imyeyu.com/repository/npm-timi/" + "preview:doc": "pnpm run -C docs preview" }, "publishConfig": { "registry": "https://nexus.imyeyu.com/repository/npm-timi/" @@ -25,19 +28,37 @@ ], "exports": { ".": { - "types": "./dist/timi-tdesign-pc/src/index.d.ts", - "import": "./dist/timi-tdesign-pc.mjs", - "require": "./dist/timi-tdesign-pc.umd.js" + "types": "./dist/index.d.ts", + "import": "./dist/index.js" }, - "./style.css": "./dist/timi-tdesign-pc.css" + "./components": { + "types": "./dist/components/index.d.ts", + "import": "./dist/components/index.js" + }, + "./components/user-profile/popup": { + "types": "./dist/components/user-profile/popup/index.d.ts", + "import": "./dist/components/user-profile/popup/index.js" + }, + "./components/*": { + "types": "./dist/components/*/index.d.ts", + "import": "./dist/components/*/index.js" + }, + "./store/popupUser": { + "types": "./dist/store/popupUser.d.ts", + "import": "./dist/store/popupUser.js" + }, + "./style.css": "./dist/timi-tdesign-pc.css", + "./src/*": "./src/*" }, "engines": { "node": ">=16.0.0" }, "dependencies": { "tdesign-vue-next": "^1.18.6", - "timi-web": "link:E:/WebProject/timi-web", - "vue": "^3.5.26" + "@timi/web": "^2.0.0" + }, + "peerDependencies": { + "vue": "^3.5.0" }, "devDependencies": { "@types/node": "^25.0.8", @@ -63,6 +84,7 @@ "vite-plugin-vue-setup-extend": "^0.4.0", "@vue/tsconfig": "^0.8.1", "vite": "7.3.1", - "vue-tsc": "^3.2.2" + "vue-tsc": "^3.2.2", + "vue": "^3.5.26" } } diff --git a/src/components/admin-layout/index.ts b/src/components/admin-layout/index.ts index 77c302b..1725a09 100644 --- a/src/components/admin-layout/index.ts +++ b/src/components/admin-layout/index.ts @@ -1,5 +1,5 @@ import view from "./index.vue"; -import { WebToolkit } from "timi-web"; +import { WebToolkit } from "@timi/web/utils"; export const AdminLayout = WebToolkit.withInstall(view); export default AdminLayout; diff --git a/src/components/article-editor/content.ts b/src/components/article-editor/content.ts index 933b0ab..c2cd062 100644 --- a/src/components/article-editor/content.ts +++ b/src/components/article-editor/content.ts @@ -3,7 +3,7 @@ import { TEMP_FILE_ID_ATTR, isLocalMediaId, normalizeContent -} from "timi-web/editor"; +} from "@timi/web/editor"; import type { ArticleContentType, Attachment } from "./types"; /** 文章内容中附件和临时文件的标识前缀。 */ diff --git a/src/components/article-editor/index.ts b/src/components/article-editor/index.ts index 49fee24..b2d3230 100644 --- a/src/components/article-editor/index.ts +++ b/src/components/article-editor/index.ts @@ -1,5 +1,5 @@ import view from "./index.vue"; -import { WebToolkit } from "timi-web"; +import { WebToolkit } from "@timi/web/utils"; import type { Article } from "./types"; export type { diff --git a/src/components/article-editor/index.vue b/src/components/article-editor/index.vue index 3369496..40327a2 100644 --- a/src/components/article-editor/index.vue +++ b/src/components/article-editor/index.vue @@ -25,7 +25,7 @@