no message
This commit is contained in:
parent
3a7e4a05cc
commit
83b5140b48
1
electron/.gitignore
vendored
1
electron/.gitignore
vendored
@ -4,4 +4,5 @@ package-lock.json
|
|||||||
|
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
|
.devload
|
||||||
.native
|
.native
|
||||||
|
211
electron/build.js
vendored
211
electron/build.js
vendored
@ -1,17 +1,22 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
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');
|
||||||
const config = require('../package.json')
|
const config = require('../package.json')
|
||||||
|
const argv = process.argv;
|
||||||
|
const env = require('dotenv').config({ path: './.env' })
|
||||||
|
|
||||||
// 删除
|
/**
|
||||||
|
* 删除目录及文件
|
||||||
|
* @param path
|
||||||
|
*/
|
||||||
function deleteFile(path) {
|
function deleteFile(path) {
|
||||||
let files = [];
|
let files = [];
|
||||||
if( fs.existsSync(path) ) {
|
if (fs.existsSync(path)) {
|
||||||
files = fs.readdirSync(path);
|
files = fs.readdirSync(path);
|
||||||
files.forEach(function(file,index){
|
files.forEach(function (file, index) {
|
||||||
let curPath = path + "/" + file;
|
let curPath = path + "/" + file;
|
||||||
if(fs.statSync(curPath).isDirectory()) {
|
if (fs.statSync(curPath).isDirectory()) {
|
||||||
deleteFile(curPath);
|
deleteFile(curPath);
|
||||||
} else {
|
} else {
|
||||||
fs.unlinkSync(curPath);
|
fs.unlinkSync(curPath);
|
||||||
@ -21,7 +26,12 @@ function deleteFile(path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制文件
|
/**
|
||||||
|
* 复制文件
|
||||||
|
* @param srcPath
|
||||||
|
* @param tarPath
|
||||||
|
* @param cb
|
||||||
|
*/
|
||||||
function copyFile(srcPath, tarPath, cb) {
|
function copyFile(srcPath, tarPath, cb) {
|
||||||
let rs = fs.createReadStream(srcPath)
|
let rs = fs.createReadStream(srcPath)
|
||||||
rs.on('error', function (err) {
|
rs.on('error', function (err) {
|
||||||
@ -43,48 +53,11 @@ function copyFile(srcPath, tarPath, cb) {
|
|||||||
rs.pipe(ws)
|
rs.pipe(ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制文件夹所有
|
/**
|
||||||
function copyDir(srcDir, tarDir, cb) {
|
* 给地址加上前后
|
||||||
if (fs.existsSync(tarDir)) {
|
* @param str
|
||||||
fs.readdir(srcDir, function (err, files) {
|
* @returns {string}
|
||||||
let count = 0
|
*/
|
||||||
let checkEnd = function () {
|
|
||||||
++count == files.length && cb && cb()
|
|
||||||
}
|
|
||||||
if (err) {
|
|
||||||
checkEnd()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
files.forEach(function (file) {
|
|
||||||
let srcPath = path.join(srcDir, file)
|
|
||||||
let tarPath = path.join(tarDir, file)
|
|
||||||
fs.stat(srcPath, function (err, stats) {
|
|
||||||
if (stats.isDirectory()) {
|
|
||||||
fs.mkdir(tarPath, function (err) {
|
|
||||||
if (err) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
copyDir(srcPath, tarPath, checkEnd)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
copyFile(srcPath, tarPath, checkEnd)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
//为空时直接回调
|
|
||||||
files.length === 0 && cb && cb()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
fs.mkdir(tarDir, function (err) {
|
|
||||||
if (err) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
copyDir(srcDir, tarDir, cb)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 给地址加上前后
|
|
||||||
function formatUrl(str) {
|
function formatUrl(str) {
|
||||||
let url;
|
let url;
|
||||||
if (str.substring(0, 7) === "http://" ||
|
if (str.substring(0, 7) === "http://" ||
|
||||||
@ -94,97 +67,89 @@ function formatUrl(str) {
|
|||||||
url = "http://" + str.trim();
|
url = "http://" + str.trim();
|
||||||
}
|
}
|
||||||
if (url.substring(url.length - 1) != "/") {
|
if (url.substring(url.length - 1) != "/") {
|
||||||
url+= "/"
|
url += "/"
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 运行命令
|
|
||||||
function exec(command, quiet) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
let child = child_process.exec(command, {encoding: 'utf8'}, () => {
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
if (!quiet) {
|
|
||||||
child.stdout.pipe(process.stdout);
|
|
||||||
}
|
|
||||||
child.stderr.pipe(process.stderr);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('execute command failed :', command);
|
|
||||||
reject(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ***************************************************************************************************/
|
/** ***************************************************************************************************/
|
||||||
/** ***************************************************************************************************/
|
/** ***************************************************************************************************/
|
||||||
/** ***************************************************************************************************/
|
/** ***************************************************************************************************/
|
||||||
|
|
||||||
const electronDir = path.resolve(__dirname, "public");
|
const electronDir = path.resolve(__dirname, "public");
|
||||||
const nativeCachePath = path.resolve(__dirname, ".native");
|
const nativeCachePath = path.resolve(__dirname, ".native");
|
||||||
if (fs.existsSync(electronDir)) {
|
const devloadCachePath = path.resolve(__dirname, ".devload");
|
||||||
deleteFile(electronDir);
|
|
||||||
}
|
|
||||||
fs.mkdirSync(electronDir);
|
|
||||||
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
|
||||||
|
|
||||||
const platform = ["build-mac-intel", "build-mac-m1", "build-win"];
|
if (argv[2] === "--build") {
|
||||||
const questions = [
|
if (fs.existsSync(electronDir)) {
|
||||||
{
|
deleteFile(electronDir);
|
||||||
type: 'input',
|
|
||||||
name: 'targetUrl',
|
|
||||||
message: "请输入网站地址",
|
|
||||||
default: () => {
|
|
||||||
if (fs.existsSync(nativeCachePath)) {
|
|
||||||
return fs.readFileSync(nativeCachePath, 'utf8');
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
validate: function (value) {
|
|
||||||
return value !== ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'list',
|
|
||||||
name: 'platform',
|
|
||||||
message: "选择编译系统平台",
|
|
||||||
choices: [{
|
|
||||||
name: "MacOS Intel",
|
|
||||||
value: [platform[0]]
|
|
||||||
}, {
|
|
||||||
name: "MacOS M1",
|
|
||||||
value: [platform[1]]
|
|
||||||
}, {
|
|
||||||
name: "Window x86_64",
|
|
||||||
value: [platform[2]]
|
|
||||||
}, {
|
|
||||||
name: "All platforms",
|
|
||||||
value: platform
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
];
|
fs.mkdirSync(electronDir);
|
||||||
|
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
||||||
|
|
||||||
inquirer.prompt(questions).then(answers => {
|
const platform = ["build-mac-intel", "build-mac-m1", "build-win"];
|
||||||
let data = `window.systemInformation = {
|
const questions = [
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
name: 'targetUrl',
|
||||||
|
message: "请输入网站地址",
|
||||||
|
default: () => {
|
||||||
|
if (fs.existsSync(nativeCachePath)) {
|
||||||
|
return fs.readFileSync(nativeCachePath, 'utf8');
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
},
|
||||||
|
validate: function (value) {
|
||||||
|
return value !== ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'list',
|
||||||
|
name: 'platform',
|
||||||
|
message: "选择编译系统平台",
|
||||||
|
choices: [{
|
||||||
|
name: "MacOS Intel",
|
||||||
|
value: [platform[0]]
|
||||||
|
}, {
|
||||||
|
name: "MacOS M1",
|
||||||
|
value: [platform[1]]
|
||||||
|
}, {
|
||||||
|
name: "Window x86_64",
|
||||||
|
value: [platform[2]]
|
||||||
|
}, {
|
||||||
|
name: "All platforms",
|
||||||
|
value: platform
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
inquirer.prompt(questions).then(answers => {
|
||||||
|
let data = `window.systemInformation = {
|
||||||
version: "${config.version}",
|
version: "${config.version}",
|
||||||
origin: "./",
|
origin: "./",
|
||||||
apiUrl: "${formatUrl(answers.targetUrl)}api/"
|
apiUrl: "${formatUrl(answers.targetUrl)}api/"
|
||||||
}`;
|
}`;
|
||||||
fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl));
|
fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl));
|
||||||
fs.writeFileSync(electronDir + "/config.js", data, 'utf8');
|
fs.writeFileSync(electronDir + "/config.js", data, 'utf8');
|
||||||
//
|
//
|
||||||
let packageFile = path.resolve(__dirname, "package.json");
|
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
||||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
let packageFile = path.resolve(__dirname, "package.json");
|
||||||
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
let packageString = fs.readFileSync(packageFile, 'utf8');
|
||||||
packageString = packageString.replace(/"name":\s*"(.*?)"/, `"name": "${config.name}"`);
|
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
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(item => {
|
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||||
child_process.spawn("npm", ["run", item], {stdio: "inherit", cwd: "electron"});
|
answers.platform.forEach(arg => {
|
||||||
})
|
child_process.spawn("npm", ["run", arg], {stdio: "inherit", cwd: "electron"});
|
||||||
});
|
})
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
fs.writeFileSync(devloadCachePath, formatUrl("127.0.0.1:" + env.parsed.APP_PORT), 'utf8');
|
||||||
|
child_process.spawn("mix", ["watch", "--hot"], {stdio: "inherit"});
|
||||||
|
child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
21
electron/main.js
vendored
21
electron/main.js
vendored
@ -1,6 +1,13 @@
|
|||||||
const {app, BrowserWindow} = require('electron')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
let willQuitApp = false;
|
const {app, BrowserWindow} = require('electron')
|
||||||
|
|
||||||
|
let willQuitApp = false,
|
||||||
|
devloadCachePath = path.resolve(__dirname, ".devload"),
|
||||||
|
devloadUrl = "";
|
||||||
|
if (fs.existsSync(devloadCachePath)) {
|
||||||
|
devloadUrl = fs.readFileSync(devloadCachePath, 'utf8')
|
||||||
|
}
|
||||||
|
|
||||||
function getCounterValue(title) {
|
function getCounterValue(title) {
|
||||||
const itemCountRegex = /[([{]([\d.,]*)\+?[}\])]/;
|
const itemCountRegex = /[([{]([\d.,]*)\+?[}\])]/;
|
||||||
@ -17,9 +24,15 @@ function createWindow(setDockBadge) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.loadFile('./public/index.html').then(r => {
|
if (devloadUrl) {
|
||||||
|
mainWindow.loadURL(devloadUrl).then(r => {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
mainWindow.loadFile('./public/index.html').then(r => {
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
mainWindow.on('page-title-updated', function (event, title) {
|
mainWindow.on('page-title-updated', function (event, title) {
|
||||||
const counterValue = getCounterValue(title);
|
const counterValue = getCounterValue(title);
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron-forge start",
|
"start": "electron-forge start",
|
||||||
|
"start-quiet": "electron-forge start &> /dev/null",
|
||||||
"build": "electron-builder",
|
"build": "electron-builder",
|
||||||
"build-mac-intel": "electron-builder --mac",
|
"build-mac-intel": "electron-builder --mac",
|
||||||
"build-mac-m1": "electron-builder --mac --arm64",
|
"build-mac-m1": "electron-builder --mac --arm64",
|
||||||
@ -20,6 +21,7 @@
|
|||||||
"@electron-forge/maker-rpm": "^6.0.0-beta.57",
|
"@electron-forge/maker-rpm": "^6.0.0-beta.57",
|
||||||
"@electron-forge/maker-squirrel": "^6.0.0-beta.57",
|
"@electron-forge/maker-squirrel": "^6.0.0-beta.57",
|
||||||
"@electron-forge/maker-zip": "^6.0.0-beta.57",
|
"@electron-forge/maker-zip": "^6.0.0-beta.57",
|
||||||
|
"dotenv": "^9.0.2",
|
||||||
"electron": "^13.1.6",
|
"electron": "^13.1.6",
|
||||||
"electron-builder": "^22.11.7"
|
"electron-builder": "^22.11.7"
|
||||||
},
|
},
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "./cmd dev",
|
"start": "./cmd dev",
|
||||||
"build": "./cmd prod",
|
"build": "./cmd prod",
|
||||||
"build-electron": "node ./electron/build.js",
|
"electron-start": "node ./electron/build.js",
|
||||||
|
"electron-build": "node ./electron/build.js --build",
|
||||||
"version": "node ./version.js"
|
"version": "node ./version.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
2
resources/assets/js/app.js
vendored
2
resources/assets/js/app.js
vendored
@ -52,7 +52,7 @@ VueRouter.prototype.push = function push(location) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
mode: __PLATFORM === "web" ? 'history' : 'hash',
|
mode: !__IS_WEB ? 'hash' : 'history',
|
||||||
routes
|
routes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
6
webpack.mix.js
vendored
6
webpack.mix.js
vendored
@ -21,10 +21,10 @@ if (!['--watch', '--hot'].includes(argv[3])) {
|
|||||||
output.publicPath = './';
|
output.publicPath = './';
|
||||||
}
|
}
|
||||||
|
|
||||||
let platform = "web";
|
let is_web = true;
|
||||||
let publicPath = 'public'
|
let publicPath = 'public'
|
||||||
if (argv[4] === '--electron') {
|
if (argv[4] === '--electron') {
|
||||||
platform = "electron"
|
is_web = false
|
||||||
publicPath = 'electron/public';
|
publicPath = 'electron/public';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ mix
|
|||||||
output,
|
output,
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'__PLATFORM': platform
|
'__IS_WEB': is_web,
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user