Skip to content

Commit

Permalink
Merge branch '0.4.4' of https://github.com/nodecg/nodecg into 0.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Van Camp committed Jan 28, 2015
2 parents 6441bcc + 771ceb8 commit 9176764
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
24 changes: 13 additions & 11 deletions lib/bundles/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

var parse = require('./parser.js'),
events = require('events'),
watcher = require('./watcher.js'),
fs = require('fs'),
Q = require('q'),
log = require('../logger')('nodecg/lib/bundles');
var parse = require('./parser.js');
var events = require('events');
var watcher = require('./watcher.js');
var fs = require('fs');
var Q = require('q');
var log = require('../logger')('nodecg/lib/bundles');

exports = module.exports = new events.EventEmitter();

var _bundles = [];

log.trace("Loading bundles");
log.trace('Loading bundles');

// Do an initial scan of the bundles dir
if (!fs.existsSync('bundles/')) {
Expand All @@ -32,7 +32,7 @@ _bundlesDir.forEach(function(bundleFolderName) {
if (parsePromise) {
var postParsePromise = parsePromise.then(function(bundle) {
if (!bundle) return;
log.trace("Parsed bundle %s", bundle.name);
log.trace('Parsed bundle %s', bundle.name);
_bundles.push(bundle);
});
promises.push(postParsePromise);
Expand All @@ -46,11 +46,12 @@ Q.all(promises)

if (parsePromise) {
parsePromise.then(function(bundle) {
log.info("%s was changed, and has been reloaded from disk", name);
log.info('%s was changed, and has been reloaded from disk', name);
exports.add(bundle);
});
} else {
log.info("%s's nodecg.json can no longer be found on disk, assuming the bundle has been deleted or moved", name);
log.info('%s\'s nodecg.json can no longer be found on disk, ' +
'assuming the bundle has been deleted or moved', name);
exports.remove(name);
}
});
Expand Down Expand Up @@ -84,7 +85,8 @@ exports.add = function(bundle) {
exports.remove = function(bundleName) {
var len = _bundles.length;
for (var i = 0; i < len; i++) {
if (!_bundles[i]) continue; // TODO: this check shouldn't have to happen, idk why things in this array can sometimes be undefined
// TODO: this check shouldn't have to happen, idk why things in this array can sometimes be undefined
if (!_bundles[i]) continue;
if (_bundles[i].name === bundleName) _bundles.splice(i, 1);
}
};
48 changes: 26 additions & 22 deletions lib/bundles/parser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict';

var fs = require('fs'),
configHelper = require('../config'),
config = configHelper.getConfig(),
semver = require('semver'),
path = require('path'),
log = require('../logger')('nodecg/lib/bundles/parser'),
jade = require('jade'),
util = require('util'),
Q = require('q'),
exec = require('child_process').exec,

pjson = require('../../package.json');
var fs = require('fs');
var configHelper = require('../config');
var config = configHelper.getConfig();
var semver = require('semver');
var path = require('path');
var log = require('../logger')('nodecg/lib/bundles/parser');
var jade = require('jade');
var util = require('util');
var Q = require('q');
var exec = require('child_process').exec;

var pjson = require('../../package.json');

module.exports = function parse(bundleName) {
// resolve the path to the bundle and its nodecg.json
Expand All @@ -23,15 +23,15 @@ module.exports = function parse(bundleName) {
return null;
}

log.trace("Discovered bundle in folder bundles/%s", bundleName);
log.trace('Discovered bundle in folder bundles/%s', bundleName);

// Read metadata from the nodecg.json manifest file
var bundle = readManifest(manifestPath);
bundle.dir = dir;

// Don't load the bundle if it depends on a different version of NodeCG
if (!isCompatible(bundle.nodecgDependency)) {
log.warn("Did not load %s as it requires NodeCG %s. Current version is %s",
log.warn('Did not load %s as it requires NodeCG %s. Current version is %s',
bundle.name, bundle.nodecgDependency, pjson.version);
return null;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ function installNpmPackages(bundle) {

// Check for existing dependencies
var cmdline = 'npm ls --json --depth=0';
exec(cmdline, { cwd: bundle.dir }, function(err, stdout, stderr) {
exec(cmdline, { cwd: bundle.dir }, function(err, stdout) {
var data = JSON.parse(stdout);

var toInstall = [];
Expand All @@ -112,7 +112,7 @@ function installNpmPackages(bundle) {
exec(cmdline, { cwd: bundle.dir }, function(err) {
if (err) {
deferred.reject(new Error(
util.format("[%s] Failed to install npm dependencies:", bundle.name, err.message)
util.format('[%s] Failed to install npm dependencies:', bundle.name, err.message)
));
}
log.trace('Successfully installed dependencies for bundle', bundle.name);
Expand All @@ -135,7 +135,8 @@ function readDashboardPanels(bundle) {
try {
manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
} catch(e) {
log.warn("[%s] dashboard/panels.json not found or not valid, this bundle will not have any dashboard panels", bundle.name);
log.warn('[%s] dashboard/panels.json not found or not valid, this bundle will not have any dashboard panels',
bundle.name);
return;
}

Expand All @@ -146,7 +147,8 @@ function readDashboardPanels(bundle) {
if (typeof(panel.title) === 'undefined') missingProps.push('title');
if (typeof(panel.file) === 'undefined') missingProps.push('file');
if (missingProps.length) {
log.error("[%s] Panel #%d could not be parsed as it is missing the following properties:", bundle.name, index, missingProps.join(', '));
log.error('[%s] Panel #%d could not be parsed as it is missing the following properties:',
bundle.name, index, missingProps.join(', '));
return;
}

Expand All @@ -157,7 +159,8 @@ function readDashboardPanels(bundle) {

switch (path.extname(panel.file)) {
case '.jade':
// Render the panel as Jade, giving it access to both this specific bundle's config and NodeCG's config
// Render the panel as Jade, giving it access to both
// this specific bundle's config and NodeCG's config
panel.body = jade.renderFile(panel.file, {
bundleConfig: bundle.config,
ncgConfig: config
Expand All @@ -172,7 +175,7 @@ function readDashboardPanels(bundle) {

bundle.dashboard.panels.push(panel);
} catch (e) {
log.error("Error parsing panel '%s' for bundle %s:\n", panel.name, bundle.name, e.message);
log.error('Error parsing panel \'%s\' for bundle %s:\n', panel.name, bundle.name, e.message);
}
});
}
Expand All @@ -184,9 +187,10 @@ function readDashboardResources(bundle) {

var dashboardDir;
try {
dashboardDir = fs.readdirSync(bundle.dashboard.dir); // returns just the filenames of each file in the folder, not full path
// returns just the filenames of each file in the folder, not full path
dashboardDir = fs.readdirSync(bundle.dashboard.dir);
} catch(e) {
log.warn("[%s] No dashboard folder found, this bundle will not have dashboard panels", bundle.name);
log.warn('[%s] No dashboard folder found, this bundle will not have dashboard panels', bundle.name);
return;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/bundles/watcher.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var gaze = require('gaze'),
path = require('path'),
log = require('../logger')('nodecg/lib/bundles/watcher'),
EventEmitter = require('events').EventEmitter,
emitter = new EventEmitter();
var gaze = require('gaze');
var path = require('path');
var log = require('../logger')('nodecg/lib/bundles/watcher');
var EventEmitter = require('events').EventEmitter;
var emitter = new EventEmitter();

require('string.prototype.endswith');

Expand All @@ -16,9 +16,9 @@ var watchPatterns = [
'!**/node_modules/**' // Ignore node_modules folders
];

gaze(watchPatterns, function(err, watcher) {
gaze(watchPatterns, function(err) {
if (err) {
log.error(err.stack, "Couldn't start watcher, NodeCG will exit.");
log.error(err.stack, 'Couldn\'t start watcher, NodeCG will exit.');
process.exit(1);
}

Expand All @@ -37,8 +37,8 @@ gaze(watchPatterns, function(err, watcher) {
prevPart = part;
});

log.debug("Change detected in " + bundleName + ": " + filepath + " " + event);
emitter.emit("bundleChanged", bundleName);
log.debug('Change detected in', bundleName, ': ', filepath, event);
emitter.emit('bundleChanged', bundleName);
});

this.on('error', function(error) {
Expand Down

0 comments on commit 9176764

Please sign in to comment.