Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
470772341f | ||
|
675f00b8a0 | ||
|
ae52803aec | ||
|
fb8cf78958 |
34
.github/workflows/electron.yml
vendored
Normal file
34
.github/workflows/electron.yml
vendored
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ build ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
environment: build
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [macos-11]
|
||||||
|
platform: [
|
||||||
|
build-mac,
|
||||||
|
build-mac-arm,
|
||||||
|
build-win
|
||||||
|
]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js 14.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 14.x
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GH_PAT }}
|
||||||
|
run: ./cmd electron ${{ matrix.platform }}
|
||||||
|
|
20
cmd
20
cmd
@ -87,7 +87,7 @@ run_compile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_electron() {
|
run_electron() {
|
||||||
local type=$1
|
local argv=$@
|
||||||
check_node
|
check_node
|
||||||
if [ ! -d "./electron/node_modules" ]; then
|
if [ ! -d "./electron/node_modules" ]; then
|
||||||
pushd electron
|
pushd electron
|
||||||
@ -97,11 +97,7 @@ run_electron() {
|
|||||||
if [ -d "./electron/dist" ]; then
|
if [ -d "./electron/dist" ]; then
|
||||||
rm -rf "./electron/dist"
|
rm -rf "./electron/dist"
|
||||||
fi
|
fi
|
||||||
if [ "$type" = "prod" ]; then
|
node ./electron/build.js $argv
|
||||||
node ./electron/build.js --build
|
|
||||||
else
|
|
||||||
node ./electron/build.js
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_exec() {
|
run_exec() {
|
||||||
@ -200,8 +196,10 @@ env_init() {
|
|||||||
####################################################################################
|
####################################################################################
|
||||||
####################################################################################
|
####################################################################################
|
||||||
|
|
||||||
check_docker
|
if [[ "$1" != "electron" ]]; then
|
||||||
env_init
|
check_docker
|
||||||
|
env_init
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [ $# -gt 0 ]; then
|
||||||
if [[ "$1" == "init" ]] || [[ "$1" == "install" ]]; then
|
if [[ "$1" == "init" ]] || [[ "$1" == "install" ]]; then
|
||||||
@ -260,11 +258,7 @@ if [ $# -gt 0 ]; then
|
|||||||
run_compile prod
|
run_compile prod
|
||||||
elif [[ "$1" == "electron" ]]; then
|
elif [[ "$1" == "electron" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
if [[ "$@" == "dev" ]]; then
|
run_electron $@
|
||||||
run_electron dev
|
|
||||||
else
|
|
||||||
run_electron prod
|
|
||||||
fi
|
|
||||||
elif [[ "$1" == "doc" ]]; then
|
elif [[ "$1" == "doc" ]]; then
|
||||||
shift 1
|
shift 1
|
||||||
run_exec php "php app/Http/Controllers/Api/apidoc.php"
|
run_exec php "php app/Http/Controllers/Api/apidoc.php"
|
||||||
|
104
electron/build.js
vendored
104
electron/build.js
vendored
@ -1,5 +1,4 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const fse = require('fs-extra')
|
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const inquirer = require('inquirer');
|
const inquirer = require('inquirer');
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
@ -103,19 +102,57 @@ function rightExists(string, find) {
|
|||||||
const electronDir = path.resolve(__dirname, "public");
|
const electronDir = path.resolve(__dirname, "public");
|
||||||
const nativeCachePath = path.resolve(__dirname, ".native");
|
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"];
|
||||||
|
|
||||||
if (argv[2] === "--build") {
|
// 编译网站
|
||||||
|
function step1() {
|
||||||
if (fs.existsSync(electronDir)) {
|
if (fs.existsSync(electronDir)) {
|
||||||
deleteFile(electronDir);
|
deleteFile(electronDir);
|
||||||
}
|
}
|
||||||
fs.mkdirSync(electronDir);
|
fs.mkdirSync(electronDir);
|
||||||
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
||||||
|
//
|
||||||
|
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||||
|
}
|
||||||
|
|
||||||
const platform = ["build-mac-intel", "build-mac-m1", "build-win"];
|
// 生成配置、编译应用
|
||||||
|
function step2(data) {
|
||||||
|
let systemInfo = `window.systemInformation = {
|
||||||
|
version: "${config.version}",
|
||||||
|
origin: "./",
|
||||||
|
apiUrl: "${formatUrl(data.url)}api/"
|
||||||
|
}`;
|
||||||
|
fs.writeFileSync(electronDir + "/config.js", systemInfo, 'utf8');
|
||||||
|
fs.writeFileSync(nativeCachePath, formatUrl(data.url));
|
||||||
|
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
||||||
|
//
|
||||||
|
let packageFile = path.resolve(__dirname, "package.json");
|
||||||
|
let packageString = fs.readFileSync(packageFile, 'utf8');
|
||||||
|
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${data.name}"`);
|
||||||
|
packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${data.id}"`);
|
||||||
|
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
||||||
|
packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "' + getDomain(data.url) + '-${version}-${os}-${arch}.${ext}"');
|
||||||
|
fs.writeFileSync(packageFile, packageString, 'utf8');
|
||||||
|
//
|
||||||
|
child_process.spawnSync("npm", ["run", data.platform], {stdio: "inherit", cwd: "electron"});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 还原配置
|
||||||
|
function step3() {
|
||||||
|
let packageFile = path.resolve(__dirname, "package.json");
|
||||||
|
let packageString = fs.readFileSync(packageFile, 'utf8');
|
||||||
|
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
||||||
|
packageString = packageString.replace(/"appId":\s*"(.*?)"/, `"appId": "${config.app.id}"`);
|
||||||
|
packageString = packageString.replace(/"artifactName":\s*"(.*?)"/g, '"artifactName": "${productName}-${version}-${os}-${arch}.${ext}"');
|
||||||
|
fs.writeFileSync(packageFile, packageString, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (["build", "prod"].includes(argv[2])) {
|
||||||
|
// 自定义编译
|
||||||
const questions = [
|
const questions = [
|
||||||
{
|
{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'targetUrl',
|
name: 'website',
|
||||||
message: "请输入网站地址",
|
message: "请输入网站地址",
|
||||||
default: () => {
|
default: () => {
|
||||||
if (fs.existsSync(nativeCachePath)) {
|
if (fs.existsSync(nativeCachePath)) {
|
||||||
@ -135,10 +172,10 @@ if (argv[2] === "--build") {
|
|||||||
name: 'platform',
|
name: 'platform',
|
||||||
message: "选择编译系统平台",
|
message: "选择编译系统平台",
|
||||||
choices: [{
|
choices: [{
|
||||||
name: "MacOS Intel",
|
name: "MacOS",
|
||||||
value: [platform[0]]
|
value: [platform[0]]
|
||||||
}, {
|
}, {
|
||||||
name: "MacOS M1",
|
name: "MacOS arm64",
|
||||||
value: [platform[1]]
|
value: [platform[1]]
|
||||||
}, {
|
}, {
|
||||||
name: "Window x86_64",
|
name: "Window x86_64",
|
||||||
@ -149,43 +186,30 @@ if (argv[2] === "--build") {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
inquirer.prompt(questions).then(answers => {
|
inquirer.prompt(questions).then(answers => {
|
||||||
let data = `window.systemInformation = {
|
step1();
|
||||||
version: "${config.version}",
|
answers.platform.forEach(platform => {
|
||||||
origin: "./",
|
step2({
|
||||||
apiUrl: "${formatUrl(answers.targetUrl)}api/"
|
"name": config.name,
|
||||||
}`;
|
"id": config.app.id,
|
||||||
fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl));
|
"url": answers.website,
|
||||||
fs.writeFileSync(electronDir + "/config.js", data, 'utf8');
|
"platform": platform
|
||||||
//
|
})
|
||||||
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
});
|
||||||
let packageFile = path.resolve(__dirname, "package.json");
|
step3();
|
||||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
|
||||||
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
|
||||||
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
|
||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
|
||||||
//
|
|
||||||
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
|
||||||
answers.platform.forEach(arg => {
|
|
||||||
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 if (platform.includes(argv[2])) {
|
||||||
|
// 自动编译
|
||||||
|
step1();
|
||||||
|
config.app.sites.forEach((data) => {
|
||||||
|
if (data.name && data.id && data.url) {
|
||||||
|
data.platform = argv[2];
|
||||||
|
step2(data)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
step3();
|
||||||
} else {
|
} else {
|
||||||
|
// 开发模式
|
||||||
fs.writeFileSync(devloadCachePath, formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8');
|
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("mix", ["watch", "--hot", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||||
child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"});
|
child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "DooTask",
|
"name": "DooTask",
|
||||||
"version": "0.3.99",
|
"version": "0.4.0",
|
||||||
"description": "DooTask is task management system.",
|
"description": "DooTask is task management system.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -8,13 +8,22 @@
|
|||||||
"start": "electron-forge start",
|
"start": "electron-forge start",
|
||||||
"start-quiet": "sleep 3 && electron-forge start &> /dev/null",
|
"start-quiet": "sleep 3 && electron-forge start &> /dev/null",
|
||||||
"build": "electron-builder",
|
"build": "electron-builder",
|
||||||
"build-mac-intel": "electron-builder --mac",
|
"build-mac": "electron-builder --mac",
|
||||||
"build-mac-m1": "electron-builder --mac --arm64",
|
"build-mac-arm": "electron-builder --mac --arm64",
|
||||||
"build-win": "electron-builder --win",
|
"build-win": "electron-builder --win",
|
||||||
"package": "electron-forge package",
|
"package": "electron-forge package",
|
||||||
"make": "electron-forge make",
|
"make": "electron-forge make",
|
||||||
"publish": "electron-forge publish"
|
"publish": "electron-forge publish"
|
||||||
},
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "KuaiFan",
|
||||||
|
"email": "aipaw@live.cn",
|
||||||
|
"url": "https://github.com/kuaifan"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/kuaifan/dootask.git"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-forge/cli": "^6.0.0-beta.61",
|
"@electron-forge/cli": "^6.0.0-beta.61",
|
||||||
"@electron-forge/maker-deb": "^6.0.0-beta.61",
|
"@electron-forge/maker-deb": "^6.0.0-beta.61",
|
||||||
@ -32,16 +41,27 @@
|
|||||||
"xlsx": "^0.17.2"
|
"xlsx": "^0.17.2"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
|
"appId": "com.dootask.task",
|
||||||
|
"artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
|
||||||
"files": [
|
"files": [
|
||||||
"public",
|
"public",
|
||||||
"main.js",
|
"main.js",
|
||||||
"preload.js"
|
"preload.js"
|
||||||
],
|
],
|
||||||
"mac": {
|
"mac": {
|
||||||
"icon": "../resources/assets/statics/public/images/logo-app.png"
|
"icon": "../resources/assets/statics/public/images/logo-app.png",
|
||||||
|
"target": "dmg",
|
||||||
|
"publish": ["github"]
|
||||||
},
|
},
|
||||||
"win": {
|
"win": {
|
||||||
"icon": "../resources/assets/statics/public/images/logo-app.ico"
|
"icon": "../resources/assets/statics/public/images/logo-app.ico",
|
||||||
|
"target": ["tar.gz", "nsis"],
|
||||||
|
"publish": ["github"]
|
||||||
|
},
|
||||||
|
"nsis": {
|
||||||
|
"oneClick": false,
|
||||||
|
"artifactName": "${productName}-${version}-${os}-${arch}.${ext}",
|
||||||
|
"allowToChangeInstallationDirectory": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
26
package.json
26
package.json
@ -1,12 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "DooTask",
|
"name": "DooTask",
|
||||||
"version": "0.3.99",
|
"version": "0.4.0",
|
||||||
"description": "DooTask is task management system.",
|
"description": "DooTask is task management system.",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./cmd dev",
|
"start": "./cmd dev",
|
||||||
"build": "./cmd prod",
|
"build": "./cmd prod",
|
||||||
"version": "node ./version.js"
|
"version": "node ./version.js"
|
||||||
},
|
},
|
||||||
|
"app": {
|
||||||
|
"id": "com.dootask.task",
|
||||||
|
"sites": [
|
||||||
|
{
|
||||||
|
"name": "DooTask",
|
||||||
|
"id": "com.dootask.task",
|
||||||
|
"url": "https://www.dootask.com/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "HitoseaTask",
|
||||||
|
"id": "com.hitosea.task",
|
||||||
|
"url": "https://t.hitosea.com/"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"author": {
|
||||||
|
"name": "KuaiFan",
|
||||||
|
"email": "aipaw@live.cn",
|
||||||
|
"url": "https://github.com/kuaifan"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/kuaifan/dootask.git"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"axios": "^0.21",
|
"axios": "^0.21",
|
||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
|
6
version.js
vendored
6
version.js
vendored
@ -2,6 +2,7 @@ const fs = require('fs');
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const exec = require('child_process').exec;
|
const exec = require('child_process').exec;
|
||||||
const packageFile = path.resolve(process.cwd(), "package.json");
|
const packageFile = path.resolve(process.cwd(), "package.json");
|
||||||
|
const packageElectronFile = path.resolve(process.cwd(), "electron/package.json");
|
||||||
|
|
||||||
function runExec(command, cb) {
|
function runExec(command, cb) {
|
||||||
exec(command, function (err, stdout, stderr) {
|
exec(command, function (err, stdout, stderr) {
|
||||||
@ -26,7 +27,12 @@ runExec("git rev-list --all --count", function (err, response) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let ver = Math.floor(num / 10000) + "." + Math.floor(num / 100) + "." + Math.floor(num % 100)
|
let ver = Math.floor(num / 10000) + "." + Math.floor(num / 100) + "." + Math.floor(num % 100)
|
||||||
|
//
|
||||||
let newResult = fs.readFileSync(packageFile, 'utf8').replace(/"version":\s*"(.*?)"/, `"version": "${ver}"`);
|
let newResult = fs.readFileSync(packageFile, 'utf8').replace(/"version":\s*"(.*?)"/, `"version": "${ver}"`);
|
||||||
fs.writeFileSync(packageFile, newResult, 'utf8');
|
fs.writeFileSync(packageFile, newResult, 'utf8');
|
||||||
|
//
|
||||||
|
let newElectronResult = fs.readFileSync(packageElectronFile, 'utf8').replace(/"version":\s*"(.*?)"/, `"version": "${ver}"`);
|
||||||
|
fs.writeFileSync(packageElectronFile, newElectronResult, 'utf8');
|
||||||
|
//
|
||||||
console.log("new version: " + ver);
|
console.log("new version: " + ver);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user