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
|
||||||
|
93
electron/build.js
vendored
93
electron/build.js
vendored
@ -3,8 +3,13 @@ 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)) {
|
||||||
@ -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://" ||
|
||||||
@ -99,30 +72,15 @@ function formatUrl(str) {
|
|||||||
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");
|
||||||
|
const devloadCachePath = path.resolve(__dirname, ".devload");
|
||||||
|
|
||||||
|
if (argv[2] === "--build") {
|
||||||
if (fs.existsSync(electronDir)) {
|
if (fs.existsSync(electronDir)) {
|
||||||
deleteFile(electronDir);
|
deleteFile(electronDir);
|
||||||
}
|
}
|
||||||
@ -174,6 +132,7 @@ inquirer.prompt(questions).then(answers => {
|
|||||||
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');
|
||||||
//
|
//
|
||||||
|
fs.writeFileSync(devloadCachePath, "", 'utf8');
|
||||||
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(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
packageString = packageString.replace(/"version":\s*"(.*?)"/, `"version": "${config.version}"`);
|
||||||
@ -181,10 +140,16 @@ inquirer.prompt(questions).then(answers => {
|
|||||||
fs.writeFileSync(packageFile, packageString, 'utf8');
|
fs.writeFileSync(packageFile, packageString, 'utf8');
|
||||||
//
|
//
|
||||||
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
child_process.spawnSync("mix", ["--production", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||||
answers.platform.forEach(item => {
|
answers.platform.forEach(arg => {
|
||||||
child_process.spawn("npm", ["run", item], {stdio: "inherit", cwd: "electron"});
|
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')
|
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) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (devloadUrl) {
|
||||||
|
mainWindow.loadURL(devloadUrl).then(r => {
|
||||||
|
|
||||||
|
})
|
||||||
|
} else {
|
||||||
mainWindow.loadFile('./public/index.html').then(r => {
|
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