优化electron脚本命令
This commit is contained in:
parent
a7ac2cee13
commit
26d9e63e83
18
.github/workflows/electron.yml
vendored
18
.github/workflows/electron.yml
vendored
@ -14,20 +14,20 @@ jobs:
|
|||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Build Changelog
|
- name: Create changelog text
|
||||||
id: github_release
|
id: changelog
|
||||||
uses: mikepenz/release-changelog-builder-action@v1
|
uses: loopwerk/tag-changelog@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GH_PAT }}
|
||||||
|
|
||||||
|
- name: Create release
|
||||||
|
uses: actions/create-release@latest
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
||||||
|
|
||||||
- name: Create Release
|
|
||||||
uses: actions/create-release@v1
|
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ github.ref }}
|
tag_name: ${{ github.ref }}
|
||||||
release_name: Release ${{ github.ref }}
|
release_name: Release ${{ github.ref }}
|
||||||
body: ${{steps.github_release.outputs.changelog}}
|
body: ${{ steps.changelog.outputs.changes }}
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
22
cmd
22
cmd
@ -66,7 +66,6 @@ docker_name() {
|
|||||||
|
|
||||||
run_compile() {
|
run_compile() {
|
||||||
local type=$1
|
local type=$1
|
||||||
local npxcmd=""
|
|
||||||
check_node
|
check_node
|
||||||
if [ ! -d "./node_modules" ]; then
|
if [ ! -d "./node_modules" ]; then
|
||||||
npm install
|
npm install
|
||||||
@ -74,29 +73,38 @@ run_compile() {
|
|||||||
run_exec php "php bin/run --mode=$type"
|
run_exec php "php bin/run --mode=$type"
|
||||||
supervisorctl_restart php
|
supervisorctl_restart php
|
||||||
#
|
#
|
||||||
mix -V &> /dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
npxcmd="npx"
|
|
||||||
fi
|
|
||||||
if [ "$type" = "prod" ]; then
|
if [ "$type" = "prod" ]; then
|
||||||
rm -rf "./public/js/build"
|
rm -rf "./public/js/build"
|
||||||
$npxcmd mix --production
|
npx mix --production
|
||||||
else
|
else
|
||||||
$npxcmd mix watch --hot
|
npx mix watch --hot
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
run_electron() {
|
run_electron() {
|
||||||
local argv=$@
|
local argv=$@
|
||||||
check_node
|
check_node
|
||||||
|
if [ ! -d "./node_modules" ]; then
|
||||||
|
npm install
|
||||||
|
fi
|
||||||
if [ ! -d "./electron/node_modules" ]; then
|
if [ ! -d "./electron/node_modules" ]; then
|
||||||
pushd electron
|
pushd electron
|
||||||
npm install
|
npm install
|
||||||
popd
|
popd
|
||||||
fi
|
fi
|
||||||
|
#
|
||||||
if [ -d "./electron/dist" ]; then
|
if [ -d "./electron/dist" ]; then
|
||||||
rm -rf "./electron/dist"
|
rm -rf "./electron/dist"
|
||||||
fi
|
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
|
node ./electron/build.js $argv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
69
electron/build.js
vendored
69
electron/build.js
vendored
@ -104,19 +104,8 @@ const nativeCachePath = path.resolve(__dirname, ".native");
|
|||||||
const devloadCachePath = path.resolve(__dirname, ".devload");
|
const devloadCachePath = path.resolve(__dirname, ".devload");
|
||||||
const platform = ["build-mac", "build-mac-arm", "build-win"];
|
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 = {
|
let systemInfo = `window.systemInformation = {
|
||||||
version: "${config.version}",
|
version: "${config.version}",
|
||||||
origin: "./",
|
origin: "./",
|
||||||
@ -138,7 +127,7 @@ function step2(data, publish) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 还原配置
|
// 还原配置
|
||||||
function step3() {
|
function step2() {
|
||||||
let packageFile = path.resolve(__dirname, "package.json");
|
let packageFile = path.resolve(__dirname, "package.json");
|
||||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
let packageString = fs.readFileSync(packageFile, 'utf8');
|
||||||
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
||||||
@ -147,7 +136,21 @@ function step3() {
|
|||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
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 = [
|
const questions = [
|
||||||
{
|
{
|
||||||
@ -187,36 +190,16 @@ if (["build", "prod"].includes(argv[2])) {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
inquirer.prompt(questions).then(answers => {
|
inquirer.prompt(questions).then(answers => {
|
||||||
step1();
|
answers.platform.forEach(platform => {
|
||||||
setTimeout(() => {
|
step1({
|
||||||
answers.platform.forEach(platform => {
|
"name": config.name,
|
||||||
step2({
|
"id": config.app.id,
|
||||||
"name": config.name,
|
"url": answers.website,
|
||||||
"id": config.app.id,
|
"platform": platform
|
||||||
"url": answers.website,
|
}, false)
|
||||||
"platform": platform
|
});
|
||||||
}, false)
|
step2();
|
||||||
});
|
|
||||||
step3();
|
|
||||||
}, 3000)
|
|
||||||
});
|
});
|
||||||
} 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"});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
"appId": "com.dootask.task",
|
"appId": "com.dootask.task",
|
||||||
"artifactName": "${productName}-v${version}-${os}-${arch}.${ext}",
|
"artifactName": "${productName}-v${version}-${os}-${arch}.${ext}",
|
||||||
"files": [
|
"files": [
|
||||||
"public",
|
"public/**/*",
|
||||||
"main.js",
|
"main.js",
|
||||||
"preload.js"
|
"preload.js"
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user