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 脚本
|
├── preload/ # Preload 脚本
|
||||||
│ ├── index.ts # 暴露 API 到渲染进程
|
│ ├── index.ts # 暴露 API 到渲染进程
|
||||||
│ └── index.d.ts # 类型声明
|
│ └── index.d.ts # 类型声明
|
||||||
|
├── shared/ # 跨进程共享代码
|
||||||
|
│ └── types/ # 共享类型定义
|
||||||
└── renderer/ # React 渲染进程
|
└── renderer/ # React 渲染进程
|
||||||
└── src/
|
└── src/
|
||||||
├── main.tsx # React 入口
|
├── main.tsx # React 入口
|
||||||
├── App.tsx # 根组件
|
├── App.tsx # 根组件
|
||||||
├── components/ # React 组件
|
├── components/ # React 组件
|
||||||
├── stores/ # Zustand Stores
|
└── stores/ # Zustand Stores
|
||||||
└── types/ # TypeScript 类型
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 3. 路径别名
|
## 3. 路径别名
|
||||||
@@ -54,7 +55,7 @@ src/
|
|||||||
| `@renderer/*` | `src/renderer/src/*` |
|
| `@renderer/*` | `src/renderer/src/*` |
|
||||||
| `@main/*` | `src/main/*` |
|
| `@main/*` | `src/main/*` |
|
||||||
| `@preload/*` | `src/preload/*` |
|
| `@preload/*` | `src/preload/*` |
|
||||||
|
| `@shared/*` | `src/shared/*` |
|
||||||
## 4. 代码风格
|
## 4. 代码风格
|
||||||
|
|
||||||
### 导入顺序
|
### 导入顺序
|
||||||
|
|||||||
@@ -11,16 +11,13 @@ import {
|
|||||||
getDomain,
|
getDomain,
|
||||||
deleteDomain,
|
deleteDomain,
|
||||||
listDomains,
|
listDomains,
|
||||||
saveVersion,
|
|
||||||
listVersions,
|
listVersions,
|
||||||
deleteVersion,
|
deleteVersion,
|
||||||
saveDownload,
|
saveDownload,
|
||||||
saveBackup,
|
saveBackup,
|
||||||
isSecureStorageAvailable,
|
|
||||||
getStorageBackend,
|
|
||||||
} from "./storage";
|
} from "./storage";
|
||||||
import { KintoneClient, KintoneError } from "./kintone-api";
|
import { KintoneClient, createKintoneClient } from "./kintone-api";
|
||||||
import type { Result } from "@renderer/types/ipc";
|
import type { Result } from "@shared/types/ipc";
|
||||||
import type {
|
import type {
|
||||||
CreateDomainParams,
|
CreateDomainParams,
|
||||||
UpdateDomainParams,
|
UpdateDomainParams,
|
||||||
@@ -35,13 +32,13 @@ import type {
|
|||||||
DownloadResult,
|
DownloadResult,
|
||||||
GetVersionsParams,
|
GetVersionsParams,
|
||||||
RollbackParams,
|
RollbackParams,
|
||||||
} from "@renderer/types/ipc";
|
} from "@shared/types/ipc";
|
||||||
import type { Domain, DomainWithStatus } from "@renderer/types/domain";
|
import type { Domain, DomainWithStatus, DomainWithPassword } from "@shared/types/domain";
|
||||||
import type {
|
import type {
|
||||||
Version,
|
Version,
|
||||||
DownloadMetadata,
|
DownloadMetadata,
|
||||||
BackupMetadata,
|
BackupMetadata,
|
||||||
} from "@renderer/types/version";
|
} from "@shared/types/version";
|
||||||
|
|
||||||
// Cache for Kintone clients
|
// Cache for Kintone clients
|
||||||
const clientCache = new Map<string, KintoneClient>();
|
const clientCache = new Map<string, KintoneClient>();
|
||||||
@@ -59,7 +56,7 @@ async function getClient(domainId: string): Promise<KintoneClient> {
|
|||||||
throw new Error(`Domain not found: ${domainId}`);
|
throw new Error(`Domain not found: ${domainId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new KintoneClient(domainWithPassword);
|
const client = createKintoneClient(domainWithPassword);
|
||||||
clientCache.set(domainId, client);
|
clientCache.set(domainId, client);
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
@@ -196,7 +193,7 @@ function registerTestConnection(): void {
|
|||||||
throw new Error(`Domain not found: ${id}`);
|
throw new Error(`Domain not found: ${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new KintoneClient(domainWithPassword);
|
const client = createKintoneClient(domainWithPassword);
|
||||||
const result = await client.testConnection();
|
const result = await client.testConnection();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -226,7 +223,7 @@ function registerTestDomainConnection(): void {
|
|||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const client = new KintoneClient(tempDomain);
|
const client = createKintoneClient(tempDomain);
|
||||||
const result = await client.testConnection();
|
const result = await client.testConnection();
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
import { KintoneRestAPIClient } from "@kintone/rest-api-client";
|
||||||
import type { KintoneRestAPIError } 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 {
|
import type {
|
||||||
KintoneSpace,
|
KintoneSpace,
|
||||||
KintoneApp,
|
KintoneApp,
|
||||||
@@ -10,7 +10,7 @@ import type {
|
|||||||
KintoneApiError,
|
KintoneApiError,
|
||||||
JSFileConfig,
|
JSFileConfig,
|
||||||
CSSFileConfig,
|
CSSFileConfig,
|
||||||
} from "@renderer/types/kintone";
|
} from "@shared/types/kintone";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom error class for Kintone API errors
|
* Custom error class for Kintone API errors
|
||||||
|
|||||||
@@ -7,12 +7,12 @@
|
|||||||
import { app, safeStorage } from "electron";
|
import { app, safeStorage } from "electron";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import type { Domain, DomainWithPassword } from "@renderer/types/domain";
|
import type { Domain, DomainWithPassword } from "@shared/types/domain";
|
||||||
import type {
|
import type {
|
||||||
Version,
|
Version,
|
||||||
DownloadMetadata,
|
DownloadMetadata,
|
||||||
BackupMetadata,
|
BackupMetadata,
|
||||||
} from "@renderer/types/version";
|
} from "@shared/types/version";
|
||||||
|
|
||||||
// ==================== Path Helpers ====================
|
// ==================== Path Helpers ====================
|
||||||
|
|
||||||
|
|||||||
8
src/preload/index.d.ts
vendored
8
src/preload/index.d.ts
vendored
@@ -14,15 +14,15 @@ import type {
|
|||||||
DownloadResult,
|
DownloadResult,
|
||||||
GetVersionsParams,
|
GetVersionsParams,
|
||||||
RollbackParams,
|
RollbackParams,
|
||||||
} from "@renderer/types/ipc";
|
} from "@shared/types/ipc";
|
||||||
import type { Domain, DomainWithStatus } from "@renderer/types/domain";
|
import type { Domain, DomainWithStatus } from "@shared/types/domain";
|
||||||
import type {
|
import type {
|
||||||
KintoneSpace,
|
KintoneSpace,
|
||||||
KintoneApp,
|
KintoneApp,
|
||||||
AppDetail,
|
AppDetail,
|
||||||
FileContent,
|
FileContent,
|
||||||
} from "@renderer/types/kintone";
|
} from "@shared/types/kintone";
|
||||||
import type { Version } from "@renderer/types/version";
|
import type { Version } from "@shared/types/version";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { FileUploader } from "../FileUploader";
|
|||||||
import { useDeployStore } from "@renderer/stores";
|
import { useDeployStore } from "@renderer/stores";
|
||||||
import { useDomainStore } from "@renderer/stores";
|
import { useDomainStore } from "@renderer/stores";
|
||||||
import { useAppStore } 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;
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ import React from "react";
|
|||||||
import { Modal, Form, Input, Select, Button, Space, message } from "antd";
|
import { Modal, Form, Input, Select, Button, Space, message } from "antd";
|
||||||
import { createStyles } from "antd-style";
|
import { createStyles } from "antd-style";
|
||||||
import { useDomainStore } from "@renderer/stores";
|
import { useDomainStore } from "@renderer/stores";
|
||||||
import type { Domain } from "@renderer/types/domain";
|
|
||||||
import type {
|
import type {
|
||||||
CreateDomainParams,
|
CreateDomainParams,
|
||||||
UpdateDomainParams,
|
UpdateDomainParams,
|
||||||
} from "@renderer/types/ipc";
|
} from "@shared/types/ipc";
|
||||||
|
|
||||||
const useStyles = createStyles(({ token, css }) => ({
|
const useStyles = createStyles(({ token, css }) => ({
|
||||||
form: css`
|
form: css`
|
||||||
@@ -184,6 +183,8 @@ const DomainForm: React.FC<DomainFormProps> = ({ open, onClose, domainId }) => {
|
|||||||
>
|
>
|
||||||
<Form.Item name="name" label="名称" style={{ marginTop: 8 }}>
|
<Form.Item name="name" label="名称" style={{ marginTop: 8 }}>
|
||||||
<Input placeholder="可选,留空则使用域名" />
|
<Input placeholder="可选,留空则使用域名" />
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="domain"
|
name="domain"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { createStyles } from "antd-style";
|
import { createStyles } from "antd-style";
|
||||||
import { useDomainStore } from "@renderer/stores";
|
import { useDomainStore } from "@renderer/stores";
|
||||||
import type { Domain } from "@renderer/types/domain";
|
import type { Domain } from "@shared/types/domain";
|
||||||
|
|
||||||
const useStyles = createStyles(({ token, css }) => ({
|
const useStyles = createStyles(({ token, css }) => ({
|
||||||
item: css`
|
item: css`
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
import { createStyles } from "antd-style";
|
import { createStyles } from "antd-style";
|
||||||
import type { UploadFile, UploadProps } from "antd";
|
import type { UploadFile, UploadProps } from "antd";
|
||||||
import type { DeployFile } from "@renderer/types/ipc";
|
import type { DeployFile } from "@shared/types/ipc";
|
||||||
|
|
||||||
const { Dragger } = Upload;
|
const { Dragger } = Upload;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { createStyles } from "antd-style";
|
|||||||
import type { TreeDataNode, TreeProps } from "antd";
|
import type { TreeDataNode, TreeProps } from "antd";
|
||||||
import { useAppStore } from "@renderer/stores";
|
import { useAppStore } from "@renderer/stores";
|
||||||
import { useDomainStore } 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 }) => ({
|
const useStyles = createStyles(({ token, css }) => ({
|
||||||
container: css`
|
container: css`
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import { createStyles } from "antd-style";
|
|||||||
import { useVersionStore } from "@renderer/stores";
|
import { useVersionStore } from "@renderer/stores";
|
||||||
import { useDomainStore } from "@renderer/stores";
|
import { useDomainStore } from "@renderer/stores";
|
||||||
import { useAppStore } 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;
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import type {
|
|||||||
KintoneSpace,
|
KintoneSpace,
|
||||||
KintoneApp,
|
KintoneApp,
|
||||||
AppDetail,
|
AppDetail,
|
||||||
} from "@renderer/types/kintone";
|
} from "@shared/types/kintone";
|
||||||
|
|
||||||
interface AppState {
|
interface AppState {
|
||||||
// State
|
// State
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import type { DeployFile, DeployResult } from "@renderer/types/ipc";
|
import type { DeployFile, DeployResult } from "@shared/types/ipc";
|
||||||
|
|
||||||
export type DeployStep =
|
export type DeployStep =
|
||||||
| "select"
|
| "select"
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import { persist } from "zustand/middleware";
|
import { persist } from "zustand/middleware";
|
||||||
import type { Domain, DomainWithStatus } from "@renderer/types/domain";
|
import type { Domain, DomainWithStatus } from "@shared/types/domain";
|
||||||
import type { ConnectionStatus } from "@renderer/types/domain";
|
import type { ConnectionStatus } from "@shared/types/domain";
|
||||||
import type {
|
import type {
|
||||||
CreateDomainParams,
|
CreateDomainParams,
|
||||||
UpdateDomainParams,
|
UpdateDomainParams,
|
||||||
} from "@renderer/types/ipc";
|
} from "@shared/types/ipc";
|
||||||
|
|
||||||
interface DomainState {
|
interface DomainState {
|
||||||
// State
|
// State
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
import type { Version } from "@renderer/types/version";
|
import type { Version } from "@shared/types/version";
|
||||||
|
|
||||||
interface VersionState {
|
interface VersionState {
|
||||||
// State
|
// State
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"src/main/**/*",
|
"src/main/**/*",
|
||||||
"src/preload/**/*",
|
"src/preload/**/*",
|
||||||
"src/renderer/**/*",
|
"src/renderer/**/*",
|
||||||
|
"src/shared/**/*"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
@@ -13,7 +14,8 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@main/*": ["src/main/*"],
|
"@main/*": ["src/main/*"],
|
||||||
"@preload/*": ["src/preload/*"],
|
"@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",
|
"extends": "@electron-toolkit/tsconfig/tsconfig.web.json",
|
||||||
"include": [
|
"include": ["src/renderer/src/**/*", "src/shared/**/*"],
|
||||||
"src/renderer/src/**/*"
|
|
||||||
],
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@renderer/*": ["src/renderer/src/*"]
|
"@renderer/*": ["src/renderer/src/*"],
|
||||||
|
"@shared/*": ["src/shared/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user