pax_global_header00006660000000000000000000000064126113300570014510gustar00rootroot0000000000000052 comment=b74a5ff121471ed00b84fb1e73a0e75488d33ccd gulp-util-3.0.7/000077500000000000000000000000001261133005700134415ustar00rootroot00000000000000gulp-util-3.0.7/.gitignore000066400000000000000000000000761261133005700154340ustar00rootroot00000000000000.DS_Store *.log node_modules build *.node components coverage gulp-util-3.0.7/.jshintrc000066400000000000000000000003131261133005700152630ustar00rootroot00000000000000{ "bitwise": true, "eqeqeq": true, "expr": true, "latedef": true, "newcap": true, "quotmark": "single", "regexp": true, "undef": true, "unused": true, "node": true, "mocha": true } gulp-util-3.0.7/.travis.yml000066400000000000000000000001751261133005700155550ustar00rootroot00000000000000sudo: false language: node_js node_js: - "iojs" - "0.12" - "0.10" after_script: - npm run coveralls git: depth: 10 gulp-util-3.0.7/LICENSE000077500000000000000000000020661261133005700144550ustar00rootroot00000000000000Copyright (c) 2014 Fractal Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gulp-util-3.0.7/README.md000066400000000000000000000103241261133005700147200ustar00rootroot00000000000000# gulp-util [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] ## Information
Packagegulp-util
Description Utility functions for gulp plugins
Node Version >= 0.10
## Usage ```javascript var gutil = require('gulp-util'); gutil.log('stuff happened', 'Really it did', gutil.colors.magenta('123')); gutil.beep(); gutil.replaceExtension('file.coffee', '.js'); // file.js var opt = { name: 'todd', file: someGulpFile }; gutil.template('test <%= name %> <%= file.path %>', opt) // test todd /js/hi.js ``` ### log(msg...) Logs stuff. Already prefixed with [gulp] and all that. If you pass in multiple arguments it will join them by a space. The default gulp coloring using gutil.colors.: ``` values (files, module names, etc.) = cyan numbers (times, counts, etc) = magenta ``` ### colors Is an instance of [chalk](https://github.com/sindresorhus/chalk). ### replaceExtension(path, newExtension) Replaces a file extension in a path. Returns the new path. ### isStream(obj) Returns true or false if an object is a stream. ### isBuffer(obj) Returns true or false if an object is a Buffer. ### template(string[, data]) This is a lodash.template function wrapper. You must pass in a valid gulp file object so it is available to the user or it will error. You can not configure any of the delimiters. Look at the [lodash docs](http://lodash.com/docs#template) for more info. ## new File(obj) This is just [vinyl](https://github.com/wearefractal/vinyl) ```javascript var file = new gutil.File({ base: path.join(__dirname, './fixtures/'), cwd: __dirname, path: path.join(__dirname, './fixtures/test.coffee') }); ``` ## noop() Returns a stream that does nothing but pass data straight through. ```javascript // gulp should be called like this : // $ gulp --type production gulp.task('scripts', function() { gulp.src('src/**/*.js') .pipe(concat('script.js')) .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop()) .pipe(gulp.dest('dist/')); }); ``` ## buffer(cb) This is similar to es.wait but instead of buffering text into one string it buffers anything into an array (so very useful for file objects). Returns a stream that can be piped to. The stream will emit one data event after the stream piped to it has ended. The data will be the same array passed to the callback. Callback is optional and receives two arguments: error and data ```javascript gulp.src('stuff/*.js') .pipe(gutil.buffer(function(err, files) { })); ``` ## new PluginError(pluginName, message[, options]) - pluginName should be the module name of your plugin - message can be a string or an existing error - By default the stack will not be shown. Set `options.showStack` to true if you think the stack is important for your error. - If you pass an error in as the message the stack will be pulled from that, otherwise one will be created. - Note that if you pass in a custom stack string you need to include the message along with that. - Error properties will be included in `err.toString()`. Can be omitted by including `{showProperties: false}` in the options. These are all acceptable forms of instantiation: ```javascript var err = new gutil.PluginError('test', { message: 'something broke' }); var err = new gutil.PluginError({ plugin: 'test', message: 'something broke' }); var err = new gutil.PluginError('test', 'something broke'); var err = new gutil.PluginError('test', 'something broke', {showStack: true}); var existingError = new Error('OMG'); var err = new gutil.PluginError('test', existingError, {showStack: true}); ``` [npm-url]: https://www.npmjs.com/package/gulp-util [npm-image]: https://badge.fury.io/js/gulp-util.svg [travis-url]: https://travis-ci.org/gulpjs/gulp-util [travis-image]: https://img.shields.io/travis/gulpjs/gulp-util.svg?branch=master [coveralls-url]: https://coveralls.io/r/gulpjs/gulp-util [coveralls-image]: https://img.shields.io/coveralls/gulpjs/gulp-util.svg [depstat-url]: https://david-dm.org/gulpjs/gulp-util [depstat-image]: https://david-dm.org/gulpjs/gulp-util.svg gulp-util-3.0.7/index.js000066400000000000000000000010511261133005700151030ustar00rootroot00000000000000module.exports = { File: require('vinyl'), replaceExtension: require('replace-ext'), colors: require('chalk'), date: require('dateformat'), log: require('./lib/log'), template: require('./lib/template'), env: require('./lib/env'), beep: require('beeper'), noop: require('./lib/noop'), isStream: require('./lib/isStream'), isBuffer: require('./lib/isBuffer'), isNull: require('./lib/isNull'), linefeed: '\n', combine: require('./lib/combine'), buffer: require('./lib/buffer'), PluginError: require('./lib/PluginError') }; gulp-util-3.0.7/lib/000077500000000000000000000000001261133005700142075ustar00rootroot00000000000000gulp-util-3.0.7/lib/PluginError.js000066400000000000000000000073231261133005700170220ustar00rootroot00000000000000var util = require('util'); var arrayDiffer = require('array-differ'); var arrayUniq = require('array-uniq'); var chalk = require('chalk'); var objectAssign = require('object-assign'); var nonEnumberableProperties = ['name', 'message', 'stack']; var propertiesNotToDisplay = nonEnumberableProperties.concat(['plugin', 'showStack', 'showProperties', '__safety', '_stack']); // wow what a clusterfuck var parseOptions = function(plugin, message, opt) { opt = opt || {}; if (typeof plugin === 'object') { opt = plugin; } else { if (message instanceof Error) { opt.error = message; } else if (typeof message === 'object') { opt = message; } else { opt.message = message; } opt.plugin = plugin; } return objectAssign({ showStack: false, showProperties: true }, opt); }; function PluginError(plugin, message, opt) { if (!(this instanceof PluginError)) throw new Error('Call PluginError using new'); Error.call(this); var options = parseOptions(plugin, message, opt); var self = this; // if options has an error, grab details from it if (options.error) { // These properties are not enumerable, so we have to add them explicitly. arrayUniq(Object.keys(options.error).concat(nonEnumberableProperties)) .forEach(function(prop) { self[prop] = options.error[prop]; }); } var properties = ['name', 'message', 'fileName', 'lineNumber', 'stack', 'showStack', 'showProperties', 'plugin']; // options object can override properties.forEach(function(prop) { if (prop in options) this[prop] = options[prop]; }, this); // defaults if (!this.name) this.name = 'Error'; if (!this.stack) { // Error.captureStackTrace appends a stack property which relies on the toString method of the object it is applied to. // Since we are using our own toString method which controls when to display the stack trace if we don't go through this // safety object, then we'll get stack overflow problems. var safety = { toString: function() { return this._messageWithDetails() + '\nStack:'; }.bind(this) }; Error.captureStackTrace(safety, arguments.callee || this.constructor); this.__safety = safety; } if (!this.plugin) throw new Error('Missing plugin name'); if (!this.message) throw new Error('Missing error message'); } util.inherits(PluginError, Error); PluginError.prototype._messageWithDetails = function() { var messageWithDetails = 'Message:\n ' + this.message; var details = this._messageDetails(); if (details !== '') { messageWithDetails += '\n' + details; } return messageWithDetails; }; PluginError.prototype._messageDetails = function() { if (!this.showProperties) { return ''; } var properties = arrayDiffer(Object.keys(this), propertiesNotToDisplay); if (properties.length === 0) { return ''; } var self = this; properties = properties.map(function stringifyProperty(prop) { return ' ' + prop + ': ' + self[prop]; }); return 'Details:\n' + properties.join('\n'); }; PluginError.prototype.toString = function () { var sig = chalk.red(this.name) + ' in plugin \'' + chalk.cyan(this.plugin) + '\''; var detailsWithStack = function(stack) { return this._messageWithDetails() + '\nStack:\n' + stack; }.bind(this); var msg; if (this.showStack) { if (this.__safety) { // There is no wrapped error, use the stack captured in the PluginError ctor msg = this.__safety.stack; } else if (this._stack) { msg = detailsWithStack(this._stack); } else { // Stack from wrapped error msg = detailsWithStack(this.stack); } } else { msg = this._messageWithDetails(); } return sig + '\n' + msg; }; module.exports = PluginError; gulp-util-3.0.7/lib/buffer.js000066400000000000000000000004321261133005700160150ustar00rootroot00000000000000var through = require('through2'); module.exports = function(fn) { var buf = []; var end = function(cb) { this.push(buf); cb(); if(fn) fn(null, buf); }; var push = function(data, enc, cb) { buf.push(data); cb(); }; return through.obj(push, end); }; gulp-util-3.0.7/lib/combine.js000066400000000000000000000003601261133005700161600ustar00rootroot00000000000000var pipeline = require('multipipe'); module.exports = function(){ var args = arguments; if (args.length === 1 && Array.isArray(args[0])) { args = args[0]; } return function(){ return pipeline.apply(pipeline, args); }; }; gulp-util-3.0.7/lib/env.js000066400000000000000000000001521261133005700153330ustar00rootroot00000000000000var parseArgs = require('minimist'); var argv = parseArgs(process.argv.slice(2)); module.exports = argv; gulp-util-3.0.7/lib/isBuffer.js000066400000000000000000000003211261133005700163060ustar00rootroot00000000000000var buf = require('buffer'); var Buffer = buf.Buffer; // could use Buffer.isBuffer but this is the same exact thing... module.exports = function(o) { return typeof o === 'object' && o instanceof Buffer; }; gulp-util-3.0.7/lib/isNull.js000066400000000000000000000000671261133005700160160ustar00rootroot00000000000000module.exports = function(v) { return v === null; }; gulp-util-3.0.7/lib/isStream.js000066400000000000000000000001571261133005700163370ustar00rootroot00000000000000var Stream = require('stream').Stream; module.exports = function(o) { return !!o && o instanceof Stream; }; gulp-util-3.0.7/lib/log.js000066400000000000000000000006561261133005700153350ustar00rootroot00000000000000var hasGulplog = require('has-gulplog'); module.exports = function(){ if(hasGulplog()){ // specifically deferring loading here to keep from registering it globally var gulplog = require('gulplog'); gulplog.info.apply(gulplog, arguments); } else { // specifically defering loading because it might not be used var fancylog = require('fancy-log'); fancylog.apply(null, arguments); } return this; }; gulp-util-3.0.7/lib/noop.js000066400000000000000000000001361261133005700155200ustar00rootroot00000000000000var through = require('through2'); module.exports = function () { return through.obj(); }; gulp-util-3.0.7/lib/template.js000066400000000000000000000011741261133005700163630ustar00rootroot00000000000000var template = require('lodash.template'); var reEscape = require('lodash._reescape'); var reEvaluate = require('lodash._reevaluate'); var reInterpolate = require('lodash._reinterpolate'); var forcedSettings = { escape: reEscape, evaluate: reEvaluate, interpolate: reInterpolate }; module.exports = function(tmpl, data) { var fn = template(tmpl, forcedSettings); var wrapped = function(o) { if (typeof o === 'undefined' || typeof o.file === 'undefined') { throw new Error('Failed to provide the current file as "file" to the template'); } return fn(o); }; return (data ? wrapped(data) : wrapped); }; gulp-util-3.0.7/package.json000066400000000000000000000024651261133005700157360ustar00rootroot00000000000000{ "name": "gulp-util", "description": "Utility functions for gulp plugins", "version": "3.0.7", "repository": "gulpjs/gulp-util", "author": "Fractal (http://wearefractal.com/)", "files": [ "index.js", "lib" ], "dependencies": { "array-differ": "^1.0.0", "array-uniq": "^1.0.2", "beeper": "^1.0.0", "chalk": "^1.0.0", "dateformat": "^1.0.11", "fancy-log": "^1.1.0", "gulplog": "^1.0.0", "has-gulplog": "^0.1.0", "lodash._reescape": "^3.0.0", "lodash._reevaluate": "^3.0.0", "lodash._reinterpolate": "^3.0.0", "lodash.template": "^3.0.0", "minimist": "^1.1.0", "multipipe": "^0.1.2", "object-assign": "^3.0.0", "replace-ext": "0.0.1", "through2": "^2.0.0", "vinyl": "^0.5.0" }, "devDependencies": { "buffer-equal": "^0.0.1", "coveralls": "^2.11.2", "event-stream": "^3.1.7", "istanbul": "^0.3.5", "istanbul-coveralls": "^1.0.1", "jshint": "^2.5.11", "lodash.templatesettings": "^3.0.0", "mocha": "^2.0.1", "rimraf": "^2.2.8", "should": "^7.0.1" }, "scripts": { "test": "jshint *.js lib/*.js test/*.js && mocha", "coveralls": "istanbul cover _mocha --report lcovonly && istanbul-coveralls" }, "engines": { "node": ">=0.10" }, "license": "MIT" } gulp-util-3.0.7/test/000077500000000000000000000000001261133005700144205ustar00rootroot00000000000000gulp-util-3.0.7/test/File.js000066400000000000000000000025541261133005700156430ustar00rootroot00000000000000var util = require('..'); var should = require('should'); var path = require('path'); require('mocha'); describe('File()', function() { it('should return a valid file', function(done) { var fname = path.join(__dirname, './fixtures/test.coffee'); var base = path.join(__dirname, './fixtures/'); var file = new util.File({ base: base, cwd: __dirname, path: fname }); should.exist(file, 'root'); should.exist(file.relative, 'relative'); should.exist(file.path, 'path'); should.exist(file.cwd, 'cwd'); should.exist(file.base, 'base'); file.path.should.equal(fname); file.cwd.should.equal(__dirname); file.base.should.equal(base); file.relative.should.equal('test.coffee'); done(); }); it('should return a valid file 2', function(done) { var fname = path.join(__dirname, './fixtures/test.coffee'); var base = __dirname; var file = new util.File({ base: base, cwd: __dirname, path: fname }); should.exist(file, 'root'); should.exist(file.relative, 'relative'); should.exist(file.path, 'path'); should.exist(file.cwd, 'cwd'); should.exist(file.base, 'base'); file.path.should.equal(fname); file.cwd.should.equal(__dirname); file.base.should.equal(base); file.relative.should.equal(path.normalize('fixtures/test.coffee')); done(); }); });gulp-util-3.0.7/test/PluginError.js000066400000000000000000000161521261133005700172330ustar00rootroot00000000000000var util = require('..'); require('should'); require('mocha'); describe('PluginError()', function(){ it('should default name to Error', function() { var err = new util.PluginError('test', 'something broke'); err.name.should.equal('Error'); }); it('should default name to Error, even when wrapped error has no name', function() { var realErr = { message: 'something broke' }; var err = new util.PluginError('test', realErr); err.name.should.equal('Error'); }); it('should print the plugin name in toString', function(){ var err = new util.PluginError('test', 'something broke'); err.toString().should.containEql('test'); }); it('should not include the stack by default in toString', function(){ var err = new util.PluginError('test', 'something broke'); // just check that there are no 'at' lines err.toString().should.not.containEql('at'); }); it('should include the stack when specified in toString', function(){ var err = new util.PluginError('test', 'something broke', {stack: 'at huh', showStack: true}); // just check that there are 'at' lines err.toString().should.containEql('at'); }); it('should take arguments as one object', function(){ var err = new util.PluginError({ plugin: 'test', message: 'something broke' }); err.plugin.should.equal('test'); err.message.should.equal('something broke'); }); it('should take arguments as plugin name and one object', function(){ var err = new util.PluginError('test', { message: 'something broke' }); err.plugin.should.equal('test'); err.message.should.equal('something broke'); }); it('should take arguments as plugin name and message', function(){ var err = new util.PluginError('test', 'something broke'); err.plugin.should.equal('test'); err.message.should.equal('something broke'); }); it('should take arguments as plugin name, message, and one object', function(){ var err = new util.PluginError('test', 'something broke', {showStack: true}); err.plugin.should.equal('test'); err.message.should.equal('something broke'); err.showStack.should.equal(true); }); it('should take arguments as plugin name, error, and one object', function(){ var realErr = new Error('something broke'); realErr.fileName = 'original.js'; var err = new util.PluginError('test', realErr, {showStack: true, fileName: 'override.js'}); err.plugin.should.equal('test'); err.message.should.equal('something broke'); err.fileName.should.equal('override.js'); err.showStack.should.equal(true); }); it('should take properties from error', function() { var realErr = new Error('something broke'); realErr.abstractProperty = 'abstract'; var err = new util.PluginError('test', realErr); err.plugin.should.equal('test'); err.message.should.equal('something broke'); err.abstractProperty.should.equal('abstract'); }); it('should be configured to show properties by default', function(){ var err = new util.PluginError('test', 'something broke'); err.showProperties.should.be.true; }); it('should not be configured to take option to show properties', function(){ var err = new util.PluginError('test', 'something broke', {showProperties: false}); err.showProperties.should.be.false; }); it('should show properties', function() { var err = new util.PluginError('test', 'it broke', {showProperties: true}); err.fileName = 'original.js'; err.lineNumber = 35; err.toString().should.containEql('it broke'); err.toString().should.not.containEql('message:'); err.toString().should.containEql('fileName:'); }); it('should show properties', function() { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; var err = new util.PluginError('test', realErr, {showProperties: true}); err.toString().should.not.containEql('message:'); err.toString().should.containEql('fileName:'); }); it('should not show properties', function() { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; var err = new util.PluginError('test', realErr, {showProperties: false}); err.toString().should.not.containEql('message:'); err.toString().should.not.containEql('fileName:'); }); it('should not show properties, but should show stack', function() { var err = new util.PluginError('test', 'it broke', {stack: 'test stack', showStack: true, showProperties: false}); err.fileName = 'original.js'; err.lineNumber = 35; err.toString().should.not.containEql('message:'); err.toString().should.not.containEql('fileName:'); err.toString().should.containEql('test stack'); }); it('should not show properties, but should show stack for real error', function() { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; realErr.stack = 'test stack'; var err = new util.PluginError('test', realErr, {showStack: true, showProperties: false}); err.toString().indexOf('message:').should.equal(-1); err.toString().indexOf('fileName:').should.equal(-1); err.toString().indexOf('test stack').should.not.equal(-1); }); it('should not show properties, but should show stack for _stack', function() { var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.lineNumber = 35; realErr._stack = 'test stack'; var err = new util.PluginError('test', realErr, {showStack: true, showProperties: false}); err.toString().indexOf('message:').should.equal(-1); err.toString().indexOf('fileName:').should.equal(-1); err.toString().indexOf('test stack').should.not.equal(-1); }); it('should show properties and stack', function(){ var realErr = new Error('something broke'); realErr.fileName = 'original.js'; realErr.stack = 'test stack'; var err = new util.PluginError('test', realErr, {showStack: true}); err.toString().indexOf('message:').should.equal(-1); err.toString().indexOf('fileName:').should.not.equal(-1); err.toString().indexOf('test stack').should.not.equal(-1); }); it('should show properties added after the error is created', function(){ var realErr = new Error('something broke'); var err = new util.PluginError('test', realErr); err.fileName = 'original.js'; err.toString().indexOf('message:').should.equal(-1); err.toString().indexOf('fileName:').should.not.equal(-1); }); it('should toString quickly', function(done) { this.timeout(100); var err = new util.PluginError('test', 'it broke', {showStack: true}); err.toString(); done(); }); it('should toString quickly with original error', function(done) { this.timeout(100); var realErr = new Error('it broke'); var err = new util.PluginError('test', realErr, {showStack: true}); err.toString(); done(); }); it('should not show "Details:" if there are no properties to show', function() { var err = new util.PluginError('plugin', 'message'); err.toString().indexOf('Details:').should.equal(-1); }); }); gulp-util-3.0.7/test/beep.js000066400000000000000000000007561261133005700157010ustar00rootroot00000000000000var util = require('..'); require('should'); require('mocha'); describe('beep()', function(){ it('should send the right code to stdout', function(done){ var writtenValue; // Stub process.stdout.write var stdout_write = process.stdout.write; process.stdout.write = function(value) { writtenValue = value; }; util.beep(); writtenValue.should.equal('\x07'); // Restore process.stdout.write process.stdout.write = stdout_write; done(); }); }); gulp-util-3.0.7/test/buffer.js000066400000000000000000000017431261133005700162340ustar00rootroot00000000000000var util = require('..'); var should = require('should'); var es = require('event-stream'); require('mocha'); describe('buffer()', function(){ it('should buffer stuff and return an array into the callback', function(done){ var src = [1,2,3]; var inp = es.readArray(src); inp.pipe(util.buffer(function(err, data){ should.not.exist(err); should.exist(data); data.should.eql(src); done(); })); }); it('should buffer stuff and emit it as a data event', function(done){ var src = [1,2,3]; var inp = es.readArray(src); inp.pipe(util.buffer()).on('data', function(data){ should.exist(data); data.should.eql(src); done(); }); }); it('should buffer stuff and return a stream with the buffered data', function(done){ var src = [1,2,3]; var inp = es.readArray(src); inp.pipe(util.buffer()).pipe(es.through(function(data) { should.exist(data); data.should.eql(src); done(); })); }); });gulp-util-3.0.7/test/colors.js000066400000000000000000000003301261133005700162530ustar00rootroot00000000000000var util = require('..'); require('should'); require('mocha'); describe('colors', function(){ it('should be a chalk instance', function(done){ util.colors.should.equal(require('chalk')); done(); }); }); gulp-util-3.0.7/test/combine.js000066400000000000000000000021441261133005700163730ustar00rootroot00000000000000var util = require('..'); var should = require('should'); var es = require('event-stream'); var Stream = require('stream'); require('mocha'); describe('combine()', function(){ it('should return a function', function(done){ var src = [1,2,3]; var inp = es.readArray(src); var factory = util.combine(inp); factory.should.be.type('function'); done(); }); it('should return a function that returns a stream combination', function(done){ var src = [1,2,3]; var inp = es.readArray(src); var inp2 = es.writeArray(function(err, data){ should.not.exist(err); data.should.eql(src); done(); }); var factory = util.combine(inp, inp2); factory().should.be.instanceof(Stream); }); it('should return a function that returns a stream combination when given an array', function(done){ var src = [1,2,3]; var inp = es.readArray(src); var inp2 = es.writeArray(function(err, data){ should.not.exist(err); data.should.eql(src); done(); }); var factory = util.combine([inp, inp2]); factory().should.be.instanceof(Stream); }); });gulp-util-3.0.7/test/date.js000066400000000000000000000010031261133005700156650ustar00rootroot00000000000000var util = require('..'); require('should'); require('mocha'); describe('date', function() { it('should be a date format instance', function(done) { util.date.should.equal(require('dateformat')); done(); }); it('should return today\'s date', function(done) { var time = new Date(); var dateutil = util.date('HH:MM:ss'); dateutil.should.equal(('0' + time.getHours()).slice(-2) + ':' + ('0' + time.getMinutes()).slice(-2) + ':' + ('0' + time.getSeconds()).slice(-2)); done(); }); }); gulp-util-3.0.7/test/env.js000066400000000000000000000003361261133005700155500ustar00rootroot00000000000000var util = require('..'); var should = require('should'); require('mocha'); describe('env', function(){ it('should exist', function(done){ should.exist(util.env); should.exist(util.env._); done(); }); }); gulp-util-3.0.7/test/isBuffer.js000066400000000000000000000005751261133005700165320ustar00rootroot00000000000000var util = require('..'); var through = require('through2'); require('should'); require('mocha'); describe('isBuffer()', function(){ it('should work on a buffer', function(done){ util.isBuffer(new Buffer('huh')).should.equal(true); done(); }); it('should not work on a stream', function(done){ util.isBuffer(through()).should.equal(false); done(); }); }); gulp-util-3.0.7/test/isNull.js000066400000000000000000000007371261133005700162330ustar00rootroot00000000000000var util = require('..'); var through = require('through2'); require('should'); require('mocha'); describe('isNull()', function(){ it('should work on a null', function(done){ util.isNull(null).should.equal(true); done(); }); it('should not work on a stream', function(done){ util.isNull(through()).should.equal(false); done(); }); it('should not work on undefined', function(done){ util.isNull(undefined).should.equal(false); done(); }); }); gulp-util-3.0.7/test/isStream.js000066400000000000000000000005751261133005700165540ustar00rootroot00000000000000var util = require('..'); var through = require('through2'); require('should'); require('mocha'); describe('isStream()', function(){ it('should work on a stream', function(done){ util.isStream(through()).should.equal(true); done(); }); it('should not work on a buffer', function(done){ util.isStream(new Buffer('huh')).should.equal(false); done(); }); }); gulp-util-3.0.7/test/linefeed.js000066400000000000000000000001561261133005700165330ustar00rootroot00000000000000/* var util = require('..'); var should = require('should'); var path = require('path'); require('mocha'); */ gulp-util-3.0.7/test/log.js000066400000000000000000000024231261133005700155400ustar00rootroot00000000000000var util = require('..'); require('should'); require('mocha'); describe('log()', function(){ it('should work i guess', function(done){ var count = 0; var writtenValue = ''; // Stub process.stdout.write var stdout_write = process.stdout.write; process.stdout.write = function(value) { writtenValue += value; if(++count > 2){ // Restore process.stdout.write after test process.stdout.write = stdout_write; } }; util.log(1, 2, 3, 4, 'five'); var time = util.date(new Date(), 'HH:MM:ss'); writtenValue.should.eql('[' + util.colors.grey(time) + '] 1 2 3 4 \'five\'\n'); done(); }); it('should accept formatting', function(done){ var count = 0; var writtenValue = ''; // Stub process.stdout.write var stdout_write = process.stdout.write; process.stdout.write = function(value) { writtenValue += value; if(++count > 2){ // Restore process.stdout.write after test process.stdout.write = stdout_write; } }; util.log('%s %d %j', 'something', 0.1, {key: 'value'}); var time = util.date(new Date(), 'HH:MM:ss'); writtenValue.should.eql( '[' + util.colors.grey(time) + '] '+ 'something 0.1 {\"key\":\"value\"}\n' ); done(); }); }); gulp-util-3.0.7/test/noop.js000066400000000000000000000011411261133005700157260ustar00rootroot00000000000000var util = require('..'); var should = require('should'); var es = require('event-stream'); require('mocha'); describe('noop()', function(){ it('should return a stream', function(done){ util.isStream(util.noop()).should.equal(true); done(); }); it('should return a stream that passes through all data', function(done){ var inp = [1,2,3,4,5,6,7,8,9]; var stream = util.noop(); es.readArray(inp) .pipe(stream) .pipe(es.writeArray(function(err, arr){ should.not.exist(err); should.exist(arr); arr.should.eql(inp); done(); })); }); }); gulp-util-3.0.7/test/replaceExtension.js000066400000000000000000000017321261133005700202710ustar00rootroot00000000000000var util = require('..'); var should = require('should'); var path = require('path'); require('mocha'); describe('replaceExtension()', function() { it('should return a valid replaced extension on nested', function(done) { var fname = path.join(__dirname, './fixtures/test.coffee'); var expected = path.join(__dirname, './fixtures/test.js'); var nu = util.replaceExtension(fname, '.js'); should.exist(nu); nu.should.equal(expected); done(); }); it('should return a valid replaced extension on flat', function(done) { var fname = 'test.coffee'; var expected = 'test.js'; var nu = util.replaceExtension(fname, '.js'); should.exist(nu); nu.should.equal(expected); done(); }); it('should not return a valid replaced extension on empty string', function(done) { var fname = ''; var expected = ''; var nu = util.replaceExtension(fname, '.js'); should.exist(nu); nu.should.equal(expected); done(); }); }); gulp-util-3.0.7/test/template.js000066400000000000000000000042421261133005700165730ustar00rootroot00000000000000var util = require('..'); var should = require('should'); require('mocha'); describe('template()', function(){ it('should work with just a template', function(done){ var opt = { name:'todd', file: { path: 'hi.js' } }; var expected = 'test todd hi.js'; var tmpl = util.template('test <%= name %> <%= file.path %>'); should.exist(tmpl); 'function'.should.equal(typeof(tmpl)); // eval it now var etmpl = tmpl(opt); 'string'.should.equal(typeof(etmpl)); etmpl.should.equal(expected); done(); }); it('should work with a template and data', function(done){ var opt = { name:'todd', file: { path: 'hi.js' } }; var expected = 'test todd hi.js'; var tmpl = util.template('test <%= name %> <%= file.path %>', opt); should.exist(tmpl); 'string'.should.equal(typeof(tmpl)); tmpl.should.equal(expected); done(); }); it('should throw an error when no file object is passed', function(){ var opt = { name:'todd' }; should.throws(function() { util.template('test <%= name %> <%= file.path %>', opt); }); }); it('should ignore modified templateSettings', function(done){ var templateSettings = require('lodash.templatesettings'); templateSettings.interpolate = /\{\{([\s\S]+?)\}\}/g; var opt = { name:'todd', file: { path: 'hi.js' } }; var expected = 'test {{name}} hi.js'; var tmpl = util.template('test {{name}} <%= file.path %>'); should.exist(tmpl); 'function'.should.equal(typeof(tmpl)); // eval it now var etmpl = tmpl(opt); 'string'.should.equal(typeof(etmpl)); etmpl.should.equal(expected); done(); }); it('should allow ES6 delimiters', function(done){ var opt = { name:'todd', file: { path: 'hi.js' } }; var expected = 'test todd hi.js'; var tmpl = util.template('test ${name} ${file.path}'); should.exist(tmpl); 'function'.should.equal(typeof(tmpl)); // eval it now var etmpl = tmpl(opt); 'string'.should.equal(typeof(etmpl)); etmpl.should.equal(expected); done(); }); });