From 26d9e63e83a7f0b01ca40be889829cda89a824da Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 22 Dec 2021 12:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96electron=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/electron.yml | 18 ++++----- cmd | 22 +++++++---- electron/build.js | 69 +++++++++++++--------------------- electron/package.json | 2 +- 4 files changed, 51 insertions(+), 60 deletions(-) diff --git a/.github/workflows/electron.yml b/.github/workflows/electron.yml index 8d1649ff..9c5ab25d 100644 --- a/.github/workflows/electron.yml +++ b/.github/workflows/electron.yml @@ -14,20 +14,20 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Build Changelog - id: github_release - uses: mikepenz/release-changelog-builder-action@v1 + - name: Create changelog text + id: changelog + uses: loopwerk/tag-changelog@v1 + with: + token: ${{ secrets.GH_PAT }} + + - name: Create release + uses: actions/create-release@latest env: GITHUB_TOKEN: ${{ secrets.GH_PAT }} - - - name: Create Release - uses: actions/create-release@v1 with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} - body: ${{steps.github_release.outputs.changelog}} - env: - GITHUB_TOKEN: ${{ secrets.GH_PAT }} + body: ${{ steps.changelog.outputs.changes }} build: runs-on: ${{ matrix.os }} diff --git a/cmd b/cmd index d34516cb..551598b0 100755 --- a/cmd +++ b/cmd @@ -66,7 +66,6 @@ docker_name() { run_compile() { local type=$1 - local npxcmd="" check_node if [ ! -d "./node_modules" ]; then npm install @@ -74,29 +73,38 @@ run_compile() { run_exec php "php bin/run --mode=$type" supervisorctl_restart php # - mix -V &> /dev/null - if [ $? -ne 0 ]; then - npxcmd="npx" - fi if [ "$type" = "prod" ]; then rm -rf "./public/js/build" - $npxcmd mix --production + npx mix --production else - $npxcmd mix watch --hot + npx mix watch --hot fi } run_electron() { local argv=$@ check_node + if [ ! -d "./node_modules" ]; then + npm install + fi if [ ! -d "./electron/node_modules" ]; then pushd electron npm install popd fi + # if [ -d "./electron/dist" ]; then rm -rf "./electron/dist" fi + if [ -d "./electron/public" ]; then + rm -rf "./electron/public" + fi + mkdir -p ./electron/public + cp ./electron/index.html ./electron/public/index.html + # + if [ "$argv" != "dev" ]; then + npx mix --production -- --env --electron + fi node ./electron/build.js $argv } diff --git a/electron/build.js b/electron/build.js index 9d47cd87..328bad5a 100644 --- a/electron/build.js +++ b/electron/build.js @@ -104,19 +104,8 @@ const nativeCachePath = path.resolve(__dirname, ".native"); const devloadCachePath = path.resolve(__dirname, ".devload"); const platform = ["build-mac", "build-mac-arm", "build-win"]; -// 编译网站 -function step1() { - if (fs.existsSync(electronDir)) { - deleteFile(electronDir); - } - fs.mkdirSync(electronDir); - copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html") - // - child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"}); -} - // 生成配置、编译应用 -function step2(data, publish) { +function step1(data, publish) { let systemInfo = `window.systemInformation = { version: "${config.version}", origin: "./", @@ -138,7 +127,7 @@ function step2(data, publish) { } // 还原配置 -function step3() { +function step2() { let packageFile = path.resolve(__dirname, "package.json"); let packageString = fs.readFileSync(packageFile, 'utf8'); packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`); @@ -147,7 +136,21 @@ function step3() { fs.writeFileSync(packageFile, packageString, 'utf8'); } -if (["build", "prod"].includes(argv[2])) { +if (["dev"].includes(argv[2])) { + // 开发模式 + fs.writeFileSync(devloadCachePath, formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8'); + child_process.spawn("npx", ["mix", "watch", "--hot", "--", "--env", "--electron"], {stdio: "inherit"}); + child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"}); +} else if (platform.includes(argv[2])) { + // 自动编译 + config.app.sites.forEach((data) => { + if (data.name && data.id && data.url) { + data.platform = argv[2]; + step1(data, true) + } + }) + step2(); +} else { // 自定义编译 const questions = [ { @@ -187,36 +190,16 @@ if (["build", "prod"].includes(argv[2])) { } ]; inquirer.prompt(questions).then(answers => { - step1(); - setTimeout(() => { - answers.platform.forEach(platform => { - step2({ - "name": config.name, - "id": config.app.id, - "url": answers.website, - "platform": platform - }, false) - }); - step3(); - }, 3000) + answers.platform.forEach(platform => { + step1({ + "name": config.name, + "id": config.app.id, + "url": answers.website, + "platform": platform + }, false) + }); + step2(); }); -} else if (platform.includes(argv[2])) { - // 自动编译 - step1(); - setTimeout(() => { - config.app.sites.forEach((data) => { - if (data.name && data.id && data.url) { - data.platform = argv[2]; - step2(data) - } - }) - step3(); - }, 3000); -} else { - // 开发模式 - fs.writeFileSync(devloadCachePath, formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8'); - child_process.spawn("mix", ["watch", "--hot", "--", "--env", "--electron"], {stdio: "inherit"}); - child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"}); } diff --git a/electron/package.json b/electron/package.json index c595af6b..14d3ca8e 100644 --- a/electron/package.json +++ b/electron/package.json @@ -47,7 +47,7 @@ "appId": "com.dootask.task", "artifactName": "${productName}-v${version}-${os}-${arch}.${ext}", "files": [ - "public", + "public/**/*", "main.js", "preload.js" ],