diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..2bc0b86 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,11 @@ +--- + +name: 🐞 Bug report +about: Create a report to help us improve +title: "[Bug] the title of bug report" +labels: bug +assignees: '' + +--- + +#### Describe the bug diff --git a/.github/ISSUE_TEMPLATE/help_wanted.md b/.github/ISSUE_TEMPLATE/help_wanted.md new file mode 100644 index 0000000..6fba797 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/help_wanted.md @@ -0,0 +1,10 @@ +--- +name: 🥺 Help wanted +about: Confuse about the use of electron-vue-vite +title: "[Help] the title of help wanted report" +labels: help wanted +assignees: '' + +--- + +#### Describe the problem you confuse diff --git a/.vscode/settings.json b/.vscode/settings.json index 6c650fc..bc6a839 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -45,7 +45,9 @@ "pair ${this.formData.host}:${this.formData.port} ${this.formData.pair}", "${item.decoder} & ${item.encoder}", " & ", - "${key}=${value}" + "${key}=${value}", + "npm install", + "npm run build" ], "cSpell.words": [ "bhsn" diff --git a/electron/events/app/index.js b/electron/ipc/app/index.js similarity index 100% rename from electron/events/app/index.js rename to electron/ipc/app/index.js diff --git a/electron/events/handles/index.js b/electron/ipc/handles/index.js similarity index 100% rename from electron/events/handles/index.js rename to electron/ipc/handles/index.js diff --git a/electron/events/index.js b/electron/ipc/index.js similarity index 100% rename from electron/events/index.js rename to electron/ipc/index.js diff --git a/electron/events/shortcuts/index.js b/electron/ipc/shortcuts/index.js similarity index 100% rename from electron/events/shortcuts/index.js rename to electron/ipc/shortcuts/index.js diff --git a/electron/events/theme/index.js b/electron/ipc/theme/index.js similarity index 100% rename from electron/events/theme/index.js rename to electron/ipc/theme/index.js diff --git a/electron/events/tray/index.js b/electron/ipc/tray/index.js similarity index 100% rename from electron/events/tray/index.js rename to electron/ipc/tray/index.js diff --git a/electron/events/updater/index.js b/electron/ipc/updater/index.js similarity index 100% rename from electron/events/updater/index.js rename to electron/ipc/updater/index.js diff --git a/electron/main.js b/electron/main.js index a98ca51..9a18259 100644 --- a/electron/main.js +++ b/electron/main.js @@ -14,7 +14,7 @@ import appStore from './helpers/store.js' import { getLogoPath } from './configs/index.js' -import events from './events/index.js' +import ipc from './ipc/index.js' import control from '$control/electron/main.js' @@ -87,7 +87,7 @@ function createWindow() { loadPage(mainWindow) - events(mainWindow) + ipc(mainWindow) control(mainWindow) } diff --git a/package.json b/package.json index 1fecf77..ac4acce 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "build:win": "vite build && electron-builder --win", "build:mac": "vite build && electron-builder --mac", "build:linux": "vite build && electron-builder --linux", - "preview": "vite preview", "svgo": "svgo --folder=src/icons/svgo --output=src/icons/svg --config=src/icons/svgo.config.js", "postinstall": "electron-builder install-app-deps", "prepare": "husky install" @@ -57,6 +56,8 @@ "postcss": "8.4.38", "postcss-nested": "6.0.1", "postcss-scss": "4.0.9", + "rimraf": "^6.0.1", + "simple-git": "^3.27.0", "unocss": "0.62.3", "unplugin-auto-import": "0.18.2", "unplugin-vue-components": "0.27.4", diff --git a/scripts/helpers/index.js b/scripts/helpers/index.js new file mode 100644 index 0000000..277cde2 --- /dev/null +++ b/scripts/helpers/index.js @@ -0,0 +1,97 @@ +import simpleGit from 'simple-git' +import fs from 'node:fs/promises' +import path from 'node:path' +import os from 'node:os' +import { exec } from 'node:child_process' +import { promisify } from 'node:util' +import { fileURLToPath } from 'node:url' + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) + +const execPromise = promisify(exec) + +/** + * 在临时目录中克隆GitHub仓库,安装依赖,构建项目,并将构建输出复制到指定目录。 + * + * @param {Object} options - 函数的配置选项。 + * @param {string} options.repoUrl - 要克隆的GitHub仓库URL。 + * @param {string} options.buildOutputDir - 构建输出所在的目录(相对于项目根目录)。 + * @param {string} options.destinationDir - 构建输出应该被复制到的目录。 + * @param {string} [options.branch] - 要克隆的分支(默认为'main')。 + * @param {string} [options.installCommand] - 安装依赖的命令。 + * @param {string} [options.buildCommand] - 构建项目的命令。 + * @returns {Promise} + * + * @example + * gitResolve({ + * repoUrl: 'https://github.com/user/project.git', + * buildOutputDir: 'dist', + * destinationDir: './public', + * branch: 'main', + * installCommand: 'npm install', + * buildCommand: 'npm run build' + * }); + */ +export async function gitResolve(options) { + const { + repoUrl, + buildOutputDir, + destinationDir, + branch = 'main', + installCommand = 'npm install', + buildCommand = 'npm run build', + } = options + + const repoName = path.basename(repoUrl, path.extname(repoUrl)) + + let tempDir + + try { + // 创建临时目录 + tempDir = await fs.mkdtemp(path.join(os.tmpdir(), `${repoName}-`)) + console.log(`创建临时目录: ${tempDir}`) + + // 克隆仓库 + console.log(`正在克隆仓库: ${repoUrl}`) + const git = simpleGit() + await git.clone(repoUrl, tempDir, ['--depth', '1', '--branch', branch]) + + // 切换到临时目录 + process.chdir(tempDir) + + // 安装依赖 + console.log('正在安装依赖...') + await execPromise(installCommand) + + // 构建项目 + console.log('正在构建项目...') + await execPromise(buildCommand) + + // 复制构建输出到目标目录 + const sourcePath = path.join(tempDir, buildOutputDir) + const finallyDestinationDir = path.join(destinationDir, repoName) + + console.log( + `正在将构建输出从 ${sourcePath} 复制到 ${finallyDestinationDir}`, + ) + await fs.cp(sourcePath, finallyDestinationDir, { recursive: true }) + + console.log('流程成功完成。') + } + catch (error) { + console.error('发生错误:', error) + throw error + } + finally { + if (tempDir) { + if (['win32'].includes(process.platform)) { + console.log( + `注意,在 Windows 中由于文件锁的原因 你需要手动清除缓存目录:\npnpm cleanup ${tempDir}`, + ) + } + else { + fs.rm(tempDir).catch(e => console.log(e.message)) + } + } + } +} diff --git a/src/components/Device/components/BatchActions/index.vue b/src/components/Device/components/BatchActions/index.vue index 4fd9824..997a7e6 100644 --- a/src/components/Device/components/BatchActions/index.vue +++ b/src/components/Device/components/BatchActions/index.vue @@ -1,40 +1,42 @@