Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Create separate index for browser builds and make build

  • Loading branch information...
commit a922b0ce8d05d271c0461a3a38794f4be992a6bd 1 parent 3340af4
Mikito Takada authored
Showing with 28 additions and 27 deletions.
  1. +20 −0 browser_index.js
  2. +2 −1  build.js
  3. +4 −7 dist/minilog.js
  4. +2 −19 index.js
20 browser_index.js
View
@@ -0,0 +1,20 @@
+exports = module.exports = require('./minilog.js');
+
+exports.backends = {
+ browser: require('./backends/browser_console.js'),
+ localstorage: require('./backends/browser_localstorage.js')
+};
+
+// allows you to enable logging from the very start
+// by doing "window.localStorage.minilogSettings = JSON.stringify(['browser']);"
+// this will start logging immediately
+if(typeof window != 'undefined' && window.localStorage &&
+ typeof JSON != 'undefined' && JSON.parse &&
+ window.localStorage.minilogSettings) {
+ var enabled = JSON.parse(window.localStorage.minilogSettings);
+ for(var i = 0; i < enabled.length; i++) {
+ if (exports.backends[enabled[i]]) {
+ exports.pipe(exports.backends[enabled[i]]);
+ }
+ }
+}
3  build.js
View
@@ -17,7 +17,8 @@ var hasBrowser = process.argv.some(function(o) { return o == 'browser'}),
var build = new Glue()
.basepath('./')
- .include('./index.js')
+ .include('./browser_index.js')
+ .main('browser_index.js')
.include('./minilog.js');
if(hasBrowser) {
11 dist/minilog.js
View
@@ -1,12 +1,9 @@
(function(){var global = this;function require(p, parent){ var path = require.resolve(p) , mod = require.modules[path]; if (!mod) throw new Error('failed to require "' + p + '" from ' + parent); if (!mod.exports) { mod.exports = {}; mod.call(mod.exports, mod, mod.exports, require.relative(path), global); } return mod.exports;}require.modules = {};require.resolve = function(path){ var orig = path , reg = path + '.js' , index = path + '/index.js'; return require.modules[reg] && reg || require.modules[index] && index || orig;};require.relative = function(parent) { return function(p){ if ('debug' == p) return debug; if ('.' != p.charAt(0)) return require(p); var path = parent.split('/') , segs = p.split('/'); path.pop(); for (var i = 0; i < segs.length; i++) { var seg = segs[i]; if ('..' == seg) path.pop(); else if ('.' != seg) path.push(seg); } return require(path.join('/'), parent); };};
require.modules["jquery"] = { exports: window.$ };
-require.modules['index.js'] = function(module, exports, require, global){
+require.modules['browser_index.js'] = function(module, exports, require, global){
exports = module.exports = require('./minilog.js');
exports.backends = {
-// redis: require('./backends/redis.js'),
-// nodeConsole: require('./backends/node_console.js'),
-// jquery: require('./backends/jquery.js')
browser: require('./backends/browser_console.js'),
localstorage: require('./backends/browser_localstorage.js')
};
@@ -129,13 +126,13 @@ var cache = false;
module.exports = {
write: function(str) {
if(typeof window == 'undefined' || !window.localStorage ||
- typeof JSON == 'undefined' || !JSON.stringify) return;
- if(!cache) { cache = window.localStorage.minilog || []; }
+ typeof JSON == 'undefined' || !JSON.stringify || !JSON.parse) return;
+ if(!cache) { cache = (window.localStorage.minilog ? JSON.parse(window.localStorage.minilog) : []); }
cache.push(new Date().toString() + ' '+ str);
window.localStorage.minilog = JSON.stringify(cache);
},
end: function() {}
};
-};Minilog = require('index.js');
+};Minilog = require('browser_index.js');
})();
21 index.js
View
@@ -1,23 +1,6 @@
exports = module.exports = require('./minilog.js');
exports.backends = {
-// redis: require('./backends/redis.js'),
-// nodeConsole: require('./backends/node_console.js'),
-// jquery: require('./backends/jquery.js')
- browser: require('./backends/browser_console.js'),
- localstorage: require('./backends/browser_localstorage.js')
+ redis: require('./backends/redis.js'),
+ nodeConsole: require('./backends/node_console.js')
};
-
-// allows you to enable logging from the very start
-// by doing "window.localStorage.minilogSettings = JSON.stringify(['browser']);"
-// this will start logging immediately
-if(typeof window != 'undefined' && window.localStorage &&
- typeof JSON != 'undefined' && JSON.parse &&
- window.localStorage.minilogSettings) {
- var enabled = JSON.parse(window.localStorage.minilogSettings);
- for(var i = 0; i < enabled.length; i++) {
- if (exports.backends[enabled[i]]) {
- exports.pipe(exports.backends[enabled[i]]);
- }
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.