diff --git a/app.js b/app.js index 98e66dd742..2163a4166b 100644 --- a/app.js +++ b/app.js @@ -5,11 +5,23 @@ var system = new EventEmitter(); var fs = require("fs"); var path = require('path') var debug = require('debug')('app'); +var mkdirp = require('mkdirp'); +var config; +var cfgDir; -var config = new (require('./bitfocus-libs/config'))(system, { - http_port: 8000, - bind_ip: "127.0.0.1", -}); +system.on('skeleton-info', function(key, val) { + if (key == 'configDir') { + debug('configuration directory', val); + cfgDir = val + "/elgato/"; + mkdirp(cfgDir, function(err) { + debug("mkdirp",cfgDir,err); + config = new (require('./bitfocus-libs/config'))(system, cfgDir, { + http_port: 8000, + bind_ip: "127.0.0.1" + }); + }); + } + }); system.on('config_loaded', function(config) { system.emit('skeleton-info', 'appURL', 'Waiting for webserver..'); @@ -24,6 +36,7 @@ system.on('exit', function() { }); }); + system.on('skeleton-bind-ip', function(ip) { config.bind_ip = ip; system.emit('config_set', 'bind_ip', ip); @@ -34,7 +47,7 @@ system.on('skeleton-ready', function() { var http = require('./lib/http')(system, 80); var io = require('./lib/io')(system, http); - var db = new (require('./lib/db'))(system); + var db = new (require('./lib/db'))(system,cfgDir); var appRoot = require('app-root-path'); var express = require('express'); var panel = new (require('./lib/elgato'))(system); diff --git a/bitfocus-libs b/bitfocus-libs index a5530e48b1..81f4220aa7 160000 --- a/bitfocus-libs +++ b/bitfocus-libs @@ -1 +1 @@ -Subproject commit a5530e48b133ff0c7bf694f41451fefb1c200d27 +Subproject commit 81f4220aa74b76acce4bfdfdba28be3c951ca929 diff --git a/bitfocus-skeleton b/bitfocus-skeleton index d06b697078..4a90999357 160000 --- a/bitfocus-skeleton +++ b/bitfocus-skeleton @@ -1 +1 @@ -Subproject commit d06b6970788a3241a9466070516a4fa0fc16a6ad +Subproject commit 4a909993572d712d8dd27548d7f2dde182ae34ce diff --git a/lib/db.js b/lib/db.js index 3761933df8..17da3362fd 100644 --- a/lib/db.js +++ b/lib/db.js @@ -19,18 +19,18 @@ var lastsave = 0; var saveInterval = 4000; // Minimum 4 seconds between each save var dirty = false; -module.exports = exports = function (system) { - return new db(system); +module.exports = exports = function (system,cfgDir) { + return new db(system, cfgDir); }; -function db(system) { +function db(system,cfgDir) { debug('new(db)'); var self = this; self._system = system; self.db = {}; try { - var data = fs.readFileSync(__dirname + '/../db'); + var data = fs.readFileSync(cfgDir + '/db'); self.db = JSON.parse(data); debug('db loaded'); @@ -98,7 +98,7 @@ function db(system) { if (new Date().getTime() - lastsave > saveInterval) { debug("db_save","begin", self.db ); - fs.writeFile(__dirname + '/../db', JSON.stringify(self.db), function (err) { + fs.writeFile(cfgDir + '/db', JSON.stringify(self.db), function (err) { if (err) { debug('db_save', 'Error saving: ' + err); system.emit('db_saved', err); diff --git a/package.json b/package.json index d3230dc5d9..07e178bd15 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "font-awesome": "4.7.0", "jquery": "3.3.1", "json-parser": "^1.1.5", + "mkdirp": "^0.5.1", "pace-progress": "1.0.2", "perfect-scrollbar": "^1.3.0", "pngjs": "^3.3.3", diff --git a/tools/build.sh b/tools/build.sh new file mode 100755 index 0000000000..034febe275 --- /dev/null +++ b/tools/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +yarn +npm run dist