Skip to content

Commit

Permalink
perf: ♻️ Script and directory structure optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 21, 2024
1 parent 6ffefe5 commit 68378ef
Show file tree
Hide file tree
Showing 15 changed files with 164 additions and 41 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/help_wanted.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -87,7 +87,7 @@ function createWindow() {

loadPage(mainWindow)

events(mainWindow)
ipc(mainWindow)

control(mainWindow)
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
97 changes: 97 additions & 0 deletions scripts/helpers/index.js
Original file line number Diff line number Diff line change
@@ -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<void>}
*
* @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))
}
}
}
}
74 changes: 38 additions & 36 deletions src/components/Device/components/BatchActions/index.vue
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
<template>
<div class="flex items-center space-x-2">
<component
:is="item.component || 'div'"
v-for="(item, index) in actionModel"
:key="index"
class="flex-none"
v-bind="{
devices,
...(item.command
? {
onClick: () => handleShell(item),
}
: {}),
}"
>
<template #default="{ loading = false } = {}">
<el-button
plain
:title="$t(item.tips || item.label)"
:loading="loading"
>
<template #icon>
<svg-icon
v-if="item.svgIcon"
:name="item.svgIcon"
:class="item.iconClass"
></svg-icon>
<el-icon v-else-if="item.elIcon" :class="item.iconClass">
<component :is="item.elIcon" />
</el-icon>
</template>
{{ $t('common.batch') }}-{{ $t(item.label) }}
</el-button>
</template>
</component>
</div>
<Scrollable>
<div class="flex items-center space-x-2">
<component
:is="item.component || 'div'"
v-for="(item, index) in actionModel"
:key="index"
class="flex-none"
v-bind="{
devices,
...(item.command
? {
onClick: () => handleShell(item),
}
: {}),
}"
>
<template #default="{ loading = false } = {}">
<el-button
plain
:title="$t(item.tips || item.label)"
:loading="loading"
>
<template #icon>
<svg-icon
v-if="item.svgIcon"
:name="item.svgIcon"
:class="item.iconClass"
></svg-icon>
<el-icon v-else-if="item.elIcon" :class="item.iconClass">
<component :is="item.elIcon" />
</el-icon>
</template>
{{ $t('common.batch') }}-{{ $t(item.label) }}
</el-button>
</template>
</component>
</div>
</Scrollable>
</template>

<script setup>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Device/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<el-table-column
v-slot="{ row, $index }"
:label="$t('device.control.name')"
min-width="250"
min-width="300"
align="left"
>
<MirrorAction
Expand Down

0 comments on commit 68378ef

Please sign in to comment.