瀏覽代碼

✨ feat(goods-module): initialize goods management module

- create package.json with module configuration and dependencies
- set up directory structure for entities, services, schemas, routes and types
- define core types including Goods, GoodsCategory and related interfaces
- configure TypeScript and Vitest for development and testing
- export module entry points for different功能模块
- add scripts for build, test, lint and type checking
yourname 1 月之前
父節點
當前提交
c5e85cabcf

+ 79 - 0
packages/goods-module/package.json

@@ -0,0 +1,79 @@
+{
+  "name": "@d8d/goods-module",
+  "version": "1.0.0",
+  "description": "商品管理模块 - 提供商品分类和商品管理的完整CRUD功能",
+  "type": "module",
+  "main": "src/index.ts",
+  "types": "src/index.ts",
+  "exports": {
+    ".": {
+      "types": "./src/index.ts",
+      "import": "./src/index.ts",
+      "require": "./src/index.ts"
+    },
+    "./services": {
+      "types": "./src/services/index.ts",
+      "import": "./src/services/index.ts",
+      "require": "./src/services/index.ts"
+    },
+    "./schemas": {
+      "types": "./src/schemas/index.ts",
+      "import": "./src/schemas/index.ts",
+      "require": "./src/schemas/index.ts"
+    },
+    "./routes": {
+      "types": "./src/routes/index.ts",
+      "import": "./src/routes/index.ts",
+      "require": "./src/routes/index.ts"
+    },
+    "./entities": {
+      "types": "./src/entities/index.ts",
+      "import": "./src/entities/index.ts",
+      "require": "./src/entities/index.ts"
+    }
+  },
+  "files": [
+    "src"
+  ],
+  "scripts": {
+    "build": "tsc",
+    "dev": "tsc --watch",
+    "test": "vitest run",
+    "test:watch": "vitest",
+    "test:coverage": "vitest run --coverage",
+    "lint": "eslint src --ext .ts,.tsx",
+    "typecheck": "tsc --noEmit"
+  },
+  "dependencies": {
+    "@d8d/shared-types": "workspace:*",
+    "@d8d/shared-utils": "workspace:*",
+    "@d8d/shared-crud": "workspace:*",
+    "@d8d/file-module": "workspace:*",
+    "@d8d/auth-module": "workspace:*",
+    "@d8d/user-module": "workspace:*",
+    "@hono/zod-openapi": "^1.0.2",
+    "typeorm": "^0.3.20",
+    "zod": "^4.1.12"
+  },
+  "devDependencies": {
+    "@types/node": "^22.10.2",
+    "typescript": "^5.8.3",
+    "vitest": "^3.2.4",
+    "@d8d/shared-test-util": "workspace:*",
+    "@typescript-eslint/eslint-plugin": "^8.18.1",
+    "@typescript-eslint/parser": "^8.18.1",
+    "eslint": "^9.17.0"
+  },
+  "peerDependencies": {
+    "hono": "^4.8.5"
+  },
+  "keywords": [
+    "goods",
+    "products",
+    "categories",
+    "crud",
+    "api"
+  ],
+  "author": "D8D Team",
+  "license": "MIT"
+}

+ 2 - 0
packages/goods-module/src/entities/index.ts

@@ -0,0 +1,2 @@
+export * from './goods.entity.js';
+export * from './goods-category.entity.js';

+ 5 - 0
packages/goods-module/src/index.ts

@@ -0,0 +1,5 @@
+export * from './entities/index.js';
+export * from './services/index.js';
+export * from './schemas/index.js';
+export * from './routes/index.js';
+export * from './types/goods.types.js';

+ 5 - 0
packages/goods-module/src/routes/index.ts

@@ -0,0 +1,5 @@
+export * from './goods.js';
+export * from './goods-categories.js';
+export * from './random.js';
+export * from './user-routes.js';
+export * from './admin-routes.js';

+ 5 - 0
packages/goods-module/src/schemas/index.ts

@@ -0,0 +1,5 @@
+export * from './goods.schema.js';
+export * from './goods-category.schema.js';
+export * from './random.schema.js';
+export * from './user-goods.schema.js';
+export * from './admin-goods.schema.js';

+ 2 - 0
packages/goods-module/src/services/index.ts

@@ -0,0 +1,2 @@
+export * from './goods.service.js';
+export * from './goods-category.service.js';

+ 29 - 0
packages/goods-module/src/types/goods.types.ts

@@ -0,0 +1,29 @@
+import type { Goods } from '../entities/goods.entity.js';
+import type { GoodsCategory } from '../entities/goods-category.entity.js';
+
+export type { Goods, GoodsCategory };
+
+export interface RandomGoodsQuery {
+  categoryId?: number;
+  includeImages?: boolean;
+  limit?: number;
+}
+
+export interface RandomGoodsResponse {
+  goods: Goods[];
+  total: number;
+}
+
+export interface GoodsWithRelations extends Goods {
+  category?: GoodsCategory;
+  supplier?: any; // TODO: 定义供应商类型
+  merchant?: any; // TODO: 定义商户类型
+  imageFile?: any; // TODO: 定义文件类型
+  slideImages?: any[]; // TODO: 定义文件类型数组
+}
+
+export interface GoodsCategoryWithRelations extends GoodsCategory {
+  parent?: GoodsCategory;
+  children?: GoodsCategory[];
+  imageFile?: any; // TODO: 定义文件类型
+}

+ 16 - 0
packages/goods-module/tsconfig.json

@@ -0,0 +1,16 @@
+{
+  "extends": "../../tsconfig.json",
+  "compilerOptions": {
+    "composite": true,
+    "rootDir": ".",
+    "outDir": "dist"
+  },
+  "include": [
+    "src/**/*",
+    "tests/**/*"
+  ],
+  "exclude": [
+    "node_modules",
+    "dist"
+  ]
+}

+ 21 - 0
packages/goods-module/vitest.config.ts

@@ -0,0 +1,21 @@
+import { defineConfig } from 'vitest/config';
+
+export default defineConfig({
+  test: {
+    globals: true,
+    environment: 'node',
+    include: ['tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
+    coverage: {
+      provider: 'v8',
+      reporter: ['text', 'json', 'html'],
+      exclude: [
+        'tests/**',
+        '**/*.d.ts',
+        '**/*.config.*',
+        '**/dist/**'
+      ]
+    },
+    // 关闭并行测试以避免数据库连接冲突
+    fileParallelism: false
+  }
+});