diff --git a/.env.example b/.env.example index ef7a67c..0a5d95e 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ # GitHub Personal Access Token for private repository access # Required for auto-updates from private repositories -GH_TOKEN=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 +GH_TOKEN=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 # For private repositories, you might also need: # GITHUB_TOKEN= # Alternative token name that some tools might use diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 58101cf..a319d44 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,17 +24,17 @@ jobs: with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20' - + - name: Configure Git to use HTTPS instead of SSH run: | git config --global url."https://github.com/".insteadOf git@github.com: git config --global url."https://".insteadOf git:// - + - name: Setup pnpm uses: pnpm/action-setup@v4 with: @@ -42,12 +42,12 @@ jobs: run_install: | - recursive: true args: [--frozen-lockfile=false] - + - name: Get pnpm store directory id: pnpm-cache run: | echo "pnpm_cache_dir=$(pnpm store path)" >> $GITHUB_OUTPUT - + - name: Setup pnpm cache uses: actions/cache@v4 with: @@ -55,48 +55,48 @@ jobs: key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - + - name: Install dependencies run: pnpm install --no-frozen-lockfile env: NPM_CONFIG_LEGACY_PEER_DEPS: true - + - name: Setup Git user run: | git config --global user.name 'github-actions[bot]' git config --global user.email 'github-actions[bot]@users.noreply.github.com' - + - name: Bump version and generate changelog run: | # 根据 commit 信息自动更新版本和生成 changelog pnpm release - + # 获取新版本号 VERSION=$(node -p "require('./package.json').version") echo "VERSION=$VERSION" >> $GITHUB_ENV - + - name: Push changes run: | git push origin main git push origin v${{ env.VERSION }} - + - name: Build for all platforms - run: pnpm build:all + run: pnpm pub env: # 在 macOS 上禁用代码签名 CSC_IDENTITY_AUTO_DISCOVERY: false # GitHub token 用于发布 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Create GitHub Release - uses: softprops/action-gh-release@v2 - with: - tag_name: v${{ env.VERSION }} - name: Release v${{ env.VERSION }} - body_path: CHANGELOG.md - draft: false - prerelease: false - files: | - release/${{ env.VERSION }}/* - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + + # - name: Create GitHub Release + # uses: softprops/action-gh-release@v2 + # with: + # tag_name: v${{ env.VERSION }} + # name: Release v${{ env.VERSION }} + # body_path: CHANGELOG.md + # draft: false + # prerelease: false + # files: | + # release/${{ env.VERSION }}/* + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/buildAssets/builder/config.js b/buildAssets/builder/config.js index 7f38cb8..a88819f 100644 --- a/buildAssets/builder/config.js +++ b/buildAssets/builder/config.js @@ -56,18 +56,18 @@ const baseConfig = { win: { icon: 'buildAssets/icons/icon.ico', target: [ - { - target: 'appx', - arch: 'x64' - }, - { - target: 'zip', - arch: 'x64' - }, - { - target: 'portable', - arch: 'x64' - }, + // { + // target: 'appx', + // arch: 'x64' + // }, + // { + // target: 'zip', + // arch: 'x64' + // }, + // { + // target: 'portable', + // arch: 'x64' + // }, { target: 'nsis', arch: 'x64' diff --git a/package.json b/package.json index 5cba0f3..ce6a694 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "vutron", - "appId": "com.vutron.vutron", + "name": "gdt-tool", + "appId": "com.tool.gdt", "version": "0.0.5", "description": "Quick Start Templates for Vite + Vue 3 + Electron", "homepage": "https://vutron.cdget.com", @@ -36,6 +36,7 @@ "lint:fix": "eslint . --ext .js,.ts,.vue --fix .", "test": "npm run build:pre && playwright test", "test:linux": "npm run build:pre && xvfb-run --auto-servernum --server-args='-screen 0, 1280x960x24' -- playwright test", + "pub": "npm run build:pre && electron-builder --config=buildAssets/builder/config.js --windows --publish=always", "release": "standard-version", "release:major": "standard-version --release-as major", "release:minor": "standard-version --release-as minor", diff --git a/src/main/AutoUpdater.ts b/src/main/AutoUpdater.ts index 550e90b..6b9cd48 100644 --- a/src/main/AutoUpdater.ts +++ b/src/main/AutoUpdater.ts @@ -17,6 +17,14 @@ export class AutoUpdater { autoUpdater.allowPrerelease = false autoUpdater.channel = 'latest' + // 如果是私有仓库,设置认证信息 + if (process.env.GH_TOKEN || process.env.GITHUB_TOKEN) { + // 使用环境变量中的令牌 + autoUpdater.requestHeaders = { + 'Authorization': `token ${process.env.GH_TOKEN || process.env.GITHUB_TOKEN}` + } + } + // 设置事件监听器 this.setupEventListeners() } diff --git a/src/main/IPCs.ts b/src/main/IPCs.ts index d72290f..7cc84c3 100644 --- a/src/main/IPCs.ts +++ b/src/main/IPCs.ts @@ -57,13 +57,37 @@ export default class IPCs { if (!dialogResult.canceled && dialogResult.filePaths.length > 0) { return { canceled: false, - filePath: dialogResult.filePaths[0] + filePath: dialogResult.filePaths[0], + isDirectory: true } } return { canceled: true } }) + // Select file or directory + ipcMain.handle('msgSelectFileOrFolder', async () => { + const dialogResult = await dialog.showOpenDialog({ + properties: ['openFile', 'openDirectory'] + }) + + if (!dialogResult.canceled && dialogResult.filePaths.length > 0) { + const filePath = dialogResult.filePaths[0]; + const fs = require('fs'); + const isDirectory = fs.statSync(filePath).isDirectory(); + + return { + canceled: false, + filePath: filePath, + isDirectory: isDirectory + } + } + + return { canceled: true } + }) + + + // Find all files in a folder recursively ipcMain.handle( 'msgFindFilesInFolder', @@ -71,16 +95,16 @@ export default class IPCs { try { const { readdirSync, statSync } = require('fs') const { join } = require('path') - + const foundFiles: string[] = [] - + const searchFiles = (dir: string) => { const items = readdirSync(dir) - + for (const item of items) { const fullPath = join(dir, item) const stats = statSync(fullPath) - + if (stats.isDirectory()) { // Recursively search in subdirectories searchFiles(fullPath) @@ -90,9 +114,9 @@ export default class IPCs { } } } - + searchFiles(folderPath) - + return foundFiles } catch (error) { console.error('Error finding files in folder:', error) @@ -188,21 +212,21 @@ export default class IPCs { } return allNodes; }; - + // Collect all nodes from the tree structure if (template.treeStructure && template.treeStructure.length > 0) { const allNodes = collectAllNodes(template.treeStructure); - + // Process all nodes, making sure directories are created before files for (const node of allNodes) { const nodePath = join(baseDirPath, node.path); - + if (node.type === 'directory') { ensureDirSync(nodePath); } else if (node.type === 'file') { const fileDir = dirname(nodePath); ensureDirSync(fileDir); - + if (node.sourceFilePath) { // Copy from source file const sourceContent = readFileSync(node.sourceFilePath); diff --git a/src/preload/index.ts b/src/preload/index.ts index b707727..73bdeab 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -11,6 +11,7 @@ const mainAvailChannels: string[] = [ 'msgOpenExternalLink', 'msgOpenFile', 'msgSelectDirectory', + 'msgSelectFileOrFolder', 'msgLoadData', 'msgSaveData', 'msgExecuteTemplate', diff --git a/src/renderer/components/layout/HeaderLayout.vue b/src/renderer/components/layout/HeaderLayout.vue index 7118a20..0df88a9 100644 --- a/src/renderer/components/layout/HeaderLayout.vue +++ b/src/renderer/components/layout/HeaderLayout.vue @@ -36,7 +36,9 @@ const headerMenus: {