Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

feat: prepare internal plugins before tauri dev

hairyff52a1c744757
diff --git a/.gitignore b/.gitignore
index 9136408f..517b7d02 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,6 @@ src-tauri/resources/preset-plugins/
.tmp
release-msi-version.tmp.json
skills
-.serena
\ No newline at end of file
+.serena
+source/
+.gitmodules
diff --git a/package.json b/package.json
index d1516382..3876fe44 100644
--- a/package.json
+++ b/package.json
@@ -10,7 +10,7 @@
"prebuild": "tsx scripts/prebuild.ts",
"build": "tsc && vite build && pnpm prebuild",
"preview": "vite preview",
- "tauri": "tauri",
+ "tauri": "tsx scripts/predev.ts",
"release": "bumpp --pr",
"test": "vitest",
"lint": "eslint",
@@ -50,10 +50,15 @@
"@vitejs/plugin-react": "^4.6.0",
"babel-plugin-react-compiler": "^1.0.0",
"bumpp": "12.2.1",
+ "citty": "^0.2.2",
+ "consola": "^3.4.2",
+ "dotenv": "^17.4.2",
"eslint": "^10.8.1",
"eslint-plugin-react-refresh": "^0.5.4",
"knip": "^6.32.2",
+ "pathe": "^2.0.3",
"tailwindcss": "4.1.11",
+ "tinyexec": "^1.3.0",
"tsx": "^4.23.12",
"typescript": "~5.8.3",
"vite": "^7.0.4",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 14ac94a7..c5a37cb7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -98,6 +98,15 @@ importers:
bumpp:
specifier: 12.2.1
version: 12.2.1(patch_hash=362685edd02f1561e78b740e2b4c1ec2bd8e266eb2e26a64055ae305cac1c3ac)
+ citty:
+ specifier: ^0.2.2
+ version: 0.2.2
+ consola:
+ specifier: ^3.4.2
+ version: 3.4.2
+ dotenv:
+ specifier: ^17.4.2
+ version: 17.4.2
eslint:
specifier: ^10.8.1
version: 10.8.1([email protected])
@@ -107,9 +116,15 @@ importers:
knip:
specifier: ^6.32.2
version: 6.32.2
+ pathe:
+ specifier: ^2.0.3
+ version: 2.0.3
tailwindcss:
specifier: 4.1.11
version: 4.1.11
+ tinyexec:
+ specifier: ^1.3.0
+ version: 1.3.0
tsx:
specifier: ^4.23.12
version: 4.23.12
@@ -1769,6 +1784,9 @@ packages:
resolution: {integrity: sha512-77PSwercCZU2Fc4sX94eF8k8Pxte6JAwL4/ICZLFjJLqegs7kCuAsqqj/70NQF6TvDpgFjkubQB2FW2ZZddvQg==}
engines: {node: '>=8'}
+ resolution: {integrity: sha512-+6vJA3L98yv+IdfKGZHBNiGW5KHn22e/JwID0Strsz8h4S/csAu/OuICwxrg44k5MRiZHWIo8XXuJgQTriRP4w==}
+
resolution: {integrity: sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==}
@@ -1797,6 +1815,10 @@ packages:
resolution: {integrity: sha512-ysOGlgTFbN2/Y6Cg3Iye8YKulHw+R2fNXHrgSmXISQdMnomY6eNDprVdW9R5xBguEqI954+S6709UyiO7B+6OQ==}
+ resolution: {integrity: sha512-5IKcdX0nnYavi6G7TtOhwkYzyjfJlatbjMjuLSfE2kYT5pMDOilZ4OvMhi637CcDICTmz3wARPoyhqyX1Y+XvA==}
+ engines: {node: ^14.18.0 || >=16.10.0}
+
resolution: {integrity: sha512-lOETlkIeYSJWcbbcvjRKGxVMXJR+8+OQb/mTPbA4ObPMytYIsUbuOE0Jzy60hjARYszq1id0j8KgVhC+WGZVTg==}
engines: {node: '>=12'}
@@ -1881,6 +1903,10 @@ packages:
resolution: {integrity: sha512-nRCa7CK3VTrM2NmGkIy4cbK7IZlgBE/PYMn55rrXefr5xXDP0LdtfPnblFDoVdcAfslJ7or6iqAUnx0CCGIWQA==}
+ resolution: {integrity: sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==}
+ engines: {node: '>=12'}
+
resolution: {integrity: sha512-bNglH7lPH5l+yHOes7Zr4VqxhOy4BQ9ZBUX4VdoFgxMpzJk7W1ZoO3Vgd9Pxa9PyjQ76sfm2aKH/nzEcCNRlew==}
@@ -4868,6 +4894,8 @@ snapshots:
+
@@ -4884,6 +4912,8 @@ snapshots:
+
@@ -4952,6 +4982,8 @@ snapshots:
'@babel/runtime': 7.29.7
csstype: 3.2.3
+
diff --git a/scripts/predev.i18n.ts b/scripts/predev.i18n.ts
new file mode 100644
index 00000000..0cf496bd
--- /dev/null
+++ b/scripts/predev.i18n.ts
@@ -0,0 +1,55 @@
+import process from 'node:process'
+
+export type PredevLocale = 'en-US' | 'zh-CN'
+
+const messages = {
+ 'en-US': {
+ 'command.description': 'Prepare the internal plugin environment and forward Tauri CLI commands',
+ 'command.yes': 'Skip confirmation before cloning internal plugins',
+ 'command.lang': 'Set the command language',
+ 'env.configured': 'Updated .env: DEV_INTERNAL_PLUGINS_DIR={dir}',
+ 'git.checking': 'Checking submodule updates: {dir}',
+ 'git.latest': 'dsh-tauri-plugins is up to date',
+ 'git.updated': 'dsh-tauri-plugins has been updated',
+ 'plugin.confirm': 'DEV_INTERNAL_PLUGINS_DIR is not set. Clone dsh-tauri-plugins as a submodule?',
+ 'plugin.invalid_dir': 'The directory exists but is not a Git submodule: {dir}',
+ 'plugin.exists': 'Submodule directory already exists: {dir}',
+ },
+ 'zh-CN': {
+ 'command.description': '准备内置插件环境并转发 Tauri CLI 命令',
+ 'command.yes': '跳过内置插件拉取确认',
+ 'command.lang': '设置命令语言',
+ 'env.configured': '已设置 .env:DEV_INTERNAL_PLUGINS_DIR={dir}',
+ 'git.checking': '检查子模块更新:{dir}',
+ 'git.latest': 'dsh-tauri-plugins 已是最新版本',
+ 'git.updated': 'dsh-tauri-plugins 已更新',
+ 'plugin.confirm': '你的内置环境目录 DEV_INTERNAL_PLUGINS_DIR 环境未设置,是否拉取 dsh-tauri-plugins 作为子模块?',
+ 'plugin.invalid_dir': '目录已存在但不是 Git 子模块:{dir}',
+ 'plugin.exists': '子模块目录已存在:{dir}',
+ },
+} as const
+
+export type PredevMessageKey = keyof typeof messages['en-US']
+
+export function detectLocale(explicitLocale?: string): PredevLocale {
+ if (explicitLocale === 'en-US' || explicitLocale === 'zh-CN')
+ return explicitLocale
+
+ const environmentLocale = process.env.LC_ALL
+ || process.env.LC_MESSAGES
+ || process.env.LANG
+ || new Intl.DateTimeFormat().resolvedOptions().locale
+
+ return environmentLocale.toLowerCase().replace('_', '-').startsWith('zh') ? 'zh-CN' : 'en-US'
+}
+
+export function translate(
+ locale: PredevLocale,
+ key: PredevMessageKey,
+ replacements: Record<string, string> = {},
+): string {
+ return Object.entries(replacements).reduce(
+ (message, [name, value]) => message.split(`{${name}}`).join(value),
+ messages[locale][key] as string,
+ )
+}
diff --git a/scripts/predev.ts b/scripts/predev.ts
new file mode 100644
index 00000000..59bbdd64
--- /dev/null
+++ b/scripts/predev.ts
@@ -0,0 +1,133 @@
+import { appendFileSync, existsSync } from 'node:fs'
+import process from 'node:process'
+import { defineCommand, runCommand } from 'citty'
+import { consola } from 'consola'
+import { config as loadDotenv } from 'dotenv'
+import { join, resolve } from 'pathe'
+import { x } from 'tinyexec'
+import { detectLocale, translate } from './predev.i18n'
+
+// ==========================================
+// 1. 配置与初始化
+// ==========================================
+const REPO_ROOT = resolve(import.meta.dirname, '..')
+const ENV_FILE = join(REPO_ROOT, '.env')
+const SUBMODULE_DIR = 'source/dsh-tauri-plugins' // 修正拼写: soruce -> source
+const PLUGINS_DIR = `${SUBMODULE_DIR}/packages`
+const SUBMODULE_PATH = join(REPO_ROOT, SUBMODULE_DIR)
+const SUBMODULE_URL = 'https://github.com/dsh-tauri-desk/dsh-tauri-plugins.git'
+const ENV_KEY = 'DEV_INTERNAL_PLUGINS_DIR'
+
+// 加载 .env 变量到 process.env
+loadDotenv({ path: ENV_FILE, quiet: true })
+
+// 智能识别语言设置
+const rawArgs = process.argv.slice(2)
+const langArg = rawArgs.find(arg => arg.startsWith('--lang='))?.slice(7)
+ ?? (rawArgs.includes('--lang') ? rawArgs[rawArgs.indexOf('--lang') + 1] : undefined)
+
+let locale = detectLocale(langArg)
+
+// ==========================================
+// 2. 核心函数 (仅保留 2 个)
+// ==========================================
+
+/**
+ * 命令执行器 (兼顾普通执行与输出捕获)
+ */
+async function exec(program: string, args: readonly string[], cwd = REPO_ROOT, capture = false): Promise<string> {
+ if (!capture)
+ consola.info(`$ ${program} ${args.join(' ')}`)
+ const result = await x(program, args, {
+ throwOnError: true,
+ nodeOptions: { cwd, env: process.env, stdio: capture ? undefined : 'inherit' },
+ })
+ return capture ? result.stdout.trim() : ''
+}
+
+/**
+ * 确保插件目录与环境配置就绪
+ */
+async function ensureInternalPlugins(skipPrompt: boolean): Promise<void> {
+ // 1. Git 子模块检查与同步
+ if (existsSync(join(SUBMODULE_PATH, '.git'))) {
+ consola.start(translate(locale, 'git.checking', { dir: SUBMODULE_DIR }))
+ await exec('git', ['fetch', '--quiet'], SUBMODULE_PATH)
+
+ const [localRev, upstreamRev] = await Promise.all([
+ exec('git', ['rev-parse', 'HEAD'], SUBMODULE_PATH, true),
+ exec('git', ['rev-parse', '@{upstream}'], SUBMODULE_PATH, true),
+ ])
+
+ if (localRev === upstreamRev) {
+ consola.success(translate(locale, 'git.latest'))
+ }
+ else {
+ await exec('git', ['pull', '--ff-only'], SUBMODULE_PATH)
+ consola.success(translate(locale, 'git.updated'))
+ }
+ }
+
+ // 2. 环境变量检测与快捷设置
+ if (process.env[ENV_KEY]?.trim())
+ return
+
+ const confirm = skipPrompt || await consola.prompt(
+ translate(locale, 'plugin.confirm'),
+ { type: 'confirm', initial: false, cancel: 'reject' },
+ )
+ if (!confirm)
+ return
+
+ // 3. 克隆/校验子模块
+ if (!existsSync(SUBMODULE_PATH)) {
+ await exec('git', ['submodule', 'add', '-f', SUBMODULE_URL, SUBMODULE_DIR])
+ }
+ else if (!existsSync(join(SUBMODULE_PATH, '.git'))) {
+ throw new Error(translate(locale, 'plugin.invalid_dir', { dir: SUBMODULE_DIR }))
+ }
+ else {
+ consola.info(translate(locale, 'plugin.exists', { dir: SUBMODULE_DIR }))
+ }
+
+ // 4. 利用 dotenv 协作写回环境配置
+ const separator = existsSync(ENV_FILE) ? '\n' : ''
+ appendFileSync(ENV_FILE, `${separator}${ENV_KEY}=${PLUGINS_DIR}\n`, 'utf8')
+ process.env[ENV_KEY] = PLUGINS_DIR
+ consola.success(translate(locale, 'env.configured', { dir: PLUGINS_DIR }))
+}
+
+// ==========================================
+// 3. CLI 主流程
+// ==========================================
+
+const command = defineCommand({
+ meta: {
+ name: 'predev',
+ description: translate(locale, 'command.description'),
+ },
+ args: {
+ yes: { type: 'boolean', description: translate(locale, 'command.yes') },
+ lang: { type: 'enum', options: ['en-US', 'zh-CN'], description: translate(locale, 'command.lang') },
+ },
+ async run({ args, rawArgs }) {
+ locale = detectLocale(args.lang)
+
+ const isDev = rawArgs[0] === 'dev'
+ // 剔除内部预处理参数
+ const tauriArgs = isDev
+ ? rawArgs.filter((arg, i) => arg !== '--yes' && arg !== '--lang' && !arg.startsWith('--lang=') && rawArgs[i - 1] !== '--lang')
+ : rawArgs
+
+ if (isDev) {
+ await ensureInternalPlugins(args.yes === true)
+ }
+
+ await exec('tauri', tauriArgs)
+ },
+})
+
+runCommand(command, { rawArgs }).catch((err: unknown) => {
+ consola.error(err instanceof Error ? err.message : err)
+ process.exitCode = 1
+})