-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: ♻️ Script and directory structure optimization
- Loading branch information
Showing
15 changed files
with
164 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters