diff --git a/AGENTS.md b/AGENTS.md index bb64d95..4fb3e96 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,13 +38,14 @@ src/ ├── preload/ # Preload 脚本 │ ├── index.ts # 暴露 API 到渲染进程 │ └── index.d.ts # 类型声明 +├── shared/ # 跨进程共享代码 +│ └── types/ # 共享类型定义 └── renderer/ # React 渲染进程 └── src/ ├── main.tsx # React 入口 ├── App.tsx # 根组件 ├── components/ # React 组件 - ├── stores/ # Zustand Stores - └── types/ # TypeScript 类型 + └── stores/ # Zustand Stores ``` ## 3. 路径别名 @@ -54,7 +55,7 @@ src/ | `@renderer/*` | `src/renderer/src/*` | | `@main/*` | `src/main/*` | | `@preload/*` | `src/preload/*` | - +| `@shared/*` | `src/shared/*` | ## 4. 代码风格 ### 导入顺序 diff --git a/src/main/ipc-handlers.ts b/src/main/ipc-handlers.ts index 9f3ed5f..9a0a2ec 100644 --- a/src/main/ipc-handlers.ts +++ b/src/main/ipc-handlers.ts @@ -11,16 +11,13 @@ import { getDomain, deleteDomain, listDomains, - saveVersion, listVersions, deleteVersion, saveDownload, saveBackup, - isSecureStorageAvailable, - getStorageBackend, } from "./storage"; -import { KintoneClient, KintoneError } from "./kintone-api"; -import type { Result } from "@renderer/types/ipc"; +import { KintoneClient, createKintoneClient } from "./kintone-api"; +import type { Result } from "@shared/types/ipc"; import type { CreateDomainParams, UpdateDomainParams, @@ -35,13 +32,13 @@ import type { DownloadResult, GetVersionsParams, RollbackParams, -} from "@renderer/types/ipc"; -import type { Domain, DomainWithStatus } from "@renderer/types/domain"; +} from "@shared/types/ipc"; +import type { Domain, DomainWithStatus, DomainWithPassword } from "@shared/types/domain"; import type { Version, DownloadMetadata, BackupMetadata, -} from "@renderer/types/version"; +} from "@shared/types/version"; // Cache for Kintone clients const clientCache = new Map(); @@ -59,7 +56,7 @@ async function getClient(domainId: string): Promise { throw new Error(`Domain not found: ${domainId}`); } - const client = new KintoneClient(domainWithPassword); + const client = createKintoneClient(domainWithPassword); clientCache.set(domainId, client); return client; } @@ -196,7 +193,7 @@ function registerTestConnection(): void { throw new Error(`Domain not found: ${id}`); } - const client = new KintoneClient(domainWithPassword); + const client = createKintoneClient(domainWithPassword); const result = await client.testConnection(); return { @@ -226,7 +223,7 @@ function registerTestDomainConnection(): void { updatedAt: new Date().toISOString(), }; - const client = new KintoneClient(tempDomain); + const client = createKintoneClient(tempDomain); const result = await client.testConnection(); if (!result.success) { diff --git a/src/main/kintone-api.ts b/src/main/kintone-api.ts index 18d9b79..a4934ca 100644 --- a/src/main/kintone-api.ts +++ b/src/main/kintone-api.ts @@ -1,6 +1,6 @@ import { KintoneRestAPIClient } from "@kintone/rest-api-client"; import type { KintoneRestAPIError } from "@kintone/rest-api-client"; -import type { DomainWithPassword } from "@renderer/types/domain"; +import type { DomainWithPassword } from "@shared/types/domain"; import type { KintoneSpace, KintoneApp, @@ -10,7 +10,7 @@ import type { KintoneApiError, JSFileConfig, CSSFileConfig, -} from "@renderer/types/kintone"; +} from "@shared/types/kintone"; /** * Custom error class for Kintone API errors diff --git a/src/main/storage.ts b/src/main/storage.ts index d56fd6d..2d6d531 100644 --- a/src/main/storage.ts +++ b/src/main/storage.ts @@ -7,12 +7,12 @@ import { app, safeStorage } from "electron"; import * as fs from "fs"; import * as path from "path"; -import type { Domain, DomainWithPassword } from "@renderer/types/domain"; +import type { Domain, DomainWithPassword } from "@shared/types/domain"; import type { Version, DownloadMetadata, BackupMetadata, -} from "@renderer/types/version"; +} from "@shared/types/version"; // ==================== Path Helpers ==================== diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index d411a8e..92fc6fa 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -14,15 +14,15 @@ import type { DownloadResult, GetVersionsParams, RollbackParams, -} from "@renderer/types/ipc"; -import type { Domain, DomainWithStatus } from "@renderer/types/domain"; +} from "@shared/types/ipc"; +import type { Domain, DomainWithStatus } from "@shared/types/domain"; import type { KintoneSpace, KintoneApp, AppDetail, FileContent, -} from "@renderer/types/kintone"; -import type { Version } from "@renderer/types/version"; +} from "@shared/types/kintone"; +import type { Version } from "@shared/types/version"; declare global { interface Window { diff --git a/src/renderer/src/components/DeployDialog/DeployDialog.tsx b/src/renderer/src/components/DeployDialog/DeployDialog.tsx index 208b484..c9fd1ff 100644 --- a/src/renderer/src/components/DeployDialog/DeployDialog.tsx +++ b/src/renderer/src/components/DeployDialog/DeployDialog.tsx @@ -29,7 +29,7 @@ import { FileUploader } from "../FileUploader"; import { useDeployStore } from "@renderer/stores"; import { useDomainStore } from "@renderer/stores"; import { useAppStore } from "@renderer/stores"; -import type { DeployFile } from "@renderer/types/ipc"; +import type { DeployFile } from "@shared/types/ipc"; const { Text } = Typography; diff --git a/src/renderer/src/components/DomainManager/DomainForm.tsx b/src/renderer/src/components/DomainManager/DomainForm.tsx index fe04f97..c4974b1 100644 --- a/src/renderer/src/components/DomainManager/DomainForm.tsx +++ b/src/renderer/src/components/DomainManager/DomainForm.tsx @@ -7,11 +7,10 @@ import React from "react"; import { Modal, Form, Input, Select, Button, Space, message } from "antd"; import { createStyles } from "antd-style"; import { useDomainStore } from "@renderer/stores"; -import type { Domain } from "@renderer/types/domain"; import type { CreateDomainParams, UpdateDomainParams, -} from "@renderer/types/ipc"; +} from "@shared/types/ipc"; const useStyles = createStyles(({ token, css }) => ({ form: css` @@ -184,6 +183,8 @@ const DomainForm: React.FC = ({ open, onClose, domainId }) => { > + + ({ item: css` diff --git a/src/renderer/src/components/FileUploader/FileUploader.tsx b/src/renderer/src/components/FileUploader/FileUploader.tsx index 15d6121..1a7461b 100644 --- a/src/renderer/src/components/FileUploader/FileUploader.tsx +++ b/src/renderer/src/components/FileUploader/FileUploader.tsx @@ -14,7 +14,7 @@ import { } from "@ant-design/icons"; import { createStyles } from "antd-style"; import type { UploadFile, UploadProps } from "antd"; -import type { DeployFile } from "@renderer/types/ipc"; +import type { DeployFile } from "@shared/types/ipc"; const { Dragger } = Upload; diff --git a/src/renderer/src/components/SpaceTree/SpaceTree.tsx b/src/renderer/src/components/SpaceTree/SpaceTree.tsx index ef0f07f..b673499 100644 --- a/src/renderer/src/components/SpaceTree/SpaceTree.tsx +++ b/src/renderer/src/components/SpaceTree/SpaceTree.tsx @@ -14,7 +14,7 @@ import { createStyles } from "antd-style"; import type { TreeDataNode, TreeProps } from "antd"; import { useAppStore } from "@renderer/stores"; import { useDomainStore } from "@renderer/stores"; -import type { KintoneSpace, KintoneApp } from "@renderer/types/kintone"; +import type { KintoneSpace, KintoneApp } from "@shared/types/kintone"; const useStyles = createStyles(({ token, css }) => ({ container: css` diff --git a/src/renderer/src/components/VersionHistory/VersionHistory.tsx b/src/renderer/src/components/VersionHistory/VersionHistory.tsx index 6553590..20f3de6 100644 --- a/src/renderer/src/components/VersionHistory/VersionHistory.tsx +++ b/src/renderer/src/components/VersionHistory/VersionHistory.tsx @@ -29,7 +29,7 @@ import { createStyles } from "antd-style"; import { useVersionStore } from "@renderer/stores"; import { useDomainStore } from "@renderer/stores"; import { useAppStore } from "@renderer/stores"; -import type { Version } from "@renderer/types/version"; +import type { Version } from "@shared/types/version"; const { Text } = Typography; diff --git a/src/renderer/src/stores/appStore.ts b/src/renderer/src/stores/appStore.ts index c286ded..6f998ef 100644 --- a/src/renderer/src/stores/appStore.ts +++ b/src/renderer/src/stores/appStore.ts @@ -8,7 +8,7 @@ import type { KintoneSpace, KintoneApp, AppDetail, -} from "@renderer/types/kintone"; +} from "@shared/types/kintone"; interface AppState { // State diff --git a/src/renderer/src/stores/deployStore.ts b/src/renderer/src/stores/deployStore.ts index 0d9f09d..5e1c623 100644 --- a/src/renderer/src/stores/deployStore.ts +++ b/src/renderer/src/stores/deployStore.ts @@ -4,7 +4,7 @@ */ import { create } from "zustand"; -import type { DeployFile, DeployResult } from "@renderer/types/ipc"; +import type { DeployFile, DeployResult } from "@shared/types/ipc"; export type DeployStep = | "select" diff --git a/src/renderer/src/stores/domainStore.ts b/src/renderer/src/stores/domainStore.ts index 9e1d0bc..089070a 100644 --- a/src/renderer/src/stores/domainStore.ts +++ b/src/renderer/src/stores/domainStore.ts @@ -5,12 +5,12 @@ import { create } from "zustand"; import { persist } from "zustand/middleware"; -import type { Domain, DomainWithStatus } from "@renderer/types/domain"; -import type { ConnectionStatus } from "@renderer/types/domain"; +import type { Domain, DomainWithStatus } from "@shared/types/domain"; +import type { ConnectionStatus } from "@shared/types/domain"; import type { CreateDomainParams, UpdateDomainParams, -} from "@renderer/types/ipc"; +} from "@shared/types/ipc"; interface DomainState { // State diff --git a/src/renderer/src/stores/versionStore.ts b/src/renderer/src/stores/versionStore.ts index 32d2dd0..fdf5a2a 100644 --- a/src/renderer/src/stores/versionStore.ts +++ b/src/renderer/src/stores/versionStore.ts @@ -4,7 +4,7 @@ */ import { create } from "zustand"; -import type { Version } from "@renderer/types/version"; +import type { Version } from "@shared/types/version"; interface VersionState { // State diff --git a/src/renderer/src/types/domain.ts b/src/shared/types/domain.ts similarity index 100% rename from src/renderer/src/types/domain.ts rename to src/shared/types/domain.ts diff --git a/src/renderer/src/types/index.ts b/src/shared/types/index.ts similarity index 100% rename from src/renderer/src/types/index.ts rename to src/shared/types/index.ts diff --git a/src/renderer/src/types/ipc.ts b/src/shared/types/ipc.ts similarity index 100% rename from src/renderer/src/types/ipc.ts rename to src/shared/types/ipc.ts diff --git a/src/renderer/src/types/kintone.ts b/src/shared/types/kintone.ts similarity index 100% rename from src/renderer/src/types/kintone.ts rename to src/shared/types/kintone.ts diff --git a/src/renderer/src/types/version.ts b/src/shared/types/version.ts similarity index 100% rename from src/renderer/src/types/version.ts rename to src/shared/types/version.ts diff --git a/tsconfig.node.json b/tsconfig.node.json index 48134a3..19f12f9 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -5,6 +5,7 @@ "src/main/**/*", "src/preload/**/*", "src/renderer/**/*", + "src/shared/**/*" ], "compilerOptions": { "composite": true, @@ -13,7 +14,8 @@ "paths": { "@main/*": ["src/main/*"], "@preload/*": ["src/preload/*"], - "@renderer/*": ["src/renderer/src/*"] + "@renderer/*": ["src/renderer/src/*"], + "@shared/*": ["src/shared/*"] } } } diff --git a/tsconfig.web.json b/tsconfig.web.json index 3340ae6..b1c99d3 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -1,13 +1,12 @@ { "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", - "include": [ - "src/renderer/src/**/*" - ], + "include": ["src/renderer/src/**/*", "src/shared/**/*"], "compilerOptions": { "composite": true, "baseUrl": ".", "paths": { - "@renderer/*": ["src/renderer/src/*"] + "@renderer/*": ["src/renderer/src/*"], + "@shared/*": ["src/shared/*"] } } -} \ No newline at end of file +}