Commit a40d375b by liimin

init

1 parent 8d936d46
duyia
Userconfig
addwords
noneles
rangestart
compileroptions
lintstagedrc
\ No newline at end of file \ No newline at end of file
pnpm lint:prettier && pnpm lint:eslint && pnpm lint:spellcheck
pnpm precommit
export default {
"*.{js,ts,tsx,jsx,vue}": ["prettier --write", "eslint --fix"],
"*.{md,json,css,less,scss}": ["prettier --write"]
};
engine-strict=true
\ No newline at end of file \ No newline at end of file
# .prettierignore
dist
public
.local
node_modules
pnpm-lock.yaml
\ No newline at end of file \ No newline at end of file
# Venus Monorepo
## 简介
- 一个使用 `pnpm` 管理的前端/后端与组件库的 Monorepo。
- 包含应用层(`apps/frontend`, `apps/backend`)与多个可复用包(`packages/*`)。
- 统一使用 `TypeScript` 与 `Rollup` 构建,配合 `ESLint`、`Prettier`、`Husky`、`lint-staged`、`Commitlint`、`Commitizen` 保持代码与提交规范。
## 技术栈
- 工作空间与包管理:`pnpm`(`pnpm-workspace.yaml`)
- 语言:`TypeScript`
- 框架:`Vue 3`(组件库)、可扩展到 React 等
- 构建:`Rollup`(统一打包脚本)
- 代码质量:`ESLint`(含 `vue-eslint-parser`)、`Prettier`、`CSpell`
- 提交规范:`Husky`、`lint-staged`、`Commitlint`、`Commitizen`
## 环境要求
- `Node >= 20`
- `pnpm >= 10.8.1`
## 快速开始
- 安装依赖:
- `pnpm install`
- 初始化 Husky(如未自动安装):
- `pnpm prepare`
- 构建所有包:
- `pnpm build`
- 开发模式(监听并增量打包 packages):
- `node scripts/dev.js`
- 单独构建某个包:
- `node scripts/buildSingle.js <packageName>`
- 示例:`node scripts/buildSingle.js components/vue`
## 项目结构
- `apps/frontend`:前端示例或入口(`tsconfig.json` 使用 `lib: [DOM, ESNext]`)
- `apps/backend`:后端示例或入口(`tsconfig.json` 使用 `types: [node]`)
- `packages/components/vue`:Vue 组件库(输出 `esm/cjs/iife`,`vue` 为 peer 依赖)
- `packages/tools` / `packages/charts` / `packages/cli`:工具、图表、CLI 辅助库
- `scripts/`:统一构建脚本(`build.js`/`dev.js`/`buildSingle.js`/`buildBase.js`)
## 可用脚本
- 格式化:`pnpm lint:prettier`
- 代码检查与修复:`pnpm lint:eslint`
- 拼写检查:`pnpm lint:spellcheck`
- 统一构建所有包:`pnpm build`
- 使用 `Commitizen` 提交:`pnpm commit`
- 预提交钩子:`pnpm precommit`(实际由 `husky` 在 `git commit` 时触发)
## 代码规范与 Lint
- `eslint.config.js`:
- 基础:`@eslint/js` + `typescript-eslint` + `eslint-config-prettier`
- 前端与包(`apps/frontend`、`packages/*`):启用 `eslint-plugin-vue` 的推荐规则;`parser: vue-eslint-parser`,并在 `<script lang="ts">` 使用 `typescript-eslint` 的解析器;`globals: browser`。
- 后端(`apps/backend`):`globals: node`。
- 已忽略:`dist`、`node_modules`、`scripts`、`*.d.ts`、`*.md`。
- `prettier.config.js` 与 `.prettierignore`:统一代码风格,忽略 `dist`、`node_modules` 等。
- `lint-staged`(`.lintstagedrc.js`):
- `*.{js,ts,tsx,jsx,vue}` → `prettier --write`、`eslint --fix`
- `*.{md,json,css,less,scss}` → `prettier --write`
- `CSpell`(`cspell.json`):
- 自定义词典:`./.cspell/custom-dictionary.txt`
- 常见目录与文件忽略(`node_modules`, `dist`, `*.d.ts`, `package.json` 等)
## 提交规范
- 使用 `pnpm commit` 进入交互式提交(`cz-git`),遵循 `commitlint` 规则。
- 可用类型包含:`feat`、`fix`、`docs`、`style`、`refactor`、`perf`、`test`、`build`、`ci`、`chore`、`revert`、`wip`、`workflow`、`types`、`release` 等。
- `husky` 预提交钩子会运行 `lint-staged`:自动执行 `prettier` 与 `eslint`,如失败将阻止提交。
## 构建与输出
- 统一构建脚本会扫描 `packages/*`:
- 仅对存在 `src/index.ts` 的包进行构建。
- Vue 组件包会作为外部依赖保留 `vue`,并在 `iife` 格式下使用 `globals: { vue: "Vue" }`。
- 输出目录:`dist/`,默认 `esm` 与 `cjs`,Vue 组件库可额外输出 `iife`。
## 常见问题
- 推送被拒(非快进):
- `git pull --rebase venus master` → 解决冲突 → `git push -u venus master`
- ESLint 报 `process 未定义`:
- 前端文件应使用浏览器环境,移除无用的 `process` 引用或在后端环境下处理。
- 拼写检查拦截:
- 将需保留的技术术语添加到 `./.cspell/custom-dictionary.txt`,并执行 `pnpm lint:spellcheck`。
## 许可
- `ISC`
console.log("hello world");
// const test = 100;
// const duyia = 1000;
// console.log(duyia);
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"],
"lib": ["ESNext"]
}
}
console.log("hello world");
window.addEventListener("DOMContentLoaded", () => {
console.log("DOMContentLoaded");
});
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": [],
"lib": ["ESNext", "DOM"]
}
}
/**@type {import('cz-git').Userconfig}*/
export default {
extends: ["@commitlint/config-conventional"],
rules: {
// @see: https://commitlint.js.org/#/reference-rules
"body-leading-blank": [2, "always"],
"footer-leading-blank": [1, "always"],
"header-max-length": [2, "always", 108],
"subject-empty": [2, "never"],
"type-empty": [2, "never"],
"subject-case": [0],
"type-enum": [
2,
"always",
[
"feat",
"fix",
"docs",
"style",
"refactor",
"perf",
"test",
"build",
"ci",
"chore",
"revert",
"wip",
"workflow",
"types",
"release"
]
]
},
prompt: {
scopes: ["root", "backend", "frontend", "components", "utils"],
allowCustomScopes: true,
skipQuestions: ["body", "footer", "footerPrefix", "breaking"], //跳过"详细描述" 和 "底部信息"
messages: {
type: "请选择提交类型:",
scope: "请输入修改范围(可选):",
customScope: "请输入自定义修改范围:",
subject: "请输入简短的变更描述:",
body: '请输入详细的变更描述(可选)。使用"|"换行:',
footer: "请输入要关闭的问题(可选):",
confirmCommit: "是否确认提交变更?"
},
types: [
{ value: "feat", name: "feat: 新增功能" },
{ value: "fix", name: "fix: 修复 bug" },
{ value: "docs", name: "docs: 文档变更" },
{ value: "style", name: "style: 代码格式(不影响功能, 例如空格、分号等格式修正)" },
{ value: "refactor", name: "refactor: 代码重构(不包括 bug 修复, 功能新增)" },
{ value: "perf", name: "perf: 性能优化" },
{ value: "test", name: "test: 添加疏漏测试或已有测试改动" },
{ value: "build", name: "build: 构建流程、外部依赖变更(如升级 npm 包、修改 webpack 配置等)" },
{ value: "ci", name: "ci: 修改 CI 配置、脚本" },
{ value: "chore", name: "chore: 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)" },
{ value: "revert", name: "revert: 回滚 commit" },
{ value: "wip", name: "wip: 进行中" },
{ value: "workflow", name: "workflow: 工作流改进" },
{ value: "types", name: "types: 类型定义文件更改" },
{ value: "release", name: "release: 发布版本" }
]
}
};
{
"import": ["@cspell/dict-lorem-ipsum/cspell-ext.json"],
"caseSensitive": false,
"dictionaries": ["custom-dictionary"],
"dictionaryDefinitions": [
{
"name": "custom-dictionary",
"path": "./.cspell/custom-dictionary.txt",
"addwords": true
}
],
"ignorePaths": [
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/docs/**",
"**/vendor/**",
"**/public/**",
"**/static/**",
"**/out/**",
"**/tmp/**",
"**/*.d.ts",
"**/package-lock.json",
"**/package.json",
"**/cache/**",
"**/logs/**"
]
}
import { defineConfig } from "eslint/config";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginPrettier from "eslint-plugin-prettier";
import eslintPluginVue from "eslint-plugin-vue";
import vueParser from "vue-eslint-parser";
import globals from "globals";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import { rules } from "eslint-config-prettier";
const ignores = ["**/dist/**", "**/node_modules/**", ".*", "scripts/**", "**/*.d.ts", "**/*.md"];
export default defineConfig(
{
// 通用配置
ignores, // 忽略项
extends: [eslint.configs.recommended, ...tseslint.configs.recommended, eslintConfigPrettier], // 继承规则
plugins: {
prettier: eslintPluginPrettier
// vue: eslintPluginVue,
},
languageOptions: {
ecmaVersion: "latest", //ecma版本
sourceType: "module", //es模块
parser: tseslint.parser // 使用 TypeScript 解析器
},
rules: {
"no-var": "error", //禁用var,使用let或const代替
...rules
}
},
//前端配置
{
ignores,
files: ["apps/frontend/**/*.{ts,js,tsx,jsx,vue}", "packages/**/*.{ts,js,tsx,jsx,vue}"],
extends: [...eslintPluginVue.configs["flat/recommended"], eslintConfigPrettier],
languageOptions: {
parser: vueParser,
parserOptions: {
parser: tseslint.parser
},
globals: {
...globals.browser
}
}
},
// 后端配置
{
ignores,
files: ["apps/backend/**/*.{ts,js}"],
languageOptions: {
globals: {
...globals.node
}
}
}
);
{
"name": "venus",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint:prettier": "prettier --write \"**/*.{js,ts,mjs,cjs,json,tsx,css,less,scss,vue,html,md}\"",
"lint:eslint": "eslint --fix \"**/*.{js,ts,mjs,cjs,json,tsx,css,less,scss,vue,html,md}\"",
"lint:spellcheck": "cspell lint \"(packages|apps)/**/*\" --config cspell.json \"**/*.{js,ts,mjs,cjs,json,css,less,scss,vue,html,md}\"",
"commit": "cz",
"prepare": "husky",
"precommit": "lint-staged",
"build": "node scripts/build.js"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-git"
}
},
"keywords": [],
"author": "liimin",
"license": "ISC",
"packageManager": "pnpm@10.8.1",
"engines": {
"node": ">=20",
"npm": ">=9",
"pnpm": ">=10.8.1"
},
"devDependencies": {
"@commitlint/cli": "^20.0.0",
"@commitlint/config-conventional": "^20.0.0",
"@cspell/dict-lorem-ipsum": "^4.0.5",
"@eslint/js": "^9.36.0",
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^24.5.2",
"@vitejs/plugin-vue": "^6.0.1",
"commitizen": "^4.3.1",
"cspell": "^9.2.1",
"cz-git": "^1.12.0",
"eslint": "^9.36.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-vue": "^10.5.0",
"globals": "^16.4.0",
"husky": "^9.1.7",
"lint-staged": "^16.2.6",
"prettier": "^3.6.2",
"rollup": "^4.52.3",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"rollup-plugin-vue": "^6.0.0",
"typescript": "^5.9.2",
"typescript-eslint": "^8.44.1",
"vue-eslint-parser": "^10.2.0"
},
"dependencies": {
"vue": "^3.5.22"
}
}
{
"name": "@venus/charts",
"private": true,
"version": "0.0.1",
"description": "Venus charts utilities",
"type": "module",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
}
},
"files": [
"dist"
],
"buildOptions": {
"formats": [
"esm",
"cjs"
],
"name": "VenusCharts"
},
"devDependencies": {
"typescript": "*"
}
}
export const version = "0.0.1";
export type ChartPoint = { x: number; y: number };
export function lineSeries(points: ChartPoint[]) {
return points.map(p => ({ x: p.x, y: p.y }));
}
export function minMax(points: ChartPoint[]) {
let minX = Infinity,
maxX = -Infinity,
minY = Infinity,
maxY = -Infinity;
for (const p of points) {
if (p.x < minX) minX = p.x;
if (p.x > maxX) maxX = p.x;
if (p.y < minY) minY = p.y;
if (p.y > maxY) maxY = p.y;
}
return { minX, maxX, minY, maxY };
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationDir": "./dist",
"outDir": "./dist",
"rootDir": "./src",
"types": ["node"],
"lib": ["ES2020"],
"moduleResolution": "bundler",
"skipLibCheck": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
{
"name": "@venus/cli",
"private": true,
"version": "0.0.1",
"description": "Venus CLI helpers",
"type": "module",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
}
},
"files": [
"dist"
],
"buildOptions": {
"formats": [
"esm",
"cjs"
],
"name": "VenusCli"
},
"devDependencies": {
"typescript": "*"
}
}
export const version = "0.0.1";
export function greet(name: string) {
return `Hello, ${name}!`;
}
export function parseArgs(argv: string[]) {
const out: Record<string, string | boolean> = {};
for (let i = 0; i < argv.length; i++) {
const token = argv[i];
if (token.startsWith("--")) {
const [key, val] = token.slice(2).split("=");
out[key] = val ?? true;
}
}
return out;
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationDir": "./dist",
"outDir": "./dist",
"rootDir": "./src",
"types": ["node"],
"lib": ["ES2020"],
"moduleResolution": "bundler",
"skipLibCheck": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
{
"name": "@venus/components-vue",
"version": "1.0.0",
"description": "Vue components library for Venus design system",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./dist/*": "./dist/*"
},
"files": [
"dist",
"src"
],
"scripts": {
"clean": "rimraf dist",
"type-check": "vue-tsc --noEmit",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"vue",
"components",
"ui",
"venus",
"design-system"
],
"author": "liimin",
"license": "ISC",
"dependencies": {
"vue": "^3.5.22"
},
"devDependencies": {
"@types/node": "^24.5.2",
"@vue/typescript-plugin": "^3.1.0",
"rimraf": "^6.0.1",
"typescript": "^5.9.2",
"vue-tsc": "^3.1.0"
},
"peerDependencies": {
"vue": "^3.0.0"
},
"buildOptions": {
"name": "VenusComponentsVue",
"formats": [
"esm",
"cjs",
"iife"
]
}
}
<template>
<button
:type="type"
:class="[
'v-button',
`v-button--${variant}`,
`v-button--${size}`,
{
'v-button--disabled': disabled,
'v-button--loading': loading
}
]"
:disabled="disabled || loading"
@click="handleClick"
>
<span v-if="loading" class="v-button__loading">⏳</span>
<span v-if="icon && !loading" class="v-button__icon">{{ icon }}</span>
<span v-if="$slots.default" class="v-button__content">
<slot />
</span>
</button>
</template>
<script lang="ts">
// Props 定义
export interface VButtonProps {
type?: "button" | "submit" | "reset";
size?: "small" | "medium" | "large";
variant?: "primary" | "secondary" | "danger" | "ghost";
disabled?: boolean;
loading?: boolean;
icon?: string;
}
// Emits 定义
export interface VButtonEmits {
click: [event: MouseEvent];
}
</script>
<script setup lang="ts">
const props = withDefaults(defineProps<VButtonProps>(), {
type: "button",
size: "medium",
variant: "primary",
disabled: false,
loading: false,
icon: ""
});
const emit = defineEmits<VButtonEmits>();
// 点击事件处理
const handleClick = (event: Event) => {
if (!props.disabled && !props.loading) {
emit("click", event as MouseEvent);
}
};
</script>
<style scoped>
.venus-button {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 8px 16px;
border: 1px solid transparent;
border-radius: 6px;
font-size: 14px;
font-weight: 500;
line-height: 1.5;
cursor: pointer;
transition: all 0.2s ease-in-out;
user-select: none;
}
.venus-button:focus {
outline: 2px solid #3b82f6;
outline-offset: 2px;
}
/* 尺寸变体 */
.venus-button--small {
padding: 4px 8px;
font-size: 12px;
}
.venus-button--medium {
padding: 8px 16px;
font-size: 14px;
}
.venus-button--large {
padding: 12px 24px;
font-size: 16px;
}
/* 颜色变体 */
.venus-button--primary {
background-color: #3b82f6;
color: white;
border-color: #3b82f6;
}
.venus-button--primary:hover:not(:disabled) {
background-color: #2563eb;
border-color: #2563eb;
}
.venus-button--secondary {
background-color: #6b7280;
color: white;
border-color: #6b7280;
}
.venus-button--secondary:hover:not(:disabled) {
background-color: #4b5563;
border-color: #4b5563;
}
.venus-button--danger {
background-color: #ef4444;
color: white;
border-color: #ef4444;
}
.venus-button--danger:hover:not(:disabled) {
background-color: #dc2626;
border-color: #dc2626;
}
.venus-button--ghost {
background-color: transparent;
color: #3b82f6;
border-color: #3b82f6;
}
.venus-button--ghost:hover:not(:disabled) {
background-color: #3b82f6;
color: white;
}
/* 状态 */
.venus-button--disabled,
.venus-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.venus-button--loading {
cursor: not-allowed;
}
.venus-button--icon-only {
padding: 8px;
}
.venus-button--icon-only.venus-button--small {
padding: 4px;
}
.venus-button--icon-only.venus-button--large {
padding: 12px;
}
.venus-button__loading {
animation: spin 1s linear infinite;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>
import VButton from "./VButton.vue";
export { VButton };
export default VButton;
// @ts-nocheck
export {};
declare module "vue" {
export interface GlobalComponents {}
export interface GlobalDirectives {}
}
declare global {
const __VLS_directiveBindingRestFields: { instance: null; oldValue: null; modifiers: any; dir: any };
const __VLS_unref: typeof import("vue").unref;
const __VLS_placeholder: any;
type __VLS_NativeElements = __VLS_SpreadMerge<SVGElementTagNameMap, HTMLElementTagNameMap>;
type __VLS_IntrinsicElements = globalThis.JSX.IntrinsicElements;
type __VLS_Element = globalThis.JSX.Element;
type __VLS_GlobalComponents = import("vue").GlobalComponents &
Pick<typeof import("vue"), "Transition" | "TransitionGroup" | "KeepAlive" | "Suspense" | "Teleport">;
type __VLS_GlobalDirectives = import("vue").GlobalDirectives;
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
type __VLS_SpreadMerge<A, B> = Omit<A, keyof B> & B;
type __VLS_WithComponent<
N0 extends string,
LocalComponents,
Self,
N1 extends string,
N2 extends string,
N3 extends string
> = N1 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N1] }
: N2 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N2] }
: N3 extends keyof LocalComponents
? { [K in N0]: LocalComponents[N3] }
: Self extends object
? { [K in N0]: Self }
: N1 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N1] }
: N2 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N2] }
: N3 extends keyof __VLS_GlobalComponents
? { [K in N0]: __VLS_GlobalComponents[N3] }
: {};
type __VLS_FunctionalComponentCtx<T, K> = __VLS_PickNotAny<
"__ctx" extends keyof __VLS_PickNotAny<K, {}> ? (K extends { __ctx?: infer Ctx } ? NonNullable<Ctx> : never) : any,
T extends (props: any, ctx: infer Ctx) => any ? Ctx : any
>;
type __VLS_FunctionalComponentProps<T, K> = "__ctx" extends keyof __VLS_PickNotAny<K, {}>
? K extends { __ctx?: { props?: infer P } }
? NonNullable<P>
: never
: T extends (props: infer P, ...args: any) => any
? P
: {};
type __VLS_FunctionalComponent<T> = (
props: (T extends { $props: infer Props } ? Props : {}) & Record<string, unknown>,
ctx?: any
) => __VLS_Element & {
__ctx?: {
attrs?: any;
slots?: T extends { $slots: infer Slots } ? Slots : Record<string, any>;
emit?: T extends { $emit: infer Emit } ? Emit : {};
props?: (T extends { $props: infer Props } ? Props : {}) & Record<string, unknown>;
expose?: (exposed: T) => void;
};
};
type __VLS_IsFunction<T, K> = K extends keyof T
? __VLS_IsAny<T[K]> extends false
? unknown extends T[K]
? false
: true
: false
: false;
type __VLS_NormalizeComponentEvent<
Props,
Emits,
onEvent extends keyof Props,
Event extends keyof Emits,
CamelizedEvent extends keyof Emits
> =
__VLS_IsFunction<Props, onEvent> extends true
? Props
: __VLS_IsFunction<Emits, Event> extends true
? { [K in onEvent]?: Emits[Event] }
: __VLS_IsFunction<Emits, CamelizedEvent> extends true
? { [K in onEvent]?: Emits[CamelizedEvent] }
: Props;
// fix https://github.com/vuejs/language-tools/issues/926
type __VLS_UnionToIntersection<U> = (U extends unknown ? (arg: U) => unknown : never) extends (
arg: infer P
) => unknown
? P
: never;
type __VLS_OverloadUnionInner<T, U = unknown> = U & T extends (...args: infer A) => infer R
? U extends T
? never
: __VLS_OverloadUnionInner<T, Pick<T, keyof T> & U & ((...args: A) => R)> | ((...args: A) => R)
: never;
type __VLS_OverloadUnion<T> = Exclude<
__VLS_OverloadUnionInner<(() => never) & T>,
T extends () => never ? never : () => never
>;
type __VLS_ConstructorOverloads<T> =
__VLS_OverloadUnion<T> extends infer F
? F extends (event: infer E, ...args: infer A) => any
? { [K in E & string]: (...args: A) => void }
: never
: never;
type __VLS_NormalizeEmits<T> = __VLS_PrettifyGlobal<
__VLS_UnionToIntersection<
__VLS_ConstructorOverloads<T> & {
[K in keyof T]: T[K] extends any[] ? { (...args: T[K]): void } : never;
}
>
>;
type __VLS_EmitsToProps<T> = __VLS_PrettifyGlobal<{
[K in string & keyof T as `on${Capitalize<K>}`]?: (
...args: T[K] extends (...args: infer P) => any ? P : T[K] extends null ? any[] : never
) => any;
}>;
type __VLS_ResolveEmits<
Comp,
Emits,
TypeEmits = {},
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? (string extends keyof E ? {} : E) : never
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
type __VLS_ResolveDirectives<T> = {
[K in keyof T & string as `v${Capitalize<K>}`]: T[K];
};
type __VLS_PrettifyGlobal<T> = { [K in keyof T as K]: T[K] } & {};
type __VLS_WithDefaultsGlobal<P, D> = {
[K in keyof P as K extends keyof D ? K : never]-?: P[K];
} & {
[K in keyof P as K extends keyof D ? never : K]: P[K];
};
type __VLS_UseTemplateRef<T> = Readonly<import("vue").ShallowRef<T | null>>;
type __VLS_ProxyRefs<T> = import("vue").ShallowUnwrapRef<T>;
function __VLS_getVForSourceType<T extends number | string | any[] | Iterable<any>>(
source: T
): [
item: T extends number
? number
: T extends string
? string
: T extends any[]
? T[number]
: T extends Iterable<infer T1>
? T1
: any,
index: number
][];
function __VLS_getVForSourceType<T>(source: T): [item: T[keyof T], key: keyof T, index: number][];
function __VLS_getSlotParameters<S, D extends S>(slot: S, decl?: D): D extends (...args: infer P) => any ? P : any[];
function __VLS_asFunctionalDirective<T>(
dir: T
): T extends import("vue").ObjectDirective
? NonNullable<T["created" | "beforeMount" | "mounted" | "beforeUpdate" | "updated" | "beforeUnmount" | "unmounted"]>
: T extends (...args: any) => any
? T
: (arg1: unknown, arg2: unknown, arg3: unknown, arg4: unknown) => void;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(
t: T,
instance?: K
): T extends new (...args: any) => any
? __VLS_FunctionalComponent<K>
: T extends () => any
? (props: {}, ctx?: any) => ReturnType<T>
: T extends (...args: any) => any
? T
: __VLS_FunctionalComponent<{}>;
function __VLS_functionalComponentArgsRest<T extends (...args: any) => any>(
t: T
): 2 extends Parameters<T>["length"] ? [any] : [];
function __VLS_asFunctionalElement<T>(tag: T, endTag?: T): (attrs: T & Record<string, unknown>) => void;
function __VLS_asFunctionalSlot<S>(slot: S): S extends () => infer R ? (props: {}) => R : NonNullable<S>;
function __VLS_tryAsConstant<const T>(t: T): T;
}
// 组件导出
export { default as VButton } from "./VButton";
// 类型导出 - 暂时注释掉,因为 Vue 组件的类型导出在构建时有问题
// export type { VButtonProps, VButtonEmits } from './VButton/VButton.vue'
// 版本信息
export const version = "1.0.0";
// 导入组件用于默认导出
import VButton from "./VButton";
// 默认导出所有组件
export default {
VButton,
version
};
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src",
"types": ["node"],
"lib": ["DOM", "ES2020"],
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"skipLibCheck": true,
"isolatedModules": true
},
"vueCompilerOptions": {
"target": 3,
"globalTypesPath": "./src/global.d.ts"
},
"include": ["src/**/*", "src/global.d.ts"],
"exclude": ["node_modules", "dist"]
}
{
"name": "@venus/tools",
"version": "0.1.0",
"description": "Utilities for Venus",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./dist/*": "./dist/*"
},
"files": [
"dist",
"src"
],
"buildOptions": {
"name": "VenusTools",
"formats": [
"esm",
"cjs"
]
}
}
// Venus tools entry
export const version = "0.1.0";
export function noop(): void {}
export function sum(a: number, b: number): number {
return a + b;
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"rootDir": "./src",
"types": ["node"],
"lib": ["ES2020"],
"moduleResolution": "bundler",
"skipLibCheck": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}
This diff could not be displayed because it is too large.
packages:
- "packages/*"
- "apps/frontend/*"
- "apps/backend/*"
// prettier.config.js
/**
* @type {import('prettier').config}
* @see https://www.prettier.cn/docs/options.html
*/
export default {
// 指定最大换行长度
printWidth: 120,
//缩进制表符宽度|空格数
tabWidth: 2,
//使用制表符而不是空格缩进行(true:制表符,false:空格)
useTabs: false,
//结尾不用分号(true:有,false:没有)
semi: true,
//使用单引号(true:单引号,false:双引号)
singleQuote: false,
// 在对象字面量中决定是否将属性名用引号括起来 可选值"<as-needed|con
quoteProps: "as-needed",
//在JSX中使用单引号而不是双引号(true:单引号,false:双引号)
jsxSingleQuote: false,
// 多行时尽可能打印尾随逗号 可选值"<noneles5|all>"
trailingComma: "none",
//在对象字面量中是否需要用空格括起来(true:需要,false:不需要)
bracketSpacing: true,
//将{>}多行元素放在最后一行的末尾,而不是单独放在下一行(true:放末尾,false:单独一行)
bracketSameLine: false,
//(x)={>}<{><}>箭头函数参数只有一个时是否要有小括号(avoid:省略括号,always:不省略括号)
arrowParens: "avoid",
//指定要使用的解析器,不需要写文件开头的 @prettier
requirePragma: false,
//可以在文件顶部插入一个特殊标记,指定该文件已使用 Prettier 格式化
insertPragma: false,
//用于控制文本是否应该被换行以及如何进行换行
proseWrap: "preserve",
//在htm中空格是否是敏感的“css”。遵守 C5S 显示属性的默认值,"strict”。空格被认为是敏感的,“ignore”。 空格被认为是不敏感的
htmlWhitespaceSensitivity: "css",
//控制在 Vue 单文件组件中{<}script{>}和{<}style{>}标签内的代码缩进方式
vueIndentScriptAndStyle: false,
//换行符使用 1f 结尾是 可选值"{<}auto|lf|crlf|cr{>}"
endOfLine: "auto",
///这两个选项可用于格式化以给定字符偏移量(分别包括和不包括)开始和结束的代码(rangestart:开始,rangeEnd:结束)
rangeStart: 0,
rangeEnd: Infinity
};
// 进行统一打包管理 rollup
import { rollup } from "rollup";
import { getRollupConfigs, clearDist } from "./buildBase.js";
import terser from "@rollup/plugin-terser";
async function build() {
const configs = await getRollupConfigs();
for (const name of Object.keys(configs)) {
clearDist(name);
const config = configs[name];
console.log(`正在打包:${name}`);
const bundle = await rollup({
input: config.input,
plugins: [...config.plugins, terser()],
external: config.external
});
const tasks = [];
for (const output of config.output) {
tasks.push(bundle.write(output));
}
await Promise.all(tasks);
console.log(`打包完成:${name}`);
}
}
build();
import path from "node:path";
import fs from "node:fs";
import URL from "node:url";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import vue from "rollup-plugin-vue";
import postcss from "rollup-plugin-postcss";
const __filename = URL.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function discoverPackages() {
const base = path.resolve(__dirname, "../packages");
const result = [];
// tools
const toolsPath = path.resolve(base, "tools");
if (fs.existsSync(path.resolve(toolsPath, "package.json"))) {
result.push("tools");
}
// charts
const chartsPath = path.resolve(base, "charts");
if (fs.existsSync(path.resolve(chartsPath, "package.json"))) {
result.push("charts");
}
// cli
const cliPath = path.resolve(base, "cli");
if (fs.existsSync(path.resolve(cliPath, "package.json"))) {
result.push("cli");
}
// components/*
const componentsPath = path.resolve(base, "components");
if (fs.existsSync(componentsPath)) {
const subs = fs.readdirSync(componentsPath, { withFileTypes: true });
for (const dirent of subs) {
if (dirent.isDirectory()) {
const name = dirent.name;
const pkgPath = path.resolve(componentsPath, name, "package.json");
if (fs.existsSync(pkgPath)) {
result.push(`components/${name}`);
}
}
}
}
return result;
}
function getPackageRoots() {
const pkgs = discoverPackages();
return pkgs.map(pkg => path.resolve(__dirname, `../packages`, pkg));
}
async function packageJson(root) {
const pkgPath = path.resolve(root, "package.json");
const content = await fs.promises.readFile(pkgPath, "utf-8");
return JSON.parse(content);
}
export async function getRollupConfig(root) {
const config = await packageJson(root);
const tsconfig = path.resolve(root, "tsconfig.json");
const { name, formats = ["esm", "cjs"] } = config.buildOptions || {};
const dist = path.resolve(root, "./dist");
const entry = path.resolve(root, "./src/index.ts");
if (!fs.existsSync(entry)) {
return null;
}
const isVue = /components[\\/]+vue$/.test(root) || !!(config.peerDependencies && config.peerDependencies.vue);
const basePlugins = [nodeResolve(), commonjs(), postcss()];
const plugins = isVue
? [
vue({ compileTemplate: true }),
typescript({ tsconfig, tsconfigOverride: { compilerOptions: { outDir: dist } }, check: false }),
...basePlugins
]
: [typescript({ tsconfig, tsconfigOverride: { compilerOptions: { outDir: dist } }, check: false }), ...basePlugins];
const rollupOptions = {
input: entry,
external: isVue ? ["vue"] : [],
plugins
};
const output = [];
for (const format of formats) {
const outputItem = {
format,
file: path.resolve(dist, `index.${format}.js`),
sourcemap: true,
exports: "named",
globals: isVue ? { vue: "Vue" } : {}
};
if (format === "iife") {
outputItem.name = name || "VenusLib";
}
output.push(outputItem);
}
rollupOptions.output = output;
rollupOptions.watch = {
include: path.resolve(root, "src/**"),
exclude: path.resolve(root, "node_modules/**"),
clearScreen: false
};
return rollupOptions;
}
export async function getRollupConfigs() {
const pkgs = discoverPackages();
const roots = getPackageRoots();
const configs = await Promise.all(roots.map(getRollupConfig));
const result = {};
for (let i = 0; i < pkgs.length; i++) {
const cfg = configs[i];
if (!cfg) {
console.warn(`跳过包: ${pkgs[i]},缺少入口文件 src/index.ts`);
continue;
}
result[pkgs[i]] = cfg;
}
return result;
}
export function clearDist(name) {
const dist = path.resolve(__dirname, `../packages`, name, `dist`);
if (fs.existsSync(dist)) {
fs.rmSync(dist, { recursive: true, force: true });
}
}
// 单独打包指定的包
import { rollup } from "rollup";
import { getRollupConfigs, clearDist } from "./buildBase.js";
import terser from "@rollup/plugin-terser";
import path from "node:path";
import URL from "node:url";
const __filename = URL.fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function buildSingle(packageName) {
if (!packageName) {
console.error("请指定要构建的包名");
process.exit(1);
}
const packagePath = path.resolve(__dirname, `../packages/${packageName}`);
try {
// 检查包是否存在
const fs = await import("node:fs");
if (!fs.existsSync(packagePath)) {
console.error(`包 ${packageName} 不存在`);
process.exit(1);
}
console.log(`正在构建包: ${packageName}`);
// 清理 dist 目录
const distPath = path.resolve(packagePath, "dist");
if (fs.existsSync(distPath)) {
fs.rmSync(distPath, { recursive: true, force: true });
}
// 获取构建配置
const { getRollupConfig } = await import("./buildBase.js");
const config = await getRollupConfig(packagePath);
console.log(`正在打包: ${packageName}`);
const bundle = await rollup({
input: config.input,
plugins: [...config.plugins, terser()],
external: config.external
});
const tasks = [];
for (const output of config.output) {
tasks.push(bundle.write(output));
}
await Promise.all(tasks);
console.log(`打包完成: ${packageName}`);
} catch (error) {
console.error(`构建失败: ${error.message}`);
process.exit(1);
}
}
// 从命令行参数获取包名
const packageName = process.argv[2];
buildSingle(packageName);
import { getRollupConfigs } from "./buildBase.js";
import { watch } from "rollup";
async function dev() {
const configs = await getRollupConfigs();
for (const name of Object.keys(configs)) {
const config = configs[name];
const watcher = watch(
config.output.map(o => ({
input: config.input,
plugins: [...config.plugins],
external: config.external,
output: o,
watch: config.watch
}))
);
watcher.on("event", event => {
if (event.code === "START") {
console.log(`开始监听: ${name}`);
} else if (event.code === "ERROR") {
console.error(`打包失败: ${name}`, event.error);
} else if (event.code === "BUNDLE_START") {
console.log(`开始打包: ${name}`);
} else if (event.code === "BUNDLE_END") {
console.log(`打包完成: ${name}`);
}
});
}
}
dev();
{
"compileroptions": {
"baseUrl": ".",
"module": "esnext",
"target": "esnext",
"types": [],
"lib": ["esnext"],
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"strict": true,
"verbatimModuleSyntax": false,
"moduleResolution": "bundler",
"isolatedModules": true,
"noUncheckedSideEffectImports": true,
"moduleDetection": "force",
"skipLibCheck": true
},
"exclude": ["node_modules", "dist"]
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!