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/
|
||||
|
||||
.devload
|
||||
.native
|
||||
|
121
electron/build.js
vendored
121
electron/build.js
vendored
@ -3,15 +3,20 @@ const path = require('path')
|
||||
const inquirer = require('inquirer');
|
||||
const child_process = require('child_process');
|
||||
const config = require('../package.json')
|
||||
const argv = process.argv;
|
||||
const env = require('dotenv').config({ path: './.env' })
|
||||
|
||||
// 删除
|
||||
/**
|
||||
* 删除目录及文件
|
||||
* @param path
|
||||
*/
|
||||
function deleteFile(path) {
|
||||
let files = [];
|
||||
if( fs.existsSync(path) ) {
|
||||
if (fs.existsSync(path)) {
|
||||
files = fs.readdirSync(path);
|
||||
files.forEach(function(file,index){
|
||||
files.forEach(function (file, index) {
|
||||
let curPath = path + "/" + file;
|
||||
if(fs.statSync(curPath).isDirectory()) {
|
||||
if (fs.statSync(curPath).isDirectory()) {
|
||||
deleteFile(curPath);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
@ -21,7 +26,12 @@ function deleteFile(path) {
|
||||
}
|
||||
}
|
||||
|
||||
// 复制文件
|
||||
/**
|
||||
* 复制文件
|
||||
* @param srcPath
|
||||
* @param tarPath
|
||||
* @param cb
|
||||
*/
|
||||
function copyFile(srcPath, tarPath, cb) {
|
||||
let rs = fs.createReadStream(srcPath)
|
||||
rs.on('error', function (err) {
|
||||
@ -43,48 +53,11 @@ function copyFile(srcPath, tarPath, cb) {
|
||||
rs.pipe(ws)
|
||||
}
|
||||
|
||||
// 复制文件夹所有
|
||||
function copyDir(srcDir, tarDir, cb) {
|
||||
if (fs.existsSync(tarDir)) {
|
||||
fs.readdir(srcDir, function (err, files) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 给地址加上前后
|
||||
/**
|
||||
* 给地址加上前后
|
||||
* @param str
|
||||
* @returns {string}
|
||||
*/
|
||||
function formatUrl(str) {
|
||||
let url;
|
||||
if (str.substring(0, 7) === "http://" ||
|
||||
@ -94,43 +67,28 @@ function formatUrl(str) {
|
||||
url = "http://" + str.trim();
|
||||
}
|
||||
if (url.substring(url.length - 1) != "/") {
|
||||
url+= "/"
|
||||
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 nativeCachePath = path.resolve(__dirname, ".native");
|
||||
if (fs.existsSync(electronDir)) {
|
||||
deleteFile(electronDir);
|
||||
}
|
||||
fs.mkdirSync(electronDir);
|
||||
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
||||
const devloadCachePath = path.resolve(__dirname, ".devload");
|
||||
|
||||
const platform = ["build-mac-intel", "build-mac-m1", "build-win"];
|
||||
const questions = [
|
||||
if (argv[2] === "--build") {
|
||||
if (fs.existsSync(electronDir)) {
|
||||
deleteFile(electronDir);
|
||||
}
|
||||
fs.mkdirSync(electronDir);
|
||||
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
||||
|
||||
const platform = ["build-mac-intel", "build-mac-m1", "build-win"];
|
||||
const questions = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'targetUrl',
|
||||
@ -163,9 +121,9 @@ const questions = [
|
||||
value: platform
|
||||
}]
|
||||
}
|
||||
];
|
||||
];
|
||||
|
||||
inquirer.prompt(questions).then(answers => {
|
||||
inquirer.prompt(questions).then(answers => {
|
||||
let data = `window.systemInformation = {
|
||||
version: "${config.version}",
|
||||
origin: "./",
|
||||
@ -174,6 +132,7 @@ inquirer.prompt(questions).then(answers => {
|
||||
fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl));
|
||||
fs.writeFileSync(electronDir + "/config.js", data, 'utf8');
|
||||
//
|
||||
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
||||
let packageFile = path.resolve(__dirname, "package.json");
|
||||
let packageString = fs.readFileSync(packageFile, 'utf8');
|
||||
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
||||
@ -181,10 +140,16 @@ inquirer.prompt(questions).then(answers => {
|
||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
||||
//
|
||||
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||
answers.platform.forEach(item => {
|
||||
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"});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
17
electron/main.js
vendored
17
electron/main.js
vendored
@ -1,6 +1,13 @@
|
||||
const {app, BrowserWindow} = require('electron')
|
||||
const fs = require('fs')
|
||||
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) {
|
||||
const itemCountRegex = /[([{]([\d.,]*)\+?[}\])]/;
|
||||
@ -17,9 +24,15 @@ function createWindow(setDockBadge) {
|
||||
}
|
||||
})
|
||||
|
||||
if (devloadUrl) {
|
||||
mainWindow.loadURL(devloadUrl).then(r => {
|
||||
|
||||
})
|
||||
} else {
|
||||
mainWindow.loadFile('./public/index.html').then(r => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
mainWindow.on('page-title-updated', function (event, title) {
|
||||
const counterValue = getCounterValue(title);
|
||||
|
@ -6,6 +6,7 @@
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"start": "electron-forge start",
|
||||
"start-quiet": "electron-forge start &> /dev/null",
|
||||
"build": "electron-builder",
|
||||
"build-mac-intel": "electron-builder --mac",
|
||||
"build-mac-m1": "electron-builder --mac --arm64",
|
||||
@ -20,6 +21,7 @@
|
||||
"@electron-forge/maker-rpm": "^6.0.0-beta.57",
|
||||
"@electron-forge/maker-squirrel": "^6.0.0-beta.57",
|
||||
"@electron-forge/maker-zip": "^6.0.0-beta.57",
|
||||
"dotenv": "^9.0.2",
|
||||
"electron": "^13.1.6",
|
||||
"electron-builder": "^22.11.7"
|
||||
},
|
||||
|
@ -5,7 +5,8 @@
|
||||
"scripts": {
|
||||
"start": "./cmd dev",
|
||||
"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"
|
||||
},
|
||||
"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({
|
||||
mode: __PLATFORM === "web" ? 'history' : 'hash',
|
||||
mode: !__IS_WEB ? 'hash' : 'history',
|
||||
routes
|
||||
});
|
||||
|
||||
|
6
webpack.mix.js
vendored
6
webpack.mix.js
vendored
@ -21,10 +21,10 @@ if (!['--watch', '--hot'].includes(argv[3])) {
|
||||
output.publicPath = './';
|
||||
}
|
||||
|
||||
let platform = "web";
|
||||
let is_web = true;
|
||||
let publicPath = 'public'
|
||||
if (argv[4] === '--electron') {
|
||||
platform = "electron"
|
||||
is_web = false
|
||||
publicPath = 'electron/public';
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ mix
|
||||
output,
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'__PLATFORM': platform
|
||||
'__IS_WEB': is_web,
|
||||
})
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user