Skip to content

Commit

Permalink
优化electron命令
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Dec 14, 2021
1 parent cb792cb commit 32c2d60
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
25 changes: 25 additions & 0 deletions cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions electron/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
public/
package-lock.json

build/
dist/

.devload
Expand Down
29 changes: 27 additions & 2 deletions electron/build.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 32c2d60

Please sign in to comment.