Convert to ES5, add web server

* No compilation step
 * Beginnings of web interface
 * Simple express server; React-based frontend
 * CommonJS style across codebase; auto-converts to RequireJS for browser
 * Using diffsync for realtime UI
 * "Provider" -> "Plugin"
 * Plugins expose one or more Providers
This commit is contained in:
Nick Farina
2015-08-10 14:19:55 -07:00
parent bf5fc50fa6
commit dbedf7fe01
45 changed files with 52708 additions and 439 deletions

View File

@@ -1,58 +1,64 @@
import chalk from 'chalk';
var chalk = require('chalk');
let DEBUG_ENABLED = false;
'use strict';
module.exports = {
Logger: Logger,
setDebugEnabled: setDebugEnabled,
_system: new Logger() // system logger, for internal use only
}
var DEBUG_ENABLED = false;
// Turns on debug level logging
export function setDebugEnabled(enabled) {
function setDebugEnabled(enabled) {
DEBUG_ENABLED = enabled;
}
// global cache of logger instances by provider name
let loggerCache = {};
// global cache of logger instances by plugin name
var loggerCache = {};
export class Logger {
constructor(providerName) {
this.providerName = providerName;
}
/**
* Logger class
*/
debug(msg) {
if (DEBUG_ENABLED)
this.log('debug', msg);
}
info(msg) {
this.log('info', msg);
}
warn(msg) {
this.log('warn', msg);
}
error(msg) {
this.log('error', msg);
}
log(level, msg) {
if (level == 'debug')
msg = chalk.gray(msg);
else if (level == 'warn')
msg = chalk.yellow(msg);
else if (level == 'error')
msg = chalk.bold.red(msg);
// prepend provider name if applicable
if (this.providerName)
msg = chalk.cyan(`[${this.providerName}]`) + " " + msg;
console.log(msg);
}
static forProvider(providerName) {
return loggerCache[providerName] || (loggerCache[providerName] = new Logger(providerName));
}
function Logger(pluginName) {
this.pluginName = pluginName;
}
// system logger, for internal use only
export let log = new Logger();
Logger.prototype.debug = function(msg) {
if (DEBUG_ENABLED)
this.log('debug', msg);
}
Logger.prototype.info = function(msg) {
this.log('info', msg);
}
Logger.prototype.warn = function(msg) {
this.log('warn', msg);
}
Logger.prototype.error = function(msg) {
this.log('error', msg);
}
Logger.prototype.log = function(level, msg) {
if (level == 'debug')
msg = chalk.gray(msg);
else if (level == 'warn')
msg = chalk.yellow(msg);
else if (level == 'error')
msg = chalk.bold.red(msg);
// prepend plugin name if applicable
if (this.pluginName)
msg = chalk.cyan("[" + this.pluginName + "]") + " " + msg;
console.log(msg);
}
Logger.forPlugin = function(pluginName) {
return loggerCache[pluginName] || (loggerCache[pluginName] = new Logger(pluginName));
}