feat!: publish per-component ESM entries as @timi/tdesign-pc

This commit is contained in:
Timi
2026-11-23 20:28:05 +08:00
parent 1909587a0b
commit e81070597b
39 changed files with 267 additions and 91 deletions
+132
View File
@@ -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 <<EOF
{
"tag_name": "$RELEASE_TAG",
"name": "$RELEASE_TAG",
"target_commitish": "$RELEASE_TARGET",
"draft": false,
"prerelease": false
}
EOF
)
echo "Creating release $RELEASE_TAG at $RELEASE_TARGET"
http_code=$(curl -sS -w "%{http_code}" -o /tmp/release.json -X POST "$api_url" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
--connect-timeout 30 --max-time 60 -d "$payload") || http_code="000"
echo "HTTP Status: $http_code"
if [ "$http_code" = "201" ]; then
echo "OK: Release created"
elif [ "$http_code" = "409" ]; then
echo "OK: Release already exists"
else
cat /tmp/release.json 2>/dev/null || true
echo "FAIL: 创建 release 失败"
exit 1
fi
+4 -4
View File
@@ -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 包。
上传和附件地址由业务项目通过回调注入:
+36 -14
View File
@@ -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"
}
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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";
/** 文章内容中附件和临时文件的标识前缀。 */
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -25,7 +25,7 @@
<script lang="ts" setup>
import type { Article, ArticleContentType, Attachment, UploadResult } from "./types";
import { MarkdownEditor } from "timi-web";
import { MarkdownEditor } from "@timi/web/components/markdown-editor";
import { TiptapEditor } from "../tiptap-editor";
import type { TiptapEditorExpose } from "../tiptap-editor";
import {
@@ -41,7 +41,7 @@ import {
ATTACHMENT_ID_ATTR,
TEMP_FILE_ID_ATTR,
normalizeContent
} from "timi-web/editor";
} from "@timi/web/editor";
defineOptions({
name: "ArticleEditor"
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UploadResult as EditorUploadResult } from "timi-web/editor";
import type { UploadResult as EditorUploadResult } from "@timi/web/editor";
/** 文章编辑器支持的正文类型。 */
export type ArticleContentType = "TEXT" | "MARKDOWN" | "TIP_TAP" | "TIPTAP";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const ArticleView = WebToolkit.withInstall(view);
export default ArticleView;
+2 -2
View File
@@ -14,14 +14,14 @@
<script lang="ts" setup>
import type { Article, Attachment } from "../article-editor/types";
import { MarkdownView } from "timi-web";
import { MarkdownView } from "@timi/web/components/markdown-view";
import { TiptapView } from "../tiptap-view";
import {
getAttachmentIdFromSrc,
normalizeArticleContentType,
normalizeRawArticleContent
} from "../article-editor/content";
import { ATTACHMENT_ID_ATTR, normalizeContent } from "timi-web/editor";
import { ATTACHMENT_ID_ATTR, normalizeContent } from "@timi/web/editor";
defineOptions({
name: "ArticleView"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const AuthorizeForm = WebToolkit.withInstall(view);
export default AuthorizeForm;
+1 -1
View File
@@ -24,7 +24,7 @@
</template>
<script lang="ts" setup>
import { Captcha } from "timi-web";
import { Captcha } from "@timi/web/components/captcha";
import { Emits, useHandler } from "~/components/authorize-form/emits";
import type {
CaptchaData,
+1 -1
View File
@@ -30,7 +30,7 @@
</template>
<script lang="ts" setup>
import { Captcha } from "timi-web";
import { Captcha } from "@timi/web/components/captcha";
import { FormRules, MessagePlugin, SubmitContext } from "tdesign-vue-next";
import { Emits, useHandler } from "~/components/authorize-form/emits";
import type {
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import "./style.less";
export type CodeEditorScrollState = {
+2 -2
View File
@@ -65,8 +65,8 @@ import {
replaceMatchText,
type TextSearchMatch,
type TextSearchOptions
} from "timi-web/editor";
import { highlightCode, resolveCodeEditorKeydown, resolvePrismLanguage } from "timi-web/editor";
} from "@timi/web/editor";
import { highlightCode, resolveCodeEditorKeydown, resolvePrismLanguage } from "@timi/web/editor";
defineOptions({
name: "CodeEditor"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import type { NotifyDetail } from "./types";
export type { NotifyContentType, NotifyDetail } from "./types";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const NotifyView = WebToolkit.withInstall(view);
export default NotifyView;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const RootLayout = WebToolkit.withInstall(view);
export default RootLayout;
+1 -1
View File
@@ -6,7 +6,7 @@
</template>
<script lang="ts" setup>
import { Copyright } from "timi-web";
import { Copyright } from "@timi/web/components/copyright";
defineOptions({
name: "RootLayout"
@@ -19,7 +19,7 @@
</template>
<script lang="ts" setup>
import type { TiptapEditorInstance } from "timi-web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
defineOptions({
name: "TiptapCodeBlockButton"
@@ -34,7 +34,7 @@
<script lang="ts" setup>
import { showPlatformMessage } from "../message";
import type { TiptapEditorInstance } from "timi-web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
defineOptions({
name: "TiptapIframeButton"
@@ -23,7 +23,7 @@
</template>
<script lang="ts" setup>
import type { TiptapEditorInstance } from "timi-web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
defineOptions({
name: "TiptapLinkButton"
@@ -41,7 +41,7 @@
<script lang="ts" setup>
import { showPlatformMessage } from "../message";
import type { TiptapEditorInstance, UploadResult } from "timi-web/editor";
import type { TiptapEditorInstance, UploadResult } from "@timi/web/editor";
defineOptions({
name: "TiptapMediaButton"
@@ -35,7 +35,7 @@
</template>
<script lang="ts" setup>
import { formatPaddingValue, normalizeSliderValue } from "timi-web/editor";
import { formatPaddingValue, normalizeSliderValue } from "@timi/web/editor";
defineOptions({
name: "TiptapPaddingButton"
@@ -31,8 +31,8 @@
</template>
<script lang="ts" setup>
import { TABLE_PICKER_SIZE } from "timi-web/editor";
import type { TiptapEditorInstance } from "timi-web/editor";
import { TABLE_PICKER_SIZE } from "@timi/web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
defineOptions({
name: "TiptapTableButton"
@@ -100,8 +100,8 @@
</template>
<script lang="ts" setup>
import type { AlignType, UploadResult, TiptapEditorInstance } from "timi-web/editor";
import { buildHeadingOptions } from "timi-web/editor";
import type { AlignType, UploadResult, TiptapEditorInstance } from "@timi/web/editor";
import { buildHeadingOptions } from "@timi/web/editor";
import TiptapCodeBlockButton from "./TiptapCodeBlockButton.vue";
import TiptapIframeButton from "./TiptapIframeButton.vue";
import TiptapLinkButton from "./TiptapLinkButton.vue";
+3 -3
View File
@@ -1,8 +1,8 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import type { TiptapEditorInstance } from "timi-web/editor";
import { WebToolkit } from "@timi/web/utils";
import type { TiptapEditorInstance } from "@timi/web/editor";
export * from "timi-web/editor";
export * from "@timi/web/editor";
export type TiptapEditorExpose = {
submit: () => Promise<string>;
getPendingMediaCount: () => number;
+5 -5
View File
@@ -64,18 +64,18 @@ import {
buildSearchRegex,
replaceMatchText,
type TextSearchOptions
} from "timi-web/editor";
import { Toolkit } from "timi-web";
import type { PendingMediaItem, UploadMediaType, UploadResult, TiptapEditorInstance } from "timi-web/editor";
} from "@timi/web/editor";
import { Toolkit } from "@timi/web/utils";
import type { PendingMediaItem, UploadMediaType, UploadResult, TiptapEditorInstance } from "@timi/web/editor";
import TiptapToolbar from "./TiptapToolbar.vue";
import { useTiptapEditor } from "timi-web/editor";
import { useTiptapEditor } from "@timi/web/editor";
import {
ATTACHMENT_ID_ATTR,
LOCAL_MEDIA_ID_PREFIX,
TEMP_FILE_ID_ATTR,
isLocalMediaId,
normalizeContent
} from "timi-web/editor";
} from "@timi/web/editor";
defineOptions({
name: "TiptapEditor"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const TiptapView = WebToolkit.withInstall(view);
export default TiptapView;
+1 -1
View File
@@ -10,7 +10,7 @@
</template>
<script lang="ts" setup>
import { normalizeContent, useTiptapView } from "timi-web/editor";
import { normalizeContent, useTiptapView } from "@timi/web/editor";
defineOptions({
name: "TiptapView"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import type { UserLevelInfo } from "./types";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const UserProfile = WebToolkit.withInstall(view);
export default UserProfile;
+1 -1
View File
@@ -43,7 +43,7 @@
</template>
<script lang="ts" setup>
import { Icon } from "timi-web";
import { Icon } from "@timi/web/components/icon";
import { toUserLevel } from "../user-level";
import { ImageType } from "./types";
import type {
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const UserProfilePopup = WebToolkit.withInstall(view);
export default UserProfilePopup;
-2
View File
@@ -1,8 +1,6 @@
import "./assets/style/tdesign-custom.less";
import { popupUserStore } from "./store/popupUser";
import "./components/tiptap-content.less";
import "timi-web/style.css";
import "../../timi-web/src/components/prism-code-block.less";
export * from "./components";
+1 -1
View File
@@ -1,4 +1,4 @@
import { PopupConfig, PopupType } from "timi-web";
import { PopupConfig, PopupType } from "@timi/web/utils";
import type { UserView } from "~/components/user-profile/types";
const user = ref<UserView>();
+2 -5
View File
@@ -2,7 +2,7 @@
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "Bundler",
"useDefineForClassFields": true,
"jsx": "preserve",
"strict": true,
@@ -20,10 +20,7 @@
"~/*": [
"./src/*"
],
"timi-web/editor": [
"../timi-web/src/editor/index.ts"
],
"timi-tdesign-pc": [
"@timi/tdesign-pc": [
"./src/index.ts"
]
}
+1 -1
View File
@@ -3,7 +3,7 @@
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node"
"moduleResolution": "Bundler"
},
"include": [
"vite.config.ts"
+49 -22
View File
@@ -1,3 +1,4 @@
import { existsSync, readdirSync, statSync } from "fs";
import { resolve } from "path";
import { Alias, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
@@ -13,19 +14,43 @@ const alias: Alias[] = [
replacement: resolve(__dirname, "./src")
},
{
find: "*",
replacement: resolve("")
},
{
find: /^timi-web\/editor$/,
replacement: resolve(__dirname, "../timi-web/src/editor/index.ts")
},
{
find: /^timi-tdesign-pc(\/(es|lib))?$/,
find: /^@timi\/tdesign-pc(\/(es|lib))?$/,
replacement: resolve(__dirname, "./src/index.ts")
}
];
/**
* 递归收集组件入口,组件目录下存在 index.ts 时即视为一个可独立导出的组件
*/
function collectComponentEntries(
dir: string,
prefix: string,
entries: Record<string, string>
) {
for (const name of readdirSync(dir)) {
const fullPath = resolve(dir, name);
if (!statSync(fullPath).isDirectory()) {
continue;
}
const entry = resolve(fullPath, "index.ts");
if (existsSync(entry)) {
entries[`${prefix}/${name}/index`] = entry;
}
collectComponentEntries(fullPath, `${prefix}/${name}`, entries);
}
}
const entries: Record<string, string> = {
index: resolve(__dirname, "./src/index.ts"),
"components/index": resolve(__dirname, "./src/components/index.ts"),
"store/popupUser": resolve(__dirname, "./src/store/popupUser.ts")
};
collectComponentEntries(
resolve(__dirname, "./src/components"),
"components",
entries
);
export default defineConfig({
server: {
port: 3004,
@@ -37,23 +62,25 @@ export default defineConfig({
build: {
outDir: "dist",
lib: {
entry: resolve(__dirname, "./src/index.ts"),
name: "TimiTDesignPC",
fileName: "timi-tdesign-pc"
entry: entries,
formats: ["es"],
fileName: (_format, entryName) => `${entryName}.js`,
cssFileName: "timi-tdesign-pc"
},
rollupOptions: {
external: [
"vue",
"timi-web",
"tdesign-vue-next"
],
external: (id) =>
id === "vue" ||
id === "@timi/web" ||
id.startsWith("@timi/web/") ||
id === "tdesign-vue-next" ||
id.startsWith("tdesign-vue-next/"),
output: {
globals: {
vue: "Vue"
}
chunkFileNames: "chunks/[name]-[hash].js"
}
},
cssCodeSplit: false,
minify: "terser",
target: "es2017",
terserOptions: {
compress: {
// eslint-disable-next-line camelcase
@@ -69,8 +96,8 @@ export default defineConfig({
}),
VueSetupExtend(),
dts({
pathsToAliases: false,
aliasesExclude: [/^timi-web\/editor$/]
entryRoot: "src",
pathsToAliases: false
}),
AutoImport({
imports: [