From dea87dbb0b970c4e13043c309843eec4b08fde5f Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 29 Nov 2018 13:52:14 -0700 Subject: [PATCH] Scaffold: Normalize repository --- .editorconfig | 1 + .eslintrc | 2 +- .gitattributes | 1 + .npmrc | 1 + .travis.yml | 5 + LICENSE | 3 +- README.md | 28 ++++- appveyor.yml | 26 +++++ index.js | 18 ++-- package.json | 25 +++-- test.js | 286 ------------------------------------------------- test/.eslintrc | 3 + test/index.js | 177 ++++++++++++++++++++++++++++++ 13 files changed, 263 insertions(+), 313 deletions(-) create mode 100644 .gitattributes create mode 100644 .npmrc create mode 100644 appveyor.yml delete mode 100644 test.js create mode 100644 test/.eslintrc create mode 100644 test/index.js diff --git a/.editorconfig b/.editorconfig index 5760be5..e000b0c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,7 @@ indent_size = 2 charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +end_of_line = lf [*.md] trim_trailing_whitespace = false diff --git a/.eslintrc b/.eslintrc index bc99165..df8ae5f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,5 @@ { - "extends": "@phated/iceddev/es5", + "extends": "gulp", "rules": { "no-console": 0 } diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 54fe09c..7e14b19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,11 @@ sudo: false language: node_js node_js: + - '10' + - '8' + - '6' - '4' - '0.12' - '0.10' +after_script: + - npm run coveralls diff --git a/LICENSE b/LICENSE index 7909814..3a58630 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Blaine Bublitz -Based on gulp-util, copyright 2014 Fractal +Copyright (c) 2014, 2015, 2018 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index dfd3a94..33ef5c1 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ -# fancy-log +

+ + + +

-[![Travis Build Status](https://img.shields.io/travis/js-cli/fancy-log.svg?branch=master&label=travis&style=flat-square)](https://travis-ci.org/js-cli/fancy-log) +# fancy-log -Log things, prefixed with a timestamp +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] -__This module was pulled out of gulp-util for use inside the CLI__ +Log things, prefixed with a timestamp. ## Usage @@ -49,3 +53,19 @@ current time in HH:MM:ss format. ## License MIT + +[downloads-image]: http://img.shields.io/npm/dm/fancy-log.svg +[npm-url]: https://www.npmjs.com/package/fancy-log +[npm-image]: http://img.shields.io/npm/v/fancy-log.svg + +[travis-url]: https://travis-ci.org/gulpjs/fancy-log +[travis-image]: http://img.shields.io/travis/gulpjs/fancy-log.svg?label=travis-ci + +[appveyor-url]: https://ci.appveyor.com/project/gulpjs/fancy-log +[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/fancy-log.svg?label=appveyor + +[coveralls-url]: https://coveralls.io/r/gulpjs/fancy-log +[coveralls-image]: http://img.shields.io/coveralls/gulpjs/fancy-log/master.svg + +[gitter-url]: https://gitter.im/gulpjs/gulp +[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..bd65027 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,26 @@ +# http://www.appveyor.com/docs/appveyor-yml +# http://www.appveyor.com/docs/lang/nodejs-iojs + +environment: + matrix: + # node.js + - nodejs_version: "0.10" + - nodejs_version: "0.12" + - nodejs_version: "4" + - nodejs_version: "6" + - nodejs_version: "8" + - nodejs_version: "10" + +install: + - ps: Install-Product node $env:nodejs_version + - npm install + +test_script: + - node --version + - npm --version + - cmd: npm test + +build: off + +# build version format +version: "{build}" diff --git a/index.js b/index.js index c78eb45..be9548d 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,5 @@ 'use strict'; -/* - Initial code from https://github.com/gulpjs/gulp-util/blob/v3.0.6/lib/log.js - */ + var gray = require('ansi-gray'); var timestamp = require('time-stamp'); var supportsColor = require('color-support'); @@ -26,39 +24,39 @@ function addColor(str) { return str; } -function getTimestamp(){ - return '['+addColor(timestamp('HH:mm:ss'))+']'; +function getTimestamp() { + return '[' + addColor(timestamp('HH:mm:ss')) + ']'; } -function log(){ +function log() { var time = getTimestamp(); process.stdout.write(time + ' '); console.log.apply(console, arguments); return this; } -function info(){ +function info() { var time = getTimestamp(); process.stdout.write(time + ' '); console.info.apply(console, arguments); return this; } -function dir(){ +function dir() { var time = getTimestamp(); process.stdout.write(time + ' '); console.dir.apply(console, arguments); return this; } -function warn(){ +function warn() { var time = getTimestamp(); process.stderr.write(time + ' '); console.warn.apply(console, arguments); return this; } -function error(){ +function error() { var time = getTimestamp(); process.stderr.write(time + ' '); console.error.apply(console, arguments); diff --git a/package.json b/package.json index eefb669..cff694d 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "fancy-log", "version": "1.3.2", - "description": "Log things, prefixed with a timestamp", - "author": "Blaine Bublitz ", + "description": "Log things, prefixed with a timestamp.", + "author": "Gulp Team (http://gulpjs.com/)", "contributors": [ + "Blaine Bublitz ", "Aman Mittal (http://amandeepmittal.github.io/)" ], - "repository": "js-cli/fancy-log", + "repository": "gulpjs/fancy-log", "license": "MIT", "engines": { "node": ">= 0.10" @@ -17,7 +18,11 @@ "index.js" ], "scripts": { - "test": "lab -cvL test.js" + "lint": "eslint .", + "pretest": "npm run lint", + "test": "mocha --async-only", + "cover": "istanbul cover _mocha --report lcovonly", + "coveralls": "npm run cover && istanbul-coveralls" }, "dependencies": { "ansi-gray": "^0.1.1", @@ -25,12 +30,12 @@ "time-stamp": "^1.0.0" }, "devDependencies": { - "@phated/eslint-config-iceddev": "^0.2.1", - "code": "^1.5.0", - "eslint": "^1.3.1", - "eslint-plugin-mocha": "^0.5.1", - "eslint-plugin-react": "^3.3.1", - "lab": "^5.16.0" + "eslint": "^2.13.0", + "eslint-config-gulp": "^3.0.1", + "expect": "^1.20.2", + "istanbul": "^0.4.3", + "istanbul-coveralls": "^1.0.3", + "mocha": "^3.5.3" }, "keywords": [ "console.log", diff --git a/test.js b/test.js deleted file mode 100644 index 4f19fd7..0000000 --- a/test.js +++ /dev/null @@ -1,286 +0,0 @@ -'use strict'; -/* - Initial code from https://github.com/gulpjs/gulp-util/blob/v3.0.6/test/log.js - */ -var util = require('util'); - -var lab = exports.lab = require('lab').script(); -var code = require('code'); -var gray = require('ansi-gray'); -var timestamp = require('time-stamp'); - -var log = require('./'); - -lab.describe('log()', function(){ - - var term = process.env.TERM; - var colorterm = process.env.COLORTERM; - var stdout_write = process.stdout.write; - var writtenValue = ''; - - function writeSpy(value) { - writtenValue += value; - } - - lab.afterEach(function(done){ - writtenValue = ''; - done(); - }); - - lab.it('should work i guess', function(done){ - // Stub process.stdout.write - process.stdout.write = writeSpy; - - log(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + gray(time) + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - done(); - }); - - lab.it('should accept formatting', function(done){ - // Stub process.stdout.write - process.stdout.write = writeSpy; - - log('%s %d %j', 'something', 0.1, {key: 'value'}); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals( - '[' + gray(time) + '] '+ - 'something 0.1 {\"key\":\"value\"}\n' - ); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - done(); - }); - - lab.it('does not add color if argv contains --no-color', function(done) { - // Stub process.stdout.write - process.stdout.write = writeSpy; - - process.argv.push('--no-color'); - - log(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + time + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - process.argv.pop(); - - done(); - }); - - lab.it('adds color if argv contains --color', function(done) { - // Stub process.stdout.write - process.stdout.write = writeSpy; - - process.argv.push('--color'); - - log(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + gray(time) + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - process.argv.pop(); - - done(); - }); - - lab.it('does not add color if no support', function(done) { - // Stub process.stdout.write - process.stdout.write = writeSpy; - - process.env.TERM = 'dumb'; - delete process.env.COLORTERM; - - log(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + time + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - process.env.TERM = term; - process.env.COLORTERM = colorterm; - - done(); - }); -}); - -lab.describe('log.info()', function(){ - - var stdout_write = process.stdout.write; - var writtenValue = ''; - - function writeSpy(value) { - writtenValue += value; - } - - lab.afterEach(function(done){ - writtenValue = ''; - done(); - }); - - lab.it('should work i guess', function(done){ - // Stub process.stdout.write - process.stdout.write = writeSpy; - - log.info(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + gray(time) + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - done(); - }); - - lab.it('should accept formatting', function(done){ - // Stub process.stdout.write - process.stdout.write = writeSpy; - - log.info('%s %d %j', 'something', 0.1, {key: 'value'}); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals( - '[' + gray(time) + '] '+ - 'something 0.1 {\"key\":\"value\"}\n' - ); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - done(); - }); -}); - -lab.describe('log.dir()', function(){ - - var stdout_write = process.stdout.write; - var writtenValue = ''; - - function writeSpy(value) { - writtenValue += value; - } - - lab.afterEach(function(done){ - writtenValue = ''; - done(); - }); - - lab.it('should format an object with util.inspect', function(done){ - // Stub process.stdout.write - process.stdout.write = writeSpy; - - log.dir({key: 'value'}); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals( - '[' + gray(time) + '] '+ - util.inspect({key:'value'}) + '\n' - ); - - // Restore process.stdout.write after test - process.stdout.write = stdout_write; - - done(); - }); -}); - -lab.describe('log.warn()', function(){ - - var stderr_write = process.stderr.write; - var writtenValue = ''; - - function writeSpy(value) { - writtenValue += value; - } - - lab.afterEach(function(done){ - writtenValue = ''; - done(); - }); - - lab.it('should work i guess', function(done){ - // Stub process.stderr.write - process.stderr.write = writeSpy; - - log.warn(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + gray(time) + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stderr.write after test - process.stderr.write = stderr_write; - - done(); - }); - - lab.it('should accept formatting', function(done){ - // Stub process.stderr.write - process.stderr.write = writeSpy; - - log.warn('%s %d %j', 'something', 0.1, {key: 'value'}); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals( - '[' + gray(time) + '] '+ - 'something 0.1 {\"key\":\"value\"}\n' - ); - - // Restore process.stderr.write after test - process.stderr.write = stderr_write; - - done(); - }); -}); - -lab.describe('log.error()', function(){ - - var stderr_write = process.stderr.write; - var writtenValue = ''; - - function writeSpy(value) { - writtenValue += value; - } - - lab.afterEach(function(done){ - writtenValue = ''; - done(); - }); - - lab.it('should work i guess', function(done){ - // Stub process.stderr.write - process.stderr.write = writeSpy; - - log.error(1, 2, 3, 4, 'five'); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals('[' + gray(time) + '] 1 2 3 4 \'five\'\n'); - - // Restore process.stderr.write after test - process.stderr.write = stderr_write; - - done(); - }); - - lab.it('should accept formatting', function(done){ - // Stub process.stderr.write - process.stderr.write = writeSpy; - - log.error('%s %d %j', 'something', 0.1, {key: 'value'}); - var time = timestamp('HH:mm:ss'); - code.expect(writtenValue).equals( - '[' + gray(time) + '] '+ - 'something 0.1 {\"key\":\"value\"}\n' - ); - - // Restore process.stderr.write after test - process.stderr.write = stderr_write; - - done(); - }); -}); diff --git a/test/.eslintrc b/test/.eslintrc new file mode 100644 index 0000000..06b940f --- /dev/null +++ b/test/.eslintrc @@ -0,0 +1,3 @@ +{ + "extends": "gulp/test" +} diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..0efa484 --- /dev/null +++ b/test/index.js @@ -0,0 +1,177 @@ +'use strict'; + +var util = require('util'); + +var expect = require('expect'); +var gray = require('ansi-gray'); +var timestamp = require('time-stamp'); + +var log = require('../'); + +var stdoutSpy = expect.spyOn(process.stdout, 'write').andCallThrough(); +var stderrSpy = expect.spyOn(process.stderr, 'write').andCallThrough(); + +describe('log()', function() { + + var term = process.env.TERM; + var colorterm = process.env.COLORTERM; + + beforeEach(function(done) { + stdoutSpy.reset(); + done(); + }); + + it('should work i guess', function(done) { + log(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + done(); + }); + + it('should accept formatting', function(done) { + log('%s %d %j', 'something', 0.1, { key: 'value' }); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('something 0.1 {\"key\":\"value\"}\n'); + + done(); + }); + + it('does not add color if argv contains --no-color', function(done) { + process.argv.push('--no-color'); + + log(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + time + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + process.argv.pop(); + + done(); + }); + + it('adds color if argv contains --color', function(done) { + process.argv.push('--color'); + + log(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + process.argv.pop(); + + done(); + }); + + it('does not add color if no support', function(done) { + process.env.TERM = 'dumb'; + delete process.env.COLORTERM; + + log(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + time + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + process.env.TERM = term; + process.env.COLORTERM = colorterm; + + done(); + }); +}); + +describe('log.info()', function() { + + beforeEach(function(done) { + stdoutSpy.reset(); + done(); + }); + + it('should work i guess', function(done) { + log.info(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + done(); + }); + + it('should accept formatting', function(done) { + log.info('%s %d %j', 'something', 0.1, { key: 'value' }); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude('something 0.1 {\"key\":\"value\"}\n'); + + done(); + }); +}); + +describe('log.dir()', function() { + + beforeEach(function(done) { + stdoutSpy.reset(); + done(); + }); + + it('should format an object with util.inspect', function(done) { + log.dir({ key: 'value' }); + var time = timestamp('HH:mm:ss'); + expect(stdoutSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stdoutSpy.calls[1].arguments).toInclude(util.inspect({ key: 'value' }) + '\n'); + + done(); + }); +}); + +describe('log.warn()', function() { + + beforeEach(function(done) { + stderrSpy.reset(); + done(); + }); + + it('should work i guess', function(done) { + log.warn(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stderrSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stderrSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + done(); + }); + + it('should accept formatting', function(done) { + log.warn('%s %d %j', 'something', 0.1, { key: 'value' }); + var time = timestamp('HH:mm:ss'); + expect(stderrSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stderrSpy.calls[1].arguments).toInclude('something 0.1 {\"key\":\"value\"}\n'); + + done(); + }); +}); + +describe('log.error()', function() { + + beforeEach(function(done) { + stderrSpy.reset(); + done(); + }); + + it('should work i guess', function(done) { + log.error(1, 2, 3, 4, 'five'); + var time = timestamp('HH:mm:ss'); + expect(stderrSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stderrSpy.calls[1].arguments).toInclude('1 2 3 4 \'five\'\n'); + + done(); + }); + + it('should accept formatting', function(done) { + log.error('%s %d %j', 'something', 0.1, { key: 'value' }); + var time = timestamp('HH:mm:ss'); + expect(stderrSpy.calls[0].arguments).toInclude('[' + gray(time) + '] '); + expect(stderrSpy.calls[1].arguments).toInclude('something 0.1 {\"key\":\"value\"}\n'); + + done(); + }); +});