diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a3e9ade4..42e027858 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,25 +28,43 @@ jobs: platform: win-arm64 steps: - uses: actions/checkout@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '22' + node-version: '22.13.1' + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 10.12.1 + - name: Install dependencies - run: npm install + run: pnpm install + + - name: Configure pnpm workspace for Windows ${{ matrix.arch }} + run: pnpm run install:sharp env: + TARGET_OS: win32 + TARGET_ARCH: ${{ matrix.arch }} + + - name: Install dependencies + run: pnpm install + env: + npm_config_build_from_source: true npm_config_platform: win32 npm_config_arch: ${{ matrix.arch }} + - name: Install Node Runtime - run: npm run installRuntime:win:${{ matrix.arch }} - - name: Install Sharp - run: npm install sharp --build-from-source + run: pnpm run installRuntime:win:${{ matrix.arch }} + - name: Build Windows - run: npm run build:win:${{ matrix.arch }} + run: pnpm run build:win:${{ matrix.arch }} env: VITE_GITHUB_CLIENT_ID: ${{ secrets.DC_GITHUB_CLIENT_ID }} VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }} VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }} + - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -67,25 +85,39 @@ jobs: platform: linux-x64 steps: - uses: actions/checkout@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '22' + node-version: '22.13.1' + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 10.12.1 + - name: Install dependencies - run: npm install + run: pnpm install + + - name: Configure pnpm workspace for Linux ${{ matrix.arch }} + run: pnpm run install:sharp env: - npm_config_platform: linux - npm_config_arch: ${{ matrix.arch }} + TARGET_OS: linux + TARGET_ARCH: ${{ matrix.arch }} + + - name: Install dependencies + run: pnpm install + - name: Install Node Runtime - run: npm run installRuntime:linux:${{ matrix.arch }} - - name: Install Sharp - run: npm install --cpu=wasm32 sharp + run: pnpm run installRuntime:linux:${{ matrix.arch }} + - name: Build Linux - run: npm run build:linux:${{ matrix.arch }} + run: pnpm run build:linux:${{ matrix.arch }} env: VITE_GITHUB_CLIENT_ID: ${{ secrets.DC_GITHUB_CLIENT_ID }} VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }} VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }} + - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -107,21 +139,34 @@ jobs: platform: mac-arm64 steps: - uses: actions/checkout@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '22' + node-version: '22.13.1' + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 10.12.1 + - name: Install dependencies - run: npm install + run: pnpm install + + - name: Configure pnpm workspace for macOS ${{ matrix.arch }} + run: pnpm run install:sharp env: - npm_config_platform: darwin - npm_config_arch: ${{ matrix.arch }} + TARGET_OS: darwin + TARGET_ARCH: ${{ matrix.arch }} + + - name: Install dependencies + run: pnpm install + - name: Install Node Runtime - run: npm run installRuntime:mac:${{ matrix.arch }} - - name: Install Sharp - run: npm i --cpu=${{ matrix.arch }} --os=darwin sharp + run: pnpm run installRuntime:mac:${{ matrix.arch }} + - name: Build Mac - run: npm run build:mac:${{ matrix.arch }} + run: pnpm run build:mac:${{ matrix.arch }} env: CSC_LINK: ${{ secrets.DEEPCHAT_CSC_LINK }} CSC_KEY_PASSWORD: ${{ secrets.DEEPCHAT_CSC_KEY_PASS }} @@ -133,6 +178,7 @@ jobs: VITE_GITHUB_CLIENT_SECRET: ${{ secrets.DC_GITHUB_CLIENT_SECRET }} VITE_GITHUB_REDIRECT_URI: ${{ secrets.DC_GITHUB_REDIRECT_URI }} NODE_OPTIONS: '--max-old-space-size=4096' + - name: Upload artifacts uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/prcheck.yml b/.github/workflows/prcheck.yml index affe0c5e5..1e78197d1 100644 --- a/.github/workflows/prcheck.yml +++ b/.github/workflows/prcheck.yml @@ -16,20 +16,34 @@ jobs: - arch: x64 steps: - uses: actions/checkout@v4 + - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '22' - - name: Check Lint - run: npm run lint + node-version: '22.13.1' + + - name: Setup pnpm + uses: pnpm/action-setup@v2 + with: + version: 10.12.1 + - name: Install dependencies - run: npm install + run: pnpm install + + - name: Configure pnpm workspace for Linux ${{ matrix.arch }} + run: pnpm run install:sharp env: - npm_config_platform: linux - npm_config_arch: ${{ matrix.arch }} - - name: Install Sharp - run: npm install --cpu=wasm32 sharp + TARGET_OS: linux + TARGET_ARCH: ${{ matrix.arch }} + + - name: Install dependencies + run: pnpm install + + - name: Check Lint + run: pnpm run lint + - name: Check translations - run: npm run i18n && npm run i18n:en + run: pnpm run i18n + - name: Build - run: npm run build \ No newline at end of file + run: pnpm run build \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 38a758637..abb95362f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ We use GitHub to host code, to track issues and feature requests, as well as acc - Code submitted to the `dev` branch must ensure: - Basic functionality works - No compilation errors - - Project can start normally with `npm run dev` + - Project can start normally with `pnpm run dev` #### Major Features or Refactoring @@ -84,12 +84,13 @@ We use GitHub to host code, to track issues and feature requests, as well as acc 4. Install project dependencies: ```bash - npm install + pnpm install + pnpm run installRuntime ``` 5. Start the development server: ```bash - npm run dev + pnpm run dev ``` ## Project Structure @@ -109,8 +110,9 @@ We use GitHub to host code, to track issues and feature requests, as well as acc Please ensure your code follows our style guidelines by running: ```bash -npm run build -npm run i18n +pnpm run lint +pnpm run build +pnpm run i18n ``` ## Pull Request Process diff --git a/CONTRIBUTING.zh.md b/CONTRIBUTING.zh.md index 7cb70642a..395b10e24 100644 --- a/CONTRIBUTING.zh.md +++ b/CONTRIBUTING.zh.md @@ -20,7 +20,7 @@ - 提交到 `dev` 分支的代码必须确保: - 功能基本正常 - 无编译错误 - - 至少能够 `npm run dev` 正常启动 + - 至少能够 `pnpm run dev` 正常启动 #### 大型功能新增或重构 @@ -84,13 +84,13 @@ 4. 安装项目依赖: ```bash - npm install - npm run installRuntime + pnpm install + pnpm run installRuntime ``` 5. 启动开发服务器: ```bash -npm run dev +pnpm run dev ``` ## 项目结构 @@ -110,8 +110,9 @@ npm run dev 请确保您的代码符合我们的代码风格指南,可以运行以下命令: ```bash -npm run build -npm run i18n +pnpm run lint +pnpm run i18n +pnpm run build ``` ## Pull Request 流程 diff --git a/README.jp.md b/README.jp.md index 5554a8ab0..51553ab04 100644 --- a/README.jp.md +++ b/README.jp.md @@ -259,45 +259,37 @@ Mac関連の署名とパッケージングについては、[Mac リリースガ ### 依存関係のインストール ```bash -$ npm install -$ npm run installRuntime +$ pnpm install +$ pnpm run installRuntime # エラーが出た場合: No module named 'distutils' $ pip install setuptools -# Windows x64の場合 -$ npm install --cpu=x64 --os=win32 sharp -# Mac Apple Siliconの場合 -$ npm install --cpu=arm64 --os=darwin sharp -# Mac Intelの場合 -$ npm install --cpu=x64 --os=darwin sharp -# Linux x64の場合 -$ npm install --cpu=x64 --os=linux sharp ``` ### 開発を開始 ```bash -$ npm run dev +$ pnpm run dev ``` ### ビルド ```bash # Windowsの場合 -$ npm run build:win +$ pnpm run build:win # macOSの場合 -$ npm run build:mac +$ pnpm run build:mac # Linuxの場合 -$ npm run build:linux +$ pnpm run build:linux # アーキテクチャを指定してパッケージング -$ npm run build:win:x64 -$ npm run build:win:arm64 -$ npm run build:mac:x64 -$ npm run build:mac:arm64 -$ npm run build:linux:x64 -$ npm run build:linux:arm64 +$ pnpm run build:win:x64 +$ pnpm run build:win:arm64 +$ pnpm run build:mac:x64 +$ pnpm run build:mac:arm64 +$ pnpm run build:linux:x64 +$ pnpm run build:linux:arm64 ``` ## 👥 コミュニティと貢献 diff --git a/README.md b/README.md index 85eab2456..bb61e955b 100644 --- a/README.md +++ b/README.md @@ -263,45 +263,37 @@ For Mac-related signing and packaging, please refer to the [Mac Release Guide](h ### Install Dependencies ```bash -$ npm install -$ npm run installRuntime +$ pnpm install +$ pnpm run installRuntime # if got err: No module named 'distutils' $ pip install setuptools -# for windows x64 -$ npm install --cpu=x64 --os=win32 sharp -# for mac apple silicon -$ npm install --cpu=arm64 --os=darwin sharp -# for mac intel -$ npm install --cpu=x64 --os=darwin sharp -# for linux x64 -$ npm install --cpu=x64 --os=linux sharp ``` ### Start Development ```bash -$ npm run dev +$ pnpm run dev ``` ### Build ```bash # For Windows -$ npm run build:win +$ pnpm run build:win # For macOS -$ npm run build:mac +$ pnpm run build:mac # For Linux -$ npm run build:linux +$ pnpm run build:linux # Specify architecture packaging -$ npm run build:win:x64 -$ npm run build:win:arm64 -$ npm run build:mac:x64 -$ npm run build:mac:arm64 -$ npm run build:linux:x64 -$ npm run build:linux:arm64 +$ pnpm run build:win:x64 +$ pnpm run build:win:arm64 +$ pnpm run build:mac:x64 +$ pnpm run build:mac:arm64 +$ pnpm run build:linux:x64 +$ pnpm run build:linux:arm64 ``` For a more detailed guide on development, project structure, and architecture, please see the [Developer Guide](./docs/developer-guide.md). diff --git a/README.zh.md b/README.zh.md index 23c5b1765..0aed71819 100644 --- a/README.zh.md +++ b/README.zh.md @@ -259,45 +259,37 @@ Windows和Linux通过GitHub Action打包。 ### 安装依赖 ```bash -$ npm install -$ npm run installRuntime +$ pnpm install +$ pnpm run installRuntime # 如果出现错误:No module named 'distutils' $ pip install setuptools -# 对于Windows x64 -$ npm install --cpu=x64 --os=win32 sharp -# 对于Mac Apple Silicon -$ npm install --cpu=arm64 --os=darwin sharp -# 对于Mac Intel -$ npm install --cpu=x64 --os=darwin sharp -# 对于Linux x64 -$ npm install --cpu=x64 --os=linux sharp ``` ### 开始开发 ```bash -$ npm run dev +$ pnpm run dev ``` ### 构建 ```bash # Windows -$ npm run build:win +$ pnpm run build:win # macOS -$ npm run build:mac +$ pnpm run build:mac # Linux -$ npm run build:linux +$ pnpm run build:linux # 指定架构打包 -$ npm run build:win:x64 -$ npm run build:win:arm64 -$ npm run build:mac:x64 -$ npm run build:mac:arm64 -$ npm run build:linux:x64 -$ npm run build:linux:arm64 +$ pnpm run build:win:x64 +$ pnpm run build:win:arm64 +$ pnpm run build:mac:x64 +$ pnpm run build:mac:arm64 +$ pnpm run build:linux:x64 +$ pnpm run build:linux:arm64 ``` ## 👥 社区与贡献 diff --git a/package.json b/package.json index dd922ed06..a5b3b0986 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,13 @@ "main": "./out/main/index.js", "author": "ThinkInAIXYZ", "type": "module", + "engines": { + "node": ">=20.12.2", + "pnpm": ">=10.11.0" + }, + "packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac", "scripts": { + "preinstall": "npx only-allow pnpm", "test": "vitest", "test:main": "vitest --config vitest.config.ts test/main", "test:renderer": "vitest --config vitest.config.renderer.ts test/renderer", @@ -16,23 +22,24 @@ "lint": "npx -y oxlint .", "typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false", "typecheck:web": "vue-tsc --noEmit -p tsconfig.web.json --composite false", - "typecheck": "npm run typecheck:node && npm run typecheck:web", + "typecheck": "pnpm run typecheck:node && pnpm run typecheck:web", "start": "electron-vite preview", "dev": "electron-vite dev --watch", "dev:inspect": "electron-vite dev --watch --inspect=9229", "dev:linux": "electron-vite dev --watch --noSandbox", - "build": "npm run typecheck && electron-vite build", + "build": "pnpm run typecheck && electron-vite build", "postinstall": "node scripts/postinstall.js && electron-builder install-app-deps", - "build:unpack": "npm run build && electron-builder --dir", - "build:win": "npm run build && electron-builder --win", - "build:win:x64": "npm run build && electron-builder --win --x64", - "build:win:arm64": "npm run build && electron-builder --win --arm64", - "build:mac": "npm run build && electron-builder --mac", - "build:mac:arm64": "npm run build && electron-builder --mac --arm64", - "build:mac:x64": "npm run build && electron-builder -c electron-builder-macx64.yml --mac --x64 ", - "build:linux": "npm run build && electron-builder --linux", - "build:linux:x64": "npm run build && electron-builder --linux --x64", - "build:linux:arm64": "npm run build && electron-builder --linux --arm64", + "build:unpack": "pnpm run build && electron-builder --dir", + "build:win": "pnpm run build && electron-builder --win", + "build:win:x64": "pnpm run build && electron-builder --win --x64", + "build:win:arm64": "pnpm run build && electron-builder --win --arm64", + "install:sharp": "node scripts/install-sharp-for-platform.js", + "build:mac": "pnpm run build && electron-builder --mac", + "build:mac:arm64": "pnpm run build && electron-builder --mac --arm64", + "build:mac:x64": "pnpm run build && electron-builder -c electron-builder-macx64.yml --mac --x64 ", + "build:linux": "pnpm run build && electron-builder --linux", + "build:linux:x64": "pnpm run build && electron-builder --linux --x64", + "build:linux:arm64": "pnpm run build && electron-builder --linux --arm64", "afterSign": "scripts/notarize.js", "installRuntime": "tiny-runtime-injector -d runtime/node -n v22.15.0 --no-docs --no-dev --no-sourcemaps", "installRuntime:win:x64": "tiny-runtime-injector -d runtime/node -n v22.15.0 -a x64 -p win32 --no-docs --no-dev --no-sourcemaps", @@ -103,8 +110,6 @@ "@tiptap/suggestion": "^2.11.7", "@tiptap/vue-3": "^2.11.7", "@types/better-sqlite3": "^7.6.0", - "@types/dompurify": "^3.0.5", - "@types/mermaid": "^9.1.0", "@types/node": "^22.14.1", "@types/xlsx": "^0.0.35", "@vitejs/plugin-vue": "^5.2.3", @@ -146,11 +151,15 @@ "vue-use-monaco": "^0.0.6", "vue-virtual-scroller": "^2.0.0-beta.8", "vuedraggable": "^4.1.0", + "yaml": "^2.8.0", "zod-to-json-schema": "^3.24.5" }, "pnpm": { "onlyBuiltDependencies": [ - "electron" + "@tailwindcss/oxide", + "electron", + "electron-winstaller", + "lzo" ], "ignoredBuiltDependencies": [ "better-sqlite3-multiple-ciphers", diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml new file mode 100644 index 000000000..fec0b8aca --- /dev/null +++ b/pnpm-workspace.yaml @@ -0,0 +1,5 @@ +supportedArchitectures: + os: + - current + cpu: + - current diff --git a/scripts/install-sharp-for-platform.js b/scripts/install-sharp-for-platform.js new file mode 100644 index 000000000..8d73a46e1 --- /dev/null +++ b/scripts/install-sharp-for-platform.js @@ -0,0 +1,95 @@ +#!/usr/bin/env node + +/** + * Update pnpm-workspace.yaml supportedArchitectures for different platforms + * 根据不同平台动态修改 pnpm-workspace.yaml 的 supportedArchitectures 配置 + */ + +import { readFileSync, writeFileSync, existsSync } from 'fs'; +import { platform, arch } from 'os'; +import YAML from 'yaml'; + +// Get platform info from environment or system +const targetOS = process.env.TARGET_OS || process.env.npm_config_os || platform(); +const targetArch = process.env.TARGET_ARCH || process.env.npm_config_arch || arch(); + +console.log(`🎯 Configuring pnpm workspace for platform: ${targetOS}-${targetArch}`); + +// Define platform-specific configurations +const platformConfigs = { + 'win32-x64': { + os: ['current', 'win32'], + cpu: ['current', 'x64'] + }, + 'win32-arm64': { + os: ['current', 'win32'], + cpu: ['current', 'arm64'] + }, + 'linux-x64': { + os: ['current', 'linux'], + cpu: ['current', 'wasm32'], // Include wasm32 for Sharp WebAssembly + }, + 'linux-arm64': { + os: ['current','linux'], + cpu: ['current', 'wasm32'], + }, + 'darwin-x64': { + os: ['current', 'darwin'], + cpu: ['current', 'x64'], + }, + 'darwin-arm64': { + os: ['current', 'darwin'], + cpu: ['current', 'arm64'], + } +}; + +const platformKey = `${targetOS}-${targetArch}`; +const config = platformConfigs[platformKey]; + +if (!config) { + console.warn(`⚠️ No specific configuration for ${platformKey}, using default`); + console.log(`📝 Keeping existing pnpm-workspace.yaml configuration`); + process.exit(0); +} + +const workspaceFile = 'pnpm-workspace.yaml'; + +try { + let workspaceConfig = {}; + + // Read and parse existing file if it exists + if (existsSync(workspaceFile)) { + const existingContent = readFileSync(workspaceFile, 'utf8'); + try { + workspaceConfig = YAML.parse(existingContent) || {}; + console.log(`📖 Parsed existing pnpm-workspace.yaml`); + } catch (parseError) { + console.warn(`⚠️ Failed to parse existing YAML, creating new config: ${parseError.message}`); + workspaceConfig = {}; + } + } + + // Update supportedArchitectures configuration + workspaceConfig.supportedArchitectures = { + os: config.os, + cpu: config.cpu + }; + + // Convert back to YAML with proper formatting + const finalContent = YAML.stringify(workspaceConfig, { + indent: 2, + lineWidth: 0, + minContentWidth: 0 + }); + + writeFileSync(workspaceFile, finalContent, 'utf8'); + console.log(`✅ Updated pnpm-workspace.yaml for ${platformKey}`); + console.log(`📋 Configuration:`); + console.log(` OS: ${config.os.join(', ')}`); + console.log(` CPU: ${config.cpu.join(', ')}`); +} catch (error) { + console.error(`❌ Failed to update pnpm-workspace.yaml: ${error.message}`); + process.exit(1); +} + +console.log(`🎉 Platform configuration completed. Run 'pnpm install' to install dependencies.`);