Skip to content

Commit

Permalink
[breaking] ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 8, 2016
1 parent f4ebf90 commit 27a20c5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 77 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[package.json]
[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
13 changes: 0 additions & 13 deletions .jshintrc

This file was deleted.

5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- 'iojs'
- '0.12'
- '0.10'
- '6'
- '4'
11 changes: 6 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
var gulp = require('gulp');
var debug = require('./');
const gulp = require('gulp');
const debug = require('./');

gulp.task('default', function () {
return gulp.src('*').pipe(debug());
});
gulp.task('default', () =>
gulp.src('*')
.pipe(debug())
);
34 changes: 17 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';
var path = require('path');
var gutil = require('gulp-util');
var through = require('through2');
var tildify = require('tildify');
var stringifyObject = require('stringify-object');
var chalk = require('chalk');
var objectAssign = require('object-assign');
var plur = require('plur');
var prop = chalk.blue;

module.exports = function (opts) {
opts = objectAssign({
const path = require('path');
const gutil = require('gulp-util');
const through = require('through2');
const tildify = require('tildify');
const stringifyObject = require('stringify-object');
const chalk = require('chalk');
const plur = require('plur');

const prop = chalk.blue;

module.exports = opts => {
opts = Object.assign({
title: 'gulp-debug:',
minimal: true
}, opts);
Expand All @@ -20,25 +20,25 @@ module.exports = function (opts) {
opts.minimal = false;
}

var count = 0;
let count = 0;

return through.obj(function (file, enc, cb) {
var full =
return through.obj((file, enc, cb) => {
const full =
'\n' +
(file.cwd ? 'cwd: ' + prop(tildify(file.cwd)) : '') +
(file.base ? '\nbase: ' + prop(tildify(file.base)) : '') +
(file.path ? '\npath: ' + prop(tildify(file.path)) : '') +
(file.stat && opts.verbose ? '\nstat: ' + prop(stringifyObject(file.stat, {indent: ' '}).replace(/[{}]/g, '').trim()) : '') +
'\n';

var output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full;
const output = opts.minimal ? prop(path.relative(process.cwd(), file.path)) : full;

count++;

gutil.log(opts.title + ' ' + output);

cb(null, file);
}, function (cb) {
}, cb => {
gutil.log(opts.title + ' ' + chalk.green(count + ' ' + plur('item', count)));
cb();
});
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "http://sindresorhus.com"
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "mocha"
"test": "xo && mocha"
},
"files": [
"index.js"
Expand All @@ -33,7 +33,6 @@
"dependencies": {
"chalk": "^1.0.0",
"gulp-util": "^3.0.0",
"object-assign": "^4.0.1",
"plur": "^2.0.0",
"stringify-object": "^3.0.0",
"through2": "^2.0.0",
Expand All @@ -44,6 +43,10 @@
"mocha": "*",
"proxyquire": "^1.0.1",
"sinon": "^1.9.1",
"strip-ansi": "^3.0.0"
"strip-ansi": "^3.0.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}
62 changes: 32 additions & 30 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,86 @@
/* eslint-env mocha */
'use strict';
var fs = require('fs');
var assert = require('assert');
var sinon = require('sinon');
var gutil = require('gulp-util');
var proxyquire = require('proxyquire');
var stripAnsi = require('strip-ansi');

var gutilStub = {
log: function () {
const fs = require('fs');
const path = require('path');
const assert = require('assert');
const sinon = require('sinon');
const gutil = require('gulp-util');
const proxyquire = require('proxyquire');
const stripAnsi = require('strip-ansi');

const gutilStub = {
log() {
// uncomment the next line to see the log messages written by gulp-debug
// during test (by default they are swallowed by the sinon stub replacing the log method)
// gutil.log.apply(gutil.log, arguments);
}
};

var debug = proxyquire('./', {
const debug = proxyquire('./', {
'gulp-util': gutilStub
});

var file;
let file;

beforeEach(function () {
beforeEach(() => {
sinon.spy(gutilStub, 'log');
file = new gutil.File({
cwd: __dirname,
base: __dirname,
path: __dirname + '/foo.js',
path: path.join(__dirname, 'foo.js'),
stat: fs.statSync('test.js'),
contents: new Buffer('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
});
});

afterEach(function () {
afterEach(() => {
gutilStub.log.restore();
});

it('should output debug info', function (cb) {
var stream = debug({title: 'unicorn:'});
it('should output debug info', cb => {
const stream = debug({title: 'unicorn:'});

stream.write(file, 'utf8', function () {
stream.write(file, 'utf8', () => {
assert(gutilStub.log.calledOnce);
assert.strictEqual(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
assert.strictEqual(stripAnsi(gutilStub.log.firstCall.args[0]).split('\n')[0], 'unicorn: foo.js');
cb();
});
});

it('should output singular item count', function (cb) {
var stream = debug({title: 'unicorn:'});
it('should output singular item count', cb => {
const stream = debug({title: 'unicorn:'});

stream.on('finish', function () {
stream.on('finish', () => {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 1 item');
cb();
});

stream.write(file, function () {
stream.write(file, () => {
stream.end();
});
});

it('should output zero item count', function (cb) {
var stream = debug({title: 'unicorn:'});
it('should output zero item count', cb => {
const stream = debug({title: 'unicorn:'});

stream.on('finish', function () {
stream.on('finish', () => {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 0 items');
cb();
});

stream.end();
});

it('should output plural item count', function (cb) {
var stream = debug({title: 'unicorn:'});
it('should output plural item count', cb => {
const stream = debug({title: 'unicorn:'});

stream.on('finish', function () {
stream.on('finish', () => {
assert.strictEqual(stripAnsi(gutilStub.log.lastCall.args[0]).split('\n')[0], 'unicorn: 2 items');
cb();
});

stream.write(file, function () {
stream.write(file, function () {
stream.write(file, () => {
stream.write(file, () => {
stream.end();
});
});
Expand Down

0 comments on commit 27a20c5

Please sign in to comment.