refactor(types): move shared types from renderer to shared directory
- Move type definitions from src/renderer/src/types/ to src/shared/types/ - Add @shared/* path alias to tsconfig.node.json and tsconfig.web.json - Update all imports from @renderer/types/* to @shared/types/* - Update AGENTS.md with new directory structure and path alias This fixes architecture violation where main/preload processes imported from renderer directory. Types are now properly shared across all processes.
This commit is contained in:
@@ -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. 代码风格
|
||||
|
||||
### 导入顺序
|
||||
|
||||
@@ -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<string, KintoneClient>();
|
||||
@@ -59,7 +56,7 @@ async function getClient(domainId: string): Promise<KintoneClient> {
|
||||
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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ====================
|
||||
|
||||
|
||||
8
src/preload/index.d.ts
vendored
8
src/preload/index.d.ts
vendored
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<DomainFormProps> = ({ open, onClose, domainId }) => {
|
||||
>
|
||||
<Form.Item name="name" label="名称" style={{ marginTop: 8 }}>
|
||||
<Input placeholder="可选,留空则使用域名" />
|
||||
</Form.Item>
|
||||
|
||||
|
||||
<Form.Item
|
||||
name="domain"
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from "@ant-design/icons";
|
||||
import { createStyles } from "antd-style";
|
||||
import { useDomainStore } from "@renderer/stores";
|
||||
import type { Domain } from "@renderer/types/domain";
|
||||
import type { Domain } from "@shared/types/domain";
|
||||
|
||||
const useStyles = createStyles(({ token, css }) => ({
|
||||
item: css`
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
KintoneSpace,
|
||||
KintoneApp,
|
||||
AppDetail,
|
||||
} from "@renderer/types/kintone";
|
||||
} from "@shared/types/kintone";
|
||||
|
||||
interface AppState {
|
||||
// State
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/*"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user