Run local server while inside packed version, Fixes: #310

This commit is contained in:
ziajka 2019-02-28 15:07:06 +01:00
parent 3cf7492452
commit 50b12f54d8
2 changed files with 41 additions and 20 deletions

View File

@ -17,6 +17,9 @@ files:
- local-server.js
- package.json
extraFiles:
- dist/exe.gns3server/**
mac:
category: public.app-category.developer-tools
# publish: github

View File

@ -3,34 +3,23 @@ const kill = require('tree-kill');
const path = require('path');
const fs = require('fs');
const { ipcMain } = require('electron')
const { app } = require('electron')
const isWin = /^win/.test(process.platform);
let runningServers = {};
exports.getLocalServerPath = async () => {
const distDirectory = path.join(__dirname, 'dist');
if (!fs.existsSync(distDirectory)) {
return;
}
const lookupDirectories = [
__dirname,
path.dirname(app.getPath('exe'))
];
const files = fs.readdirSync(distDirectory);
let serverPath = null;
files.forEach((directory) => {
if(directory.startsWith('exe.')) {
if (isWin) {
serverPath = path.join(__dirname, 'dist', directory, 'gns3server.exe');
}
else {
serverPath = path.join(__dirname, 'dist', directory, 'gns3server');
}
for(var directory of lookupDirectories) {
const serverPath = await findLocalServerPath(directory);
if(serverPath !== undefined) {
return serverPath;
}
});
if(serverPath !== null && fs.existsSync(serverPath)) {
return serverPath;
}
return;
@ -54,6 +43,35 @@ exports.stopAllLocalServers = async () => {
return await stopAll();
}
async function findLocalServerPath(baseDirectory) {
const distDirectory = path.join(baseDirectory, 'dist');
if (!fs.existsSync(distDirectory)) {
return;
}
const files = fs.readdirSync(distDirectory);
let serverPath = null;
files.forEach((directory) => {
if(directory.startsWith('exe.')) {
if (isWin) {
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server.exe');
}
else {
serverPath = path.join(baseDirectory, 'dist', directory, 'gns3server');
}
}
});
if(serverPath !== null && fs.existsSync(serverPath)) {
return serverPath;
}
return;
}
function getServerArguments(server, overrides) {
let serverArguments = [];
if(server.host) {