Skip to content

Commit

Permalink
Merge pull request adamschwartz#26 from adamschwartz/grunt
Browse files Browse the repository at this point in the history
Node package json and grunt
  • Loading branch information
adamschwartz committed Feb 7, 2014
2 parents a934db3 + 5767dce commit 6b89f1d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
28 changes: 28 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON('package.json')

coffee:
compile:
files:
'log.js': 'log.coffee'

watch:
coffee:
files: ['log.coffee']
tasks: ['coffee', 'uglify']
options:
atBegin: true

uglify:
log:
src: 'log.js'
dest: 'log.min.js'
options:
banner: '/*! log.js <%= pkg.version %> */\n'

grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-contrib-uglify'
grunt.loadNpmTasks 'grunt-contrib-coffee'

grunt.registerTask 'default', ['coffee', 'uglify']
18 changes: 18 additions & 0 deletions log.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
(function() {
var ffSupport, formats, getOrderedMatches, hasMatches, isFF, isIE, isOpera, isSafari, log, makeArray, operaSupport, safariSupport, stringToArgs, _log;

if (!(window.console && window.console.log)) {
return;
}

log = function() {
var args;
args = [];
Expand All @@ -15,12 +17,15 @@
});
return _log.apply(window, args);
};

_log = function() {
return console.log.apply(console, makeArray(arguments));
};

makeArray = function(arrayLikeThing) {
return Array.prototype.slice.call(arrayLikeThing);
};

formats = [
{
regex: /\*([^\*]+)\*/,
Expand Down Expand Up @@ -56,6 +61,7 @@
}
}
];

hasMatches = function(str) {
var _hasMatches;
_hasMatches = false;
Expand All @@ -66,6 +72,7 @@
});
return _hasMatches;
};

getOrderedMatches = function(str) {
var matches;
matches = [];
Expand All @@ -83,6 +90,7 @@
return a.match.index - b.match.index;
});
};

stringToArgs = function(str) {
var firstMatch, matches, styles;
styles = [];
Expand All @@ -94,18 +102,23 @@
}
return [str].concat(styles);
};

isSafari = function() {
return /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
};

isOpera = function() {
return /OPR/.test(navigator.userAgent) && /Opera/.test(navigator.vendor);
};

isFF = function() {
return /Firefox/.test(navigator.userAgent);
};

isIE = function() {
return /MSIE/.test(navigator.userAgent);
};

safariSupport = function() {
var m;
m = navigator.userAgent.match(/AppleWebKit\/(\d+)\.(\d+)(\.|\+|\s)/);
Expand All @@ -114,6 +127,7 @@
}
return 537.38 <= parseInt(m[1], 10) + (parseInt(m[2], 10) / 100);
};

operaSupport = function() {
var m;
m = navigator.userAgent.match(/OPR\/(\d+)\./);
Expand All @@ -122,13 +136,17 @@
}
return 15 <= parseInt(m[1], 10);
};

ffSupport = function() {
return window.console.firebug || window.console.exception;
};

if (isIE() || (isFF() && !ffSupport()) || (isOpera() && !operaSupport()) || (isSafari() && !safariSupport())) {
window.log = _log;
} else {
window.log = log;
}

window.log.l = _log;

}).call(this);
2 changes: 2 additions & 0 deletions log.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "log",
"version": "0.1.0",
"description": "Console.log with style",
"author": "Adam Schwartz <[email protected]>",
"license": "MIT",
"devDependencies": {
"grunt-contrib-coffee": "~0.7.0",
"coffee-script": "~1.6.3",
"grunt-contrib-uglify": "~0.2.4",
"grunt-cli": "~0.1.9",
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.5.3"
}
}

0 comments on commit 6b89f1d

Please sign in to comment.