ai-generate-template-electron-blank 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +14 -2
  2. package/package.json +31 -4
  3. package/scripts/create.js +64 -0
  4. package/template/.editorconfig +9 -0
  5. package/template/.env.development +6 -0
  6. package/template/.env.production +3 -0
  7. package/template/.npmrc.template +6 -0
  8. package/template/.prettierignore +14 -0
  9. package/template/.prettierrc +12 -0
  10. package/template/README.md +26 -0
  11. package/template/build/entitlements.mac.plist +12 -0
  12. package/template/build/icon.icns +0 -0
  13. package/template/build/icon.ico +0 -0
  14. package/template/build/icon.png +0 -0
  15. package/template/electron-builder.yml +19 -0
  16. package/template/electron.vite.config.ts +56 -0
  17. package/template/eslint.config.mjs +40 -0
  18. package/template/gitignore.template +60 -0
  19. package/template/hehe-theme-v2-0.0.1.tgz +0 -0
  20. package/template/package-lock.json +11377 -0
  21. package/template/package.json +65 -0
  22. package/template/postcss.config.mjs +3 -0
  23. package/template/resources/icon.png +0 -0
  24. package/template/src/main/index.ts +84 -0
  25. package/template/src/preload/index.ts +18 -0
  26. package/template/src/preload/window.d.ts +7 -0
  27. package/template/src/renderer/index.html +12 -0
  28. package/template/src/renderer/src/api/base.test.ts +14 -0
  29. package/template/src/renderer/src/api/base.ts +10 -0
  30. package/template/src/renderer/src/api/error-map.ts +19 -0
  31. package/template/src/renderer/src/api/http.ts +79 -0
  32. package/template/src/renderer/src/api/types.ts +42 -0
  33. package/template/src/renderer/src/api/user.ts +34 -0
  34. package/template/src/renderer/src/app/app.vue +11 -0
  35. package/template/src/renderer/src/app/main.ts +29 -0
  36. package/template/src/renderer/src/auth/permission.ts +13 -0
  37. package/template/src/renderer/src/auth/token.test.ts +18 -0
  38. package/template/src/renderer/src/auth/token.ts +41 -0
  39. package/template/src/renderer/src/components/ThemeSettings.vue +185 -0
  40. package/template/src/renderer/src/composables/useAppTheme.test.ts +253 -0
  41. package/template/src/renderer/src/composables/useAppTheme.ts +205 -0
  42. package/template/src/renderer/src/mocks/index.ts +3 -0
  43. package/template/src/renderer/src/mocks/mock-utils.ts +179 -0
  44. package/template/src/renderer/src/pages/Appearance.vue +48 -0
  45. package/template/src/renderer/src/pages/Blank.vue +29 -0
  46. package/template/src/renderer/src/router/index.test.ts +24 -0
  47. package/template/src/renderer/src/router/index.ts +12 -0
  48. package/template/src/renderer/src/store/index.ts +5 -0
  49. package/template/src/renderer/src/store/user.ts +45 -0
  50. package/template/src/renderer/src/styles/index.scss +7 -0
  51. package/template/src/renderer/src/styles/reset.css +11 -0
  52. package/template/src/renderer/src/styles/theme.scss +42 -0
  53. package/template/src/renderer/src/vite-env.d.ts +7 -0
  54. package/template/tsconfig.json +4 -0
  55. package/template/tsconfig.node.json +8 -0
  56. package/template/tsconfig.web.json +18 -0
  57. package/template/vite-plugin-electron-obfuscator-1.0.0.tgz +0 -0
  58. package/template/vitest.config.mts +14 -0
