no message
This commit is contained in:
parent
83b5140b48
commit
276654a7e3
2
electron/build.js
vendored
2
electron/build.js
vendored
@ -146,7 +146,7 @@ if (argv[2] === "--build") {
|
||||
});
|
||||
} 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("mix", ["watch", "--hot", "--", "--env", "--electron"], {stdio: "inherit"});
|
||||
child_process.spawn("npm", ["run", "start-quiet"], {stdio: "inherit", cwd: "electron"});
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@
|
||||
<title>Dootask</title>
|
||||
<link rel="stylesheet" type="text/css" href="./css/app.css">
|
||||
<link rel="stylesheet" type="text/css" href="./css/iview.css">
|
||||
<script src="./js/jquery.min.js"></script>
|
||||
<script src="./js/bootstrap.min.js"></script>
|
||||
<script src="./js/language.all.js"></script>
|
||||
<script src="./js/scroll-into-view.min.js"></script>
|
||||
<script src="./config.js"></script>
|
||||
|
198
electron/index.js
vendored
198
electron/index.js
vendored
@ -1,198 +0,0 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path')
|
||||
const inquirer = require('inquirer');
|
||||
const child_process = require('child_process');
|
||||
const config = require('../package.json')
|
||||
const argv = process.argv;
|
||||
|
||||
// 删除
|
||||
function deleteFile(path) {
|
||||
let files = [];
|
||||
if( fs.existsSync(path) ) {
|
||||
files = fs.readdirSync(path);
|
||||
files.forEach(function(file,index){
|
||||
let curPath = path + "/" + file;
|
||||
if(fs.statSync(curPath).isDirectory()) {
|
||||
deleteFile(curPath);
|
||||
} else {
|
||||
fs.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
fs.rmdirSync(path);
|
||||
}
|
||||
}
|
||||
|
||||
// 复制文件
|
||||
function copyFile(srcPath, tarPath, cb) {
|
||||
let rs = fs.createReadStream(srcPath)
|
||||
rs.on('error', function (err) {
|
||||
if (err) {
|
||||
console.log('read error', srcPath)
|
||||
}
|
||||
cb && cb(err)
|
||||
})
|
||||
let ws = fs.createWriteStream(tarPath)
|
||||
ws.on('error', function (err) {
|
||||
if (err) {
|
||||
console.log('write error', tarPath)
|
||||
}
|
||||
cb && cb(err)
|
||||
})
|
||||
ws.on('close', function (ex) {
|
||||
cb && cb(ex)
|
||||
})
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 给地址加上前后
|
||||
function formatUrl(str) {
|
||||
let url;
|
||||
if (str.substring(0, 7) === "http://" ||
|
||||
str.substring(0, 8) === "https://") {
|
||||
url = str.trim();
|
||||
} else {
|
||||
url = "http://" + str.trim();
|
||||
}
|
||||
if (url.substring(url.length - 1) != "/") {
|
||||
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);
|
||||
|
||||
[
|
||||
'audio',
|
||||
'css',
|
||||
'images',
|
||||
'js',
|
||||
].forEach(function (item) {
|
||||
copyDir(path.resolve(__dirname, "../public", item), electronDir + "/" + item)
|
||||
})
|
||||
|
||||
copyFile(path.resolve(__dirname, "index.html"), electronDir + "/index.html")
|
||||
|
||||
|
||||
const questions = [
|
||||
{
|
||||
type: 'input',
|
||||
name: 'targetUrl',
|
||||
message: "请输入网站地址",
|
||||
default: () => {
|
||||
if (fs.existsSync(nativeCachePath)) {
|
||||
return fs.readFileSync(nativeCachePath, 'utf8');
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
validate: function (value) {
|
||||
return value !== ''
|
||||
}
|
||||
}
|
||||
];
|
||||
if (argv[2] == 'build') {
|
||||
questions.push({
|
||||
type: 'list',
|
||||
name: 'platform',
|
||||
message: "选择操作系统平台",
|
||||
choices: [{
|
||||
name: "MacOS Intel",
|
||||
value: "build-mac-intel"
|
||||
}, {
|
||||
name: "MacOS M1",
|
||||
value: "build-mac-m1"
|
||||
}, {
|
||||
name: "Window x86_64",
|
||||
value: "build-mac-win"
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
inquirer.prompt(questions).then(answers => {
|
||||
let data = `window.systemInformation = {
|
||||
version: "${config.version}",
|
||||
origin: "./",
|
||||
apiUrl: "${formatUrl(answers.targetUrl)}api/"
|
||||
}`;
|
||||
fs.writeFileSync(nativeCachePath, formatUrl(answers.targetUrl));
|
||||
fs.writeFileSync(electronDir + "/config.js", data, 'utf8');
|
||||
//
|
||||
let packageFile = path.resolve(__dirname, "package.json");
|
||||
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');
|
||||
//
|
||||
let platform = argv[2] == "build" ? answers.platform : "start";
|
||||
exec("cd electron && npm run " + (platform)).then(r => {})
|
||||
});
|
||||
|
||||
|
||||
|
4
electron/main.js
vendored
4
electron/main.js
vendored
@ -20,7 +20,9 @@ function createWindow(setDockBadge) {
|
||||
width: 1280,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
nodeIntegration: true,
|
||||
contextIsolation: false
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -40,6 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"echarts": "^5.1.1",
|
||||
"electron": "^13.1.6",
|
||||
"element-ui": "^2.15.2",
|
||||
"notification-koro1": "^1.1.1",
|
||||
"tinymce": "^5.8.1",
|
||||
|
6
resources/assets/js/app.js
vendored
6
resources/assets/js/app.js
vendored
@ -46,13 +46,17 @@ Vue.component('EDropdown', Dropdown);
|
||||
Vue.component('EDropdownMenu', DropdownMenu);
|
||||
Vue.component('EDropdownItem', DropdownItem);
|
||||
|
||||
if (!!__IS_ELECTRON) {
|
||||
Vue.prototype.$electron = require('electron')
|
||||
}
|
||||
|
||||
const originalPush = VueRouter.prototype.push
|
||||
VueRouter.prototype.push = function push(location) {
|
||||
return originalPush.call(this, location).catch(err => err)
|
||||
}
|
||||
|
||||
const router = new VueRouter({
|
||||
mode: !__IS_WEB ? 'hash' : 'history',
|
||||
mode: !!__IS_ELECTRON ? 'hash' : 'history',
|
||||
routes
|
||||
});
|
||||
|
||||
|
2
resources/assets/js/functions/common.js
vendored
2
resources/assets/js/functions/common.js
vendored
@ -1558,4 +1558,4 @@
|
||||
});
|
||||
|
||||
window.$A = $;
|
||||
})(window, window.jQuery);
|
||||
})(window, require('jquery'));
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -13,8 +13,6 @@
|
||||
<link rel="shortcut icon" href="{{ asset_main('favicon.ico') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ mix('css/app.css') }}">
|
||||
<link rel="stylesheet" type="text/css" href="{{ asset_main('css/iview.css') }}">
|
||||
<script src="{{ asset_main('js/jquery.min.js') }}"></script>
|
||||
<script src="{{ asset_main('js/bootstrap.min.js') }}"></script>
|
||||
<script src="{{ asset_main('js/language.all.js') }}"></script>
|
||||
<script src="{{ asset_main('js/scroll-into-view.min.js') }}"></script>
|
||||
<script>
|
||||
|
35
webpack.mix.js
vendored
35
webpack.mix.js
vendored
@ -12,21 +12,9 @@ let mixBuildName = function (str) {
|
||||
return str.replace(/_/g, '/');
|
||||
}
|
||||
|
||||
let output = {
|
||||
chunkFilename: function ({chunk}) {
|
||||
return `js/build/${mixBuildName(chunk.id)}.js`
|
||||
}
|
||||
};
|
||||
if (!['--watch', '--hot'].includes(argv[3])) {
|
||||
output.publicPath = './';
|
||||
}
|
||||
|
||||
let is_web = true;
|
||||
let publicPath = 'public'
|
||||
if (argv[4] === '--electron') {
|
||||
is_web = false
|
||||
publicPath = 'electron/public';
|
||||
}
|
||||
let isHot = argv.includes('--hot');
|
||||
let isElectron = argv.includes('--electron');
|
||||
let publicPath = (!isHot && isElectron) ? 'electron/public' : 'public';
|
||||
|
||||
mix
|
||||
.copy('resources/assets/statics/public', publicPath)
|
||||
@ -34,14 +22,25 @@ mix
|
||||
.sass('resources/assets/sass/app.scss', 'css')
|
||||
.setPublicPath(publicPath)
|
||||
.webpackConfig(webpack => {
|
||||
return {
|
||||
output,
|
||||
let config = {
|
||||
output: {
|
||||
chunkFilename: ({chunk}) => {
|
||||
return `js/build/${mixBuildName(chunk.id)}.js`
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'__IS_WEB': is_web,
|
||||
'__IS_ELECTRON': isElectron,
|
||||
})
|
||||
]
|
||||
};
|
||||
if (isElectron) {
|
||||
config.target = 'electron-renderer'
|
||||
}
|
||||
if (!isHot) {
|
||||
config.output.publicPath = './'
|
||||
}
|
||||
return config
|
||||
})
|
||||
.options({
|
||||
processCssUrls: false,
|
||||
|
Loading…
x
Reference in New Issue
Block a user