diff --git a/cmd b/cmd index 73a0d53dd..f4bc423ff 100755 --- a/cmd +++ b/cmd @@ -86,6 +86,24 @@ run_compile() { fi } +run_electron() { + local type=$1 + check_node + if [ ! -d "./electron/node_modules" ]; then + pushd electron + npm install + popd + fi + if [ -d "./electron/dist" ]; then + rm -rf "./electron/dist" + fi + if [ "$type" = "prod" ]; then + node ./electron/build.js --build + else + node ./electron/build.js + fi +} + run_exec() { local container=$1 local cmd=$2 @@ -240,6 +258,13 @@ if [ $# -gt 0 ]; then elif [[ "$1" == "prod" ]] || [[ "$1" == "production" ]]; then shift 1 run_compile prod + elif [[ "$1" == "electron" ]]; then + shift 1 + if [[ "$@" == "dev" ]]; then + run_electron dev + else + run_electron prod + fi elif [[ "$1" == "doc" ]]; then shift 1 run_exec php "php app/Http/Controllers/Api/apidoc.php" diff --git a/electron/.gitignore b/electron/.gitignore index 9d248ce8e..5a4a364a6 100644 --- a/electron/.gitignore +++ b/electron/.gitignore @@ -2,6 +2,7 @@ node_modules/ public/ package-lock.json +build/ dist/ .devload diff --git a/electron/build.js b/electron/build.js index 8c56226be..34fcf2e62 100644 --- a/electron/build.js +++ b/electron/build.js @@ -1,4 +1,5 @@ const fs = require('fs'); +const fse = require('fs-extra') const path = require('path') const inquirer = require('inquirer'); const child_process = require('child_process'); @@ -72,11 +73,21 @@ function formatUrl(str) { return url; } +/** + * 正则提取域名 + * @param weburl + * @returns {string|string} + */ +function getDomain(weburl) { + let urlReg = /http(s)?:\/\/([^\/]+)/i; + let domain = weburl.match(urlReg); + return ((domain != null && domain.length > 0) ? domain[2] : ""); +} + /** * 右边是否包含 * @param string * @param find - * @param lower * @returns {boolean} */ function rightExists(string, find) { @@ -157,7 +168,21 @@ if (argv[2] === "--build") { // child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"}); answers.platform.forEach(arg => { - child_process.spawn("npm", ["run", arg], {stdio: "inherit", cwd: "electron"}); + child_process.spawnSync("npm", ["run", arg], {stdio: "inherit", cwd: "electron"}); + let name = "" + if (arg == "build-mac-intel") { + name = config.name + "-" + config.version + ".dmg" + } else if (arg == "build-mac-m1") { + name = config.name + "-" + config.version + "-arm64.dmg" + } else if (arg == "build-win") { + name = config.name + " Setup " + config.version + ".exe" + } + if (name != "") { + fse.copySync( + path.resolve(__dirname, "dist", name), + path.resolve(__dirname, "build", getDomain(answers.targetUrl), config.version, name) + ) + } }) }); } else { diff --git a/electron/package.json b/electron/package.json index 37980f205..6c2a9eb9d 100644 --- a/electron/package.json +++ b/electron/package.json @@ -21,13 +21,14 @@ "@electron-forge/maker-rpm": "^6.0.0-beta.61", "@electron-forge/maker-squirrel": "^6.0.0-beta.61", "@electron-forge/maker-zip": "^6.0.0-beta.61", - "dmg-license": "^1.0.9", + "dmg-license": "^1.0.10", "dotenv": "^10.0.0", - "electron": "^15.0.0", - "electron-builder": "^22.11.7" + "electron": "^16.0.4", + "electron-builder": "^22.14.5" }, "dependencies": { "electron-squirrel-startup": "^1.0.0", + "fs-extra": "^10.0.0", "xlsx": "^0.17.2" }, "build": { diff --git a/package.json b/package.json index 244e2d301..88c5b6823 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,6 @@ "scripts": { "start": "./cmd dev", "build": "./cmd prod", - "electron-start": "node ./electron/build.js", - "electron-build": "node ./electron/build.js --build", "version": "node ./version.js" }, "devDependencies": {