package/README.md CHANGED
@@ -1,3 +1,15 @@
1
- # Temporary Holding Version
1
+ # Electron 空白桌面模板
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 生成一个带系统标题栏的空白桌面窗口。渲染进程使用 Vue 3、TypeScript、Hash 路由和 Pinia,保留 Hehe UI、主题、公共请求封装和开发环境 Mock 扩展入口。
4
+
5
+ ## 生成项目
6
+
7
+ 使用 Node.js 22.12 及以上版本。在本目录执行以下命令,生成器会复制模板并安装依赖。
8
+
9
+ ```sh
10
+ node scripts/create.js my-desktop-app
11
+ cd my-desktop-app
12
+ npm run dev
13
+ ```
14
+
15
+ 模板源码和打包命令见 [应用说明](template/README.md)。
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "ai-generate-template-electron-blank",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Electron + Vue 3 + TypeScript 空白桌面模板",
5
+ "bin": {
6
+ "ai-generate-template-electron-blank": "scripts/create.js"
7
+ },
8
+ "license": "MIT",
9
+ "engines": {
10
+ "node": ">=22.12.0",
11
+ "npm": ">=9.0.0"
12
+ },
13
+ "files": [
14
+ "scripts/create.js",
15
+ "template/src",
16
+ "template/resources",
17
+ "template/build",
18
+ "template/*.md",
19
+ "template/package*.json",
20
+ "template/tsconfig*.json",
21
+ "template/*.config.*",
22
+ "template/.editorconfig",
23
+ "template/.env.development",
24
+ "template/.env.production",
25
+ "template/.npmrc.template",
26
+ "template/gitignore.template",
27
+ "template/.prettierrc",
28
+ "template/.prettierignore",
29
+ "template/electron-builder.yml",
30
+ "template/hehe-theme-v2-0.0.1.tgz",
31
+ "template/vite-plugin-electron-obfuscator-1.0.0.tgz"
32
+ ]
33
+ }
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('node:fs')
3
+ const path = require('node:path')
4
+ const { execSync } = require('node:child_process')
5
+ const { createHash } = require('node:crypto')
6
+
7
+ function createProject(directory) {
8
+ if (!directory) throw new Error('请提供项目目录,例如 my-desktop-app')
9
+ const target = path.resolve(directory)
10
+ const name = path.basename(target).toLowerCase()
11
+ if (!/^[a-z0-9][a-z0-9._-]*$/.test(name) || name.length > 214) {
12
+ throw new Error('项目目录名须以英文字母或数字开头,可包含点、连字符和下划线')
13
+ }
14
+ if (fs.existsSync(target) && (!fs.statSync(target).isDirectory() || fs.readdirSync(target).length)) {
15
+ throw new Error('目标路径已被占用,请选择空目录')
16
+ }
17
+
18
+ fs.mkdirSync(target, { recursive: true })
19
+ const template = path.join(__dirname, '..', 'template')
20
+ // 本地运行与 npm 包使用同一份模板文件清单。
21
+ const { files } = require('../package.json')
22
+ for (const entry of fs.readdirSync(template)) {
23
+ if (!files.some((pattern) => path.matchesGlob('template/' + entry, pattern))) continue
24
+ fs.cpSync(path.join(template, entry), path.join(target, entry), {
25
+ recursive: true,
26
+ filter: (file) => !['.git', '.DS_Store', 'node_modules'].includes(path.basename(file))
27
+ })
28
+ }
29
+ for (const [from, to] of [['gitignore.template', '.gitignore'], ['.npmrc.template', '.npmrc']]) {
30
+ fs.renameSync(path.join(target, from), path.join(target, to))
31
+ }
32
+
33
+ for (const filename of ['package.json', 'package-lock.json']) {
34
+ const file = path.join(target, filename)
35
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf8'))
36
+ pkg.name = name
37
+ if (pkg.packages) pkg.packages[''].name = name
38
+ fs.writeFileSync(file, JSON.stringify(pkg, null, 2) + '\n')
39
+ }
40
+
41
+ // 从项目名稳定派生安装标识,同名项目升级时保留原有身份。
42
+ const appId = 'com.hehe.desktop.app' + createHash('sha256').update(name).digest('hex').slice(0, 20)
43
+ const configFile = path.join(target, 'electron-builder.yml')
44
+ const config = fs.readFileSync(configFile, 'utf8')
45
+ const defaultId = /^appId: (.+)$/m.exec(config)[1]
46
+ fs.writeFileSync(configFile, config.replace('appId: ' + defaultId, 'appId: ' + appId)
47
+ .replace(/^productName: .+$/m, 'productName: ' + JSON.stringify(name))
48
+ .replace(/^ executableName: .+$/m, ' executableName: ' + JSON.stringify(name)))
49
+ const mainFile = path.join(target, 'src/main/index.ts')
50
+ fs.writeFileSync(mainFile, fs.readFileSync(mainFile, 'utf8').replace(defaultId, appId))
51
+
52
+ console.log('正在安装项目依赖…')
53
+ execSync('npm install', { cwd: target, stdio: 'inherit' })
54
+ const executable = require(path.join(target, 'node_modules', 'electron'))
55
+ if (!fs.existsSync(executable)) throw new Error('Electron 可执行文件缺失,请在项目目录重新安装依赖')
56
+ console.log(`已创建 ${target},进入该目录后运行 npm run dev。`)
57
+ }
58
+
59
+ try {
60
+ createProject(process.argv[2])
61
+ } catch (error) {
62
+ console.error(error.message)
63
+ process.exitCode = 1
64
+ }
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
@@ -0,0 +1,6 @@
1
+ # 开发环境配置
2
+ # API基础地址前缀
3
+ VITE_API_BASE=/api
4
+
5
+ # 是否启用代理
6
+ VITE_USE_PROXY=false
@@ -0,0 +1,3 @@
1
+ # 本地 HTML 加载生产页面,接入后端时填写含协议和服务前缀的完整地址。
2
+ VITE_API_BASE=
3
+ VITE_USE_PROXY=false
@@ -0,0 +1,6 @@
1
+ # npm 包注册表镜像配置
2
+ registry=https://registry.npmmirror.com
3
+
4
+ # Electron 二进制文件镜像配置
5
+ electron_mirror=https://npmmirror.com/mirrors/electron/
6
+ electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
@@ -0,0 +1,14 @@
1
+ out
2
+ dist
3
+ release
4
+ node_modules
5
+ *.local
6
+ *.log*
7
+ .vscode
8
+ .idea
9
+ *.sh
10
+ *.tgz
11
+ pnpm-lock.yaml
12
+ LICENSE.md
13
+ tsconfig.json
14
+ tsconfig.*.json
@@ -0,0 +1,12 @@
1
+ {
2
+ "semi": false,
3
+ "singleQuote": true,
4
+ "tabWidth": 2,
5
+ "trailingComma": "none",
6
+ "printWidth": 100,
7
+ "bracketSpacing": true,
8
+ "arrowParens": "always",
9
+ "endOfLine": "lf",
10
+ "vueIndentScriptAndStyle": false,
11
+ "htmlWhitespaceSensitivity": "ignore"
12
+ }
@@ -0,0 +1,26 @@
1
+ # Electron 空白应用
2
+
3
+ 运行 `npm install` 安装依赖,运行 `npm run dev` 打开开发窗口。直接在模板目录开发时也使用这两个命令。
4
+
5
+ - 默认页面位于 `src/renderer/src/pages/Blank.vue`,路由在 `src/renderer/src/router/index.ts` 中维护。Hash 路由支持安装后从本地 HTML 加载。
6
+ - 主题、组件库和 Pinia 在 `src/renderer/src/app/main.ts` 注册。按需在 `src/renderer/src/mocks/index.ts` 添加开发接口。
7
+ - 主进程位于 `src/main/index.ts`。系统标题栏提供窗口操作,预加载脚本也通过 `window.api` 提供窗口控制。
8
+ - 接入后端时,在生产环境的 `VITE_API_BASE` 填写完整服务地址,并在服务端配置跨域访问。开发环境可以使用 Vite 代理。
9
+
10
+ ## 验证与打包
11
+
12
+ ```sh
13
+ npm run lint
14
+ npm run typecheck
15
+ npm run test:run
16
+ npm run build
17
+ npm start
18
+ ```
19
+
20
+ 在 macOS 上运行 `npm run build:mac` 生成 DMG,在 Windows 上运行 `npm run build:win` 生成 NSIS 安装包。产物位于 `dist/`。分发前在 `electron-builder.yml` 设置自己的 `appId`,在 `package.json` 填写应用名称与作者。
21
+
22
+ ## 桌面主题与服务地址
23
+
24
+ 从系统菜单「外观 → 主题设置」或按 Cmd/Ctrl + 逗号打开设置,设置页可返回空白首页。支持亮色、暗色和管理员模式,以及预设色、取色器和 HEX 输入。主题与主色文字设置会在重启后恢复。业务样式可直接引用 `--color-primary`、`--color-on-primary`、`--color-card-bg` 和 `--color-text`。
25
+
26
+ 在 `.env.production.local` 设置完整的 `VITE_API_BASE` 后重新构建。开发环境可使用相对代理路径。脚手架按项目名生成安装标识,同一产品后续版本应沿用相同标识。
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>com.apple.security.cs.allow-jit</key>
6
+ <true/>
7
+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
8
+ <true/>
9
+ <key>com.apple.security.cs.allow-dyld-environment-variables</key>
10
+ <true/>
11
+ </dict>
12
+ </plist>
Binary file
Binary file
Binary file
@@ -0,0 +1,19 @@
1
+ appId: com.example.electronblank
2
+ directories:
3
+ buildResources: build
4
+ files:
5
+ - out/**/*
6
+ - resources/icon.png
7
+ win:
8
+ target: nsis
9
+ icon: build/icon.ico
10
+ nsis:
11
+ oneClick: false
12
+ allowToChangeInstallationDirectory: true
13
+ mac:
14
+ target: dmg
15
+ icon: build/icon.icns
16
+ entitlementsInherit: build/entitlements.mac.plist
17
+ linux:
18
+ target: AppImage
19
+ icon: build/icon.png
@@ -0,0 +1,56 @@
1
+ import { resolve } from 'path'
2
+ import { defineConfig, externalizeDepsPlugin, loadEnv } from 'electron-vite'
3
+ import vue from '@vitejs/plugin-vue'
4
+ import { obfuscateChunks } from 'vite-plugin-electron-obfuscator'
5
+
6
+ export default defineConfig(({ mode }) => {
7
+ const env = loadEnv(mode, process.cwd(), '')
8
+
9
+ // 根据环境变量决定是否启用代理
10
+ const enableProxy = env.VITE_USE_PROXY === 'true'
11
+
12
+ const isProd = mode === 'production'
13
+
14
+ return {
15
+ main: {
16
+ plugins: [externalizeDepsPlugin(), ...(isProd ? [obfuscateChunks()] : [])]
17
+ },
18
+ preload: {
19
+ // 沙箱预加载脚本只依赖 Electron 内置模块。
20
+ plugins: []
21
+ },
22
+ renderer: {
23
+ base: './',
24
+ envPrefix: ['VITE_', 'RENDERER_VITE_'],
25
+ resolve: {
26
+ alias: {
27
+ '@': resolve('src/renderer/src')
28
+ }
29
+ },
30
+ build: {
31
+ rollupOptions: {
32
+ output: {
33
+ // 用 hash 文件名隐藏业务模块语义,防止通过 chunk 文件名推断功能模块
34
+ chunkFileNames: 'assets/[hash].js',
35
+ entryFileNames: 'assets/[hash].js',
36
+ assetFileNames: 'assets/[hash][extname]'
37
+ }
38
+ }
39
+ },
40
+ server: {
41
+ // 只有当 VITE_USE_PROXY=true 时才启用代理
42
+ proxy: enableProxy
43
+ ? {
44
+ '/api': {
45
+ target: 'http://localhost:81', // 代理目标地址
46
+ changeOrigin: true,
47
+ rewrite: (path) => path.replace(/^\/api/, '')
48
+ }
49
+ }
50
+ : undefined
51
+ },
52
+ // 生产构建时混淆渲染端业务代码(保留动态 import 路径、超大 chunk 自动轻量化)
53
+ plugins: [vue(), ...(isProd ? [obfuscateChunks()] : [])]
54
+ }
55
+ }
56
+ })
@@ -0,0 +1,40 @@
1
+ import { defineConfig } from 'eslint/config'
2
+ import tseslint from '@electron-toolkit/eslint-config-ts'
3
+ import eslintConfigPrettier from '@electron-toolkit/eslint-config-prettier'
4
+ import eslintPluginVue from 'eslint-plugin-vue'
5
+ import vueParser from 'vue-eslint-parser'
6
+
7
+ export default defineConfig(
8
+ { ignores: ['**/node_modules', '**/dist', '**/out'] },
9
+ tseslint.configs.recommended,
10
+ eslintPluginVue.configs['flat/recommended'],
11
+ {
12
+ files: ['**/*.vue'],
13
+ languageOptions: {
14
+ parser: vueParser,
15
+ parserOptions: {
16
+ ecmaFeatures: {
17
+ jsx: true
18
+ },
19
+ extraFileExtensions: ['.vue'],
20
+ parser: tseslint.parser
21
+ }
22
+ }
23
+ },
24
+ {
25
+ files: ['**/*.{ts,mts,tsx,vue}'],
26
+ rules: {
27
+ 'vue/require-default-prop': 'off',
28
+ 'vue/multi-word-component-names': 'off',
29
+ 'vue/block-lang': [
30
+ 'error',
31
+ {
32
+ script: {
33
+ lang: 'ts'
34
+ }
35
+ }
36
+ ]
37
+ }
38
+ },
39
+ eslintConfigPrettier
40
+ )
@@ -0,0 +1,60 @@
1
+ # Logs
2
+ logs
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ pnpm-debug.log*
8
+ lerna-debug.log*
9
+
10
+ # Dependencies
11
+ node_modules
12
+ .pnpm-store
13
+
14
+ # Build output
15
+ dist
16
+ out
17
+ release
18
+ *.local
19
+
20
+ # Test coverage
21
+ coverage
22
+ *.lcov
23
+
24
+ # Environment files
25
+ .env
26
+ .env.local
27
+ .env.*.local
28
+
29
+ # IDE / Editor
30
+ .vscode/*
31
+ !.vscode/extensions.json
32
+ !.vscode/settings.json
33
+ .idea
34
+ *.suo
35
+ *.ntvs*
36
+ *.njsproj
37
+ *.sln
38
+ *.sw?
39
+
40
+ # OS files
41
+ .DS_Store
42
+ Thumbs.db
43
+
44
+ # Cache
45
+ .cache
46
+ .eslintcache
47
+ *.tsbuildinfo
48
+
49
+ # Lock files (可选,团队统一使用 npm 则保留)
50
+ # package-lock.json
51
+ # pnpm-lock.yaml
52
+ # yarn.lock
53
+
54
+ # Local tgz files
55
+ *.tgz
56
+ !hehe-theme-v2-0.0.1.tgz
57
+ !vite-plugin-electron-obfuscator-1.0.0.tgz
58
+
59
+ # Electron specific
60
+ *.blockmap
Binary file