Browse Source

move config to iguana folder (wip #2)

all-modes
pbca26 8 years ago
parent
commit
684932fbe0
  1. 6
      config.json
  2. 35
      main.js
  3. 43
      routes/shepherd.js

6
config.json

@ -1,6 +0,0 @@
{
"edexGuiOnly": true,
"iguanaGuiOnly": false,
"manualIguanaStart": false,
"skipBasiliskNetworkCheck": false
}

35
main.js

@ -10,8 +10,10 @@ const path = require('path'),
url = require('url'),
os = require('os'),
spawn = require('child_process').spawn,
exec = require('child_process').exec;
exec = require('child_process').exec,
fixPath = require('fix-path');
var fs = require('fs'),
fsnode = require('fs'),
fs = require('fs-extra'),
mkdirp = require('mkdirp'),
pm2 = require('pm2');
@ -20,18 +22,41 @@ var iguanaAppPort = 17777;
Promise = require('bluebird');
var appConfig = JSON.parse(fs.readFileSync('config.json', 'utf8'));
app.setName('Iguana');
if (os.platform() === 'linux') {
process.env.ELECTRON_RUN_AS_NODE = true;
console.log(process.env);
}
if (os.platform() === 'darwin') {
fixPath();
var iguanaBin = path.join(__dirname, '../assets/bin/osx/iguana'),
iguanaDir = process.env.HOME + '/Library/Application Support/iguana';
}
if (os.platform() === 'linux') {
var iguanaBin = path.join(__dirname, '../assets/bin/linux64/iguana'),
iguanaDir = process.env.HOME + '/.iguana';
}
if (os.platform() === 'win32') {
var iguanaDir = process.env.APPDATA + '/iguana';
iguanaDir = path.normalize(iguanaDir);
}
var appSettings = {
"edexGuiOnly": true,
"iguanaGuiOnly": false,
"manualIguanaStart": false,
"skipBasiliskNetworkCheck": false
};
var appConfig = appSettings;
// preload.js
const _setImmediate = setImmediate,
_clearImmediate = clearImmediate;
process.once('loaded', () => {
global.setImmediate = _setImmediate;
global.clearImmediate = _clearImmediate;
@ -48,12 +73,14 @@ process.once('loaded', () => {
var shepherd = require('./routes/shepherd'),
guiapp = express();
shepherd.saveLocalAppConf(appSettings);
guiapp.use(bodyParser.json()); // support json encoded bodies
guiapp.use(bodyParser.urlencoded({ extended: false })); // support encoded bodies
guiapp.get('/', function (req, res) {
res.send('Iguana app server');
})
});
var guipath = path.join(__dirname, '/gui');
guiapp.use('/gui', express.static(guipath));

43
routes/shepherd.js

@ -65,8 +65,7 @@ shepherd.get('/', function(req, res, next) {
});
shepherd.get('/appconf', function(req, res, next) {
saveLocalAppConf();
var obj = JSON.parse(fs.readFileSync('config.json', 'utf8'));
var obj = JSON.parse(fs.readFileSync(iguanaDir + '/config.json', 'utf8'));
res.send(obj);
});
@ -274,15 +273,43 @@ function slayer(flock) {
});
}
function saveLocalAppConf() {
shepherd.saveLocalAppConf = function(appSettings) {
var appConfFileName = iguanaDir + '/conf.json';
console.log(iguanaDir);
var fsWrite = function() {
var CheckFileExists = function() {
return new Promise(function(resolve, reject) {
var result = 'Check app conf.json file exists is done'
fs.ensureFile(appConfFileName, function(err) {
console.log(err); // => null
});
setTimeout(function() {
console.log(result);
resolve(result);
}, 2000);
});
}
var FixFilePermissions = function() {
return new Promise(function(resolve, reject) {
var result = 'conf.json file permissions updated to Read/Write';
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
resolve(result);
}, 1000);
});
}
var FsWrite = function() {
return new Promise(function(resolve, reject) {
var result = 'write file is done'
fs.writeFile(appConfFileName, 'test', 'utf8', function(err) {
fs.writeFile(appConfFileName, JSON.stringify(appSettings), 'utf8', function(err) {
if (err)
return console.log(err);
});
@ -290,11 +317,17 @@ function saveLocalAppConf() {
fsnode.chmodSync(appConfFileName, '0666');
setTimeout(function() {
console.log(result);
console.log('app conf.json file is copied successfully at: ' + iguanaConfsDir);
resolve(result);
}, 2000);
});
}
CheckFileExists()
.then(function(result) {
return FixFilePermissions();
})
.then(FsWrite);
}
function setConf(flock) {

Loading…
Cancel
Save