Initial commit
parent
1d1da58a64
commit
165d408a6d
@ -0,0 +1,29 @@
|
||||
# gulp-named-log
|
||||
|
||||
A logging utility, primarily intended for use with Gulp or other Vinyl streams, that outputs fancy name/severity-prefixed log lines.
|
||||
|
||||
## License
|
||||
|
||||
[WTFPL](http://www.wtfpl.net/txt/copying/) or [CC0](https://creativecommons.org/publicdomain/zero/1.0/), whichever you prefer. A donation and/or attribution are appreciated, but not required.
|
||||
|
||||
## Donate
|
||||
|
||||
My income consists largely of donations for my projects. If this module is useful to you, consider [making a donation](http://cryto.net/~joepie91/donate.html)!
|
||||
|
||||
You can donate using Bitcoin, PayPal, Flattr, cash-in-mail, SEPA transfers, and pretty much anything else.
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests welcome. Please make sure your modifications are in line with the overall code style, and ensure that you're editing the files in `src/`, not those in `lib/`.
|
||||
|
||||
Build tool of choice is `gulp`; simply run `gulp` while developing, and it will watch for changes.
|
||||
|
||||
Be aware that by making a pull request, you agree to release your modifications under the licenses stated above.
|
||||
|
||||
## Usage
|
||||
|
||||
Example coming soon.
|
||||
|
||||
## API
|
||||
|
||||
API documentation coming soon.
|
@ -0,0 +1,24 @@
|
||||
var gulp = require('gulp');
|
||||
|
||||
var gutil = require('gulp-util');
|
||||
var babel = require('gulp-babel');
|
||||
var cache = require('gulp-cached');
|
||||
var remember = require('gulp-remember');
|
||||
var plumber = require('gulp-plumber');
|
||||
|
||||
var source = ["src/**/*.js"]
|
||||
|
||||
gulp.task('babel', function() {
|
||||
return gulp.src(source)
|
||||
.pipe(plumber())
|
||||
.pipe(cache("babel"))
|
||||
.pipe(babel({presets: ["es2015"]}).on('error', gutil.log)).on('data', gutil.log)
|
||||
.pipe(remember("babel"))
|
||||
.pipe(gulp.dest("lib/"));
|
||||
});
|
||||
|
||||
gulp.task('watch', function () {
|
||||
gulp.watch(source, ['babel']);
|
||||
});
|
||||
|
||||
gulp.task('default', ['babel', 'watch']);
|
@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require("./lib");
|
@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
|
||||
var chalk = require("chalk");
|
||||
var spy = require("through2-spy");
|
||||
var fancyLog = require("fancy-log");
|
||||
|
||||
var padWidth = 5;
|
||||
|
||||
var typeColors = {
|
||||
error: "red",
|
||||
warn: "yellow",
|
||||
info: "cyan",
|
||||
debug: "gray"
|
||||
};
|
||||
|
||||
module.exports = function namedLog(name) {
|
||||
var prefix = "[" + chalk.green(name) + "]";
|
||||
|
||||
function createLog(type) {
|
||||
var prefixes = [prefix];
|
||||
|
||||
if (type) {
|
||||
var typeColor = typeColors[type] != null ? typeColors[type] : "white";
|
||||
var typePrefix = "[" + chalk[typeColor](type) + "]";
|
||||
|
||||
prefixes.push(typePrefix);
|
||||
}
|
||||
|
||||
return function log() {
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
fancyLog.apply(null, prefixes.concat(args));
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
debug: createLog("debug"),
|
||||
info: createLog("info"),
|
||||
warn: createLog("warn"),
|
||||
error: createLog("error"),
|
||||
log: createLog(),
|
||||
stream: function stream() {
|
||||
var _this = this;
|
||||
|
||||
return spy.obj(function (file) {
|
||||
_this.info(file.path, file.contents);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "gulp-named-log",
|
||||
"version": "0.0.1",
|
||||
"description": "A simple utility module for name-prefixed logging, especially in Gulp",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://git.cryto.net/joepie91/node-gulp-named-log.git"
|
||||
},
|
||||
"keywords": [
|
||||
"gulp",
|
||||
"logging"
|
||||
],
|
||||
"author": "Sven Slootweg",
|
||||
"license": "WTFPL",
|
||||
"dependencies": {
|
||||
"chalk": "^1.1.1",
|
||||
"fancy-log": "^1.2.0",
|
||||
"through2-spy": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-preset-es2015": "^6.6.0",
|
||||
"gulp": "^3.9.1",
|
||||
"gulp-babel": "^6.1.2",
|
||||
"gulp-cached": "^1.1.0",
|
||||
"gulp-plumber": "^1.1.0",
|
||||
"gulp-remember": "^0.3.0",
|
||||
"gulp-util": "^3.0.7"
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
|
||||
const chalk = require("chalk");
|
||||
const spy = require("through2-spy");
|
||||
const fancyLog = require("fancy-log");
|
||||
|
||||
const padWidth = 5;
|
||||
|
||||
const typeColors = {
|
||||
error: "red",
|
||||
warn: "yellow",
|
||||
info: "cyan",
|
||||
debug: "gray"
|
||||
}
|
||||
|
||||
module.exports = function namedLog(name) {
|
||||
let prefix = `[${chalk.green(name)}]`;
|
||||
|
||||
function createLog(type) {
|
||||
let prefixes = [prefix];
|
||||
|
||||
if (type) {
|
||||
let typeColor = (typeColors[type] != null) ? typeColors[type] : "white";
|
||||
let typePrefix = `[${chalk[typeColor](type)}]`;
|
||||
|
||||
prefixes.push(typePrefix);
|
||||
}
|
||||
|
||||
return function log(...args) {
|
||||
fancyLog.apply(null, prefixes.concat(args));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
debug: createLog("debug"),
|
||||
info: createLog("info"),
|
||||
warn: createLog("warn"),
|
||||
error: createLog("error"),
|
||||
log: createLog(),
|
||||
stream: function() {
|
||||
return spy.obj((file) => {
|
||||
this.info(file.path, file.contents);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue