From 858fa76a8cba653c275aa2bc740a12685b44ddb8 Mon Sep 17 00:00:00 2001 From: tunnckoCore Date: Sun, 12 Jul 2015 16:32:29 +0300 Subject: [PATCH] update --- .coveralls.yml | 1 - .editorconfig | 22 ++----- .gitattributes | 49 ---------------- .gitignore | 1 + .jscsrc | 116 ------------------------------------- .jshintignore | 23 -------- .jshintrc | 37 ------------ .travis.yml | 30 +++++++--- history.md => CHANGELOG.md | 10 ++-- CONTRIBUTING.md | 32 ++++++++++ LICENSE.md | 22 +++++++ README.md | 83 ++++++++++++++++++++++++++ index.js | 36 +++++++----- license.md | 22 ------- package.json | 36 +++++------- readme.md | 67 --------------------- test.js | 96 +++++++++++++++--------------- 17 files changed, 254 insertions(+), 429 deletions(-) delete mode 100644 .coveralls.yml delete mode 100644 .gitattributes delete mode 100644 .jscsrc delete mode 100644 .jshintignore delete mode 100644 .jshintrc rename history.md => CHANGELOG.md (66%) create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE.md create mode 100644 README.md delete mode 100644 license.md delete mode 100644 readme.md diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 790f583..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1 +0,0 @@ -repo_token: WwzjikNqrq3iHgead2YOoD9x44wIPC8Nw diff --git a/.editorconfig b/.editorconfig index 5595e72..ef5ea46 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,28 +7,16 @@ root = true [*] -indent_style = space charset = utf-8 end_of_line = lf -insert_final_newline = false -trim_trailing_whitespace = false - -[*.{js,php}] indent_size = 2 +indent_style = space insert_final_newline = true trim_trailing_whitespace = true -[*.{php,html}] +[*.php] indent_size = 4 -[*.{json,cson,yml,yaml,html,md,jade,css,stylus}] -indent_size = 2 - -[Makefile] -indent_size = 2 -indent_style = tab - -[.*rc] -indent_size = 2 -indent_style = space -trim_trailing_whitespace = true \ No newline at end of file +[*.md] +insert_final_newline = false +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index bf808d5..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -# .gitattributes -# -# Copyright (c) 2015 Charlike Mike Reagent, contributors. -# Released under the MIT license. -# - -# These settings are for any web project - -# Handle line endings automatically for files detected as text -# and leave all files detected as binary untouched. - -* text=auto - -# -# The above will handle all files NOT found below -# These files are text and should be normalized (Convert crlf => lf) -# - -*.php text -*.css text -*.js text -*.htm text -*.html text -*.xml text -*.txt text -*.ini text -*.inc text -.htaccess text - -# -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -# - -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.mov binary -*.mp4 binary -*.mp3 binary -*.flv binary -*.fla binary -*.swf binary -*.gz binary -*.zip binary -*.7z binary -*.ttf binary diff --git a/.gitignore b/.gitignore index e093736..d20309c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ nbproject cache temp tmp +vinyl-filter-since # Packages # # ########## diff --git a/.jscsrc b/.jscsrc deleted file mode 100644 index 8104e2f..0000000 --- a/.jscsrc +++ /dev/null @@ -1,116 +0,0 @@ -{ - "fileExtensions": [".js"], - "maxErrors": 10, - "esnext": true, - "safeContextKeyword": ["self", "_this", "that"], - - "maximumLineLength": { - "value": 80, - "allowUrlComments": true, - "allowComments": true, - "allowRegex": true - }, - - "validateQuoteMarks": "'", - "validateIndentation": 2, - - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "case", - "return", - "try", - "catch", - "typeof" - ], - - "requireCamelCaseOrUpperCaseIdentifiers": true, - "requireSpacesInConditionalExpression": true, - "requireSpaceBeforeBlockStatements": true, - "requireSpaceBeforeBinaryOperators": true, - "requireOperatorBeforeLineBreak": true, - "requireCapitalizedConstructors": true, - "requireParenthesesAroundIIFE": true, - "requireCommaBeforeLineBreak": true, - "requireLineFeedAtFileEnd": true, - "requireDotNotation": true, - - "disallowYodaConditions": true, - "disallowMultipleLineStrings": true, - "disallowMultipleLineBreaks": true, - "disallowMultipleVarDecl": true, - "disallowMixedSpacesAndTabs": true, - "disallowTrailingComma": true, - "disallowTrailingWhitespace": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowSpacesInsideObjectBrackets": "all", - "disallowSpacesInsideParentheses": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowNewlineBeforeBlockStatements": true, - "disallowSpaceBeforePostfixUnaryOperators": true, - "disallowImplicitTypeConversion": ["string"], - "disallowKeywords": ["with"], - "disallowKeywordsOnNewLine": ["else"], - "disallowSpacesInCallExpression": true, - - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "disallowSpacesInFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "disallowSpacesInFunctionDeclaration": { - "beforeOpeningRoundBrace": true - }, - - "plugins": [ - "jscs-jsdoc" - ], - "jsDoc": { - "checkParamNames": true, - "requireParamTypes": true, - "checkRedundantParams": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkRedundantAccess": true, - "checkTypes": "capitalizedNativeCase", - "checkAnnotations": { - "preset": "jsdoc3", - "extra": { - "api": true - } - } - }, - - "excludeFiles": [ - "_gh_pages/**", - "node_modules/**", - "bower_components/**", - "components/**", - "vendor/**", - "build/**", - "dest/**", - "dist/**", - "src/**", - "lib-cov/**", - "coverage/**", - "nbproject/**", - "cache/**", - "temp/**", - "tmp/**" - ] -} \ No newline at end of file diff --git a/.jshintignore b/.jshintignore deleted file mode 100644 index bbe0714..0000000 --- a/.jshintignore +++ /dev/null @@ -1,23 +0,0 @@ -# .jshintignore -# -# Copyright (c) 2015 Charlike Mike Reagent, contributors. -# Released under the MIT license. -# - -# Always-ignore dirs # -# #################### -_gh_pages -node_modules -bower_components -components -vendor -build -dest -dist -src -lib-cov -coverage -nbproject -cache -temp -tmp \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index a3f48c9..0000000 --- a/.jshintrc +++ /dev/null @@ -1,37 +0,0 @@ -{ - "maxerr" : 10, - "indent" : 2, - - "maxparams" : 3, - "maxdepth" : 3, - "maxstatements" : 15, - "maxlen" : 120, - - "camelcase" : true, - "forin" : false, - "immed" : true, - "newcap" : true, - "quotmark" : "single", - - "asi" : true, - "eqnull" : true, - "esnext" : true, - "funcscope" : true, - "globalstrict" : true, - "lastsemic" : true, - "shadow" : true, - - "node" : true, - "nonstandard" : true, - - "globals": { - "it": true, - "describe": true, - "beforeEach": true, - "afterEach": true, - "before": true, - "after": true, - "define": true, - "should": true - } -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 73e1d48..1ec1310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,25 @@ +language: "node_js" sudo: false -language: node_js + node_js: - - "iojs" - "0.10" - - "0.11" - "0.12" -matrix: - allow_failures: - - node_js: "0.10" - fast_finish: true -script: "npm run-script test-travis" -after_script: "npm install coveralls && cat ./coverage/lcov.info | coveralls" \ No newline at end of file + - "1" + - "2" + +notifications: + email: + on_success: never + on_failure: never + +before_script: + - npm install standard + - standard + +script: + - npm install istanbul + - istanbul cover test.js + +after_success: + - npm install coveralls + - cat ./coverage/lcov.info | coveralls diff --git a/history.md b/CHANGELOG.md similarity index 66% rename from history.md rename to CHANGELOG.md index b68ab04..be64f3c 100644 --- a/history.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ -## v2.0.0 / March 31, 2015 +## 2.0.0 / 2015-03-31 - Release v2.0.0 / npm@v2.0.0 - lint - update tests, 100% coverage @@ -8,15 +8,15 @@ - remove `debug` - add `assert-kindof` -## v1.0.1 / March 31, 2015 +## 1.0.1 / 2015-03-31 - Release v1.0.1 / npm@v1.0.1 - add attribution, close #1 -## v1.0.0 / March 19, 2015 +## 1.0.0 / 2015-03-19 - Release v1.0.0 / npm@v1.0.0 - add keywords - add usage - travis and coveralls sync -## v0.0.0 / March 19, 2015 -- first commits / npm@v0.0.0 \ No newline at end of file +## 0.0.0 / 2015-03-19 +- first commits \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5312165 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing Guidelines + +Contributions are always welcome! + +**Before spending lots of time on something, ask for feedback on your idea first!** + +Please search issues and pull requests before adding something new to avoid duplicating efforts and conversations. + + +## Installing + +Fork and clone the repo, then `npm install` to install all dependencies and `npm test` to ensure all is okey before you start anything. + + +## Testing + +Tests are run with `npm test`. Please ensure all tests are passing before submitting a pull request (unless you're creating a failing test to increase test coverage or show a problem). + +## Code Style + +[![standard][standard-image]][standard-url] + +This repository uses [`standard`][standard-url] to maintain code style and consistency, and to avoid style arguments. You are encouraged to install it globally. `npm test` runs `standard` so you don't have to! + +``` +npm i standard -g +``` + +It is intentional to don't have `standard`, `istanbul` and `coveralls` in the devDependencies. Travis will handle all that stuffs. That approach will save bandwidth also installing and development time. + +[standard-image]: https://cdn.rawgit.com/feross/standard/master/badge.svg +[standard-url]: https://github.com/feross/standard \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..06bdf36 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,22 @@ +# The MIT License + +Copyright (c) 2015, [Charlike Make Reagent](http://j.mp/1stW47C) +Copyright (c) 2014-2015, [Fractal](https://github.com/wearefractal/vinyl-fs) + +> 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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ef12482 --- /dev/null +++ b/README.md @@ -0,0 +1,83 @@ +# [vinyl-filter-since][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] + +> Gulp/vinyl plugin, filter files that have been modified since given Date or Number. + +[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url] + + +## Install +``` +npm i vinyl-filter-since --save +npm test +``` + + +## Usage +> For more use-cases see the [tests](./test.js) + +```js +var vinylFilterSince = require('vinyl-filter-since'); +var gulp = require('gulp'); +var through2 = require('through2'); + +gulp.src('some/file/path/*.js') + .pipe(vinylFilterSince(new Date('2015-03-16 13:27:54'))) + .pipe(through2.obj(function(file, enc, next) { + // will not come here if file is older than given date + })) +``` + + +## Contributing +Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/tunnckoCore/vinyl-filter-since/issues/new). +But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines. + + +## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url] + +[![tunnckocore.tk][author-www-img]][author-www-url] [![keybase tunnckocore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url] + + +[npmjs-url]: https://www.npmjs.com/package/vinyl-filter-since +[npmjs-img]: https://img.shields.io/npm/v/vinyl-filter-since.svg?label=vinyl-filter-since + +[license-url]: https://github.com/tunnckoCore/vinyl-filter-since/blob/master/LICENSE.md +[license-img]: https://img.shields.io/badge/license-MIT-blue.svg + + +[codeclimate-url]: https://codeclimate.com/github/tunnckoCore/vinyl-filter-since +[codeclimate-img]: https://img.shields.io/codeclimate/github/tunnckoCore/vinyl-filter-since.svg + +[travis-url]: https://travis-ci.org/tunnckoCore/vinyl-filter-since +[travis-img]: https://img.shields.io/travis/tunnckoCore/vinyl-filter-since.svg + +[coveralls-url]: https://coveralls.io/r/tunnckoCore/vinyl-filter-since +[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/vinyl-filter-since.svg + +[david-url]: https://david-dm.org/tunnckoCore/vinyl-filter-since +[david-img]: https://img.shields.io/david/tunnckoCore/vinyl-filter-since.svg + +[standard-url]: https://github.com/feross/standard +[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg + + +[author-www-url]: http://www.tunnckocore.tk +[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg + +[keybase-url]: https://keybase.io/tunnckocore +[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg + +[author-npm-url]: https://www.npmjs.com/~tunnckocore +[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg + +[author-twitter-url]: https://twitter.com/tunnckoCore +[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg + +[author-github-url]: https://github.com/tunnckoCore +[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg + +[freenode-url]: http://webchat.freenode.net/?channels=charlike +[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg + +[new-message-url]: https://github.com/tunnckoCore/messages +[new-message-img]: https://img.shields.io/badge/send%20me-message-green.svg diff --git a/index.js b/index.js index e24af1f..e503aaa 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,35 @@ -/** +/*! * vinyl-filter-since * - * Copyright (c) 2015 Charlike Mike Reagent, contributors. + * Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk) * Released under the MIT license. */ -'use strict'; +'use strict' -var Transform = require('readable-stream/transform'); +var Transform = require('readable-stream/transform') -var label = 'vinyl-filter-since'; - -module.exports = function vinylFilterSince(since) { - if (!(since instanceof Date) && typeof since !== 'number') { - throw new TypeError(label + ':15, expect `since` to be date or number.'); +module.exports = function vinylFilterSince (since) { + if (!isValid(since)) { + throw new TypeError('vinyl-filter-since: expect `since` be date or number') } return new Transform({ objectMode: true, - transform: function(file, enc, next) { + transform: function (file, enc, next) { if (since < file.stat.mtime) { - this.push(file); - return; + this.push(file) + return } - next(); + next() } - }); -}; + }) +} + +function isValid (val) { + if (typeof val === 'number' || val instanceof Number || val instanceof Date) { + return true + } + + return false +} diff --git a/license.md b/license.md deleted file mode 100644 index 66c1c15..0000000 --- a/license.md +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015 [Charlike Make Reagent](http://j.mp/1stW47C), contributors - -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. \ No newline at end of file diff --git a/package.json b/package.json index 6ef3182..3da388f 100644 --- a/package.json +++ b/package.json @@ -1,21 +1,22 @@ { "name": "vinyl-filter-since", "version": "2.0.0", - "description": "Vinyl adapter (gulp plugin) to filter files that have been modified since given Date or Number", + "description": "Gulp/vinyl plugin, filter files that have been modified since given Date or Number.", + "repository": "tunnckoCore/vinyl-filter-since", + "author": "Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)", + "main": "index.js", + "license": "MIT", "scripts": { - "lint": "jshint index.js && jscs index.js --reporter inline", - "test": "lab -cv test.js", - "test-travis": "lab -cv test.js && lab -r lcov -o ./coverage/lcov.info test.js" + "test": "standard && node test.js" }, - "author": { - "name": "Charlike Mike Reagent", - "email": "mameto_100@mail.bg", - "url": "https://github.com/tunnckoCore" + "dependencies": { + "readable-stream": "~2.0.1" + }, + "devDependencies": { + "assertit": "^0.1.0", + "through2": "^2.0.0", + "vinyl-fs": "^1.0.0" }, - "repository": "tunnckoCore/vinyl-filter-since", - "files": [ - "index.js" - ], "keywords": [ "file", "filter", @@ -29,14 +30,5 @@ "stream", "util", "vinyl" - ], - "license": "MIT", - "dependencies": { - "readable-stream": "^2.0.1" - }, - "devDependencies": { - "lab": "^5.12.1", - "through2": "^2.0.0", - "vinyl-fs": "^1.0.0" - } + ] } diff --git a/readme.md b/readme.md deleted file mode 100644 index 8f04ce4..0000000 --- a/readme.md +++ /dev/null @@ -1,67 +0,0 @@ -## [![npm][npmjs-img]][npmjs-url] [![mit license][license-img]][license-url] [![build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![deps status][daviddm-img]][daviddm-url] - -> Vinyl adapter to filter files that have been modified since given Date or Number - -## Install -``` -npm i --save vinyl-filter-since -npm test -``` - - -## Usage -> For more use-cases see the [tests](./test.js) - -```js -var vinylFilterSince = require('vinyl-filter-since'); -var gulp = require('gulp'); -var through2 = require('through2'); - -gulp.src('some/file/path/*.js') - .pipe(vinylFilterSince(new Date('2015-03-16 13:27:54'))) - .pipe(through2.obj(function(file, enc, next) { - // will not come here if file is older than given date - })) -``` - - -## Author -**Charlike Mike Reagent** -+ [gratipay/tunnckoCore][author-gratipay] -+ [twitter/tunnckoCore][author-twitter] -+ [github/tunnckoCore][author-github] -+ [npmjs/tunnckoCore][author-npmjs] -+ [more ...][contrib-more] - - -## License [![MIT license][license-img]][license-url] -Copyright (c) 2015 [Charlike Mike Reagent][contrib-more], [contributors][contrib-graf]. -Copyright (c) 2014-2015 [Fractal](https://github.com/wearefractal/vinyl-fs). -Released under the [`MIT`][license-url] license. - -[npmjs-url]: http://npm.im/vinyl-filter-since -[npmjs-img]: https://img.shields.io/npm/v/vinyl-filter-since.svg?style=flat&label=vinyl-filter-since - -[coveralls-url]: https://coveralls.io/r/tunnckoCore/vinyl-filter-since?branch=master -[coveralls-img]: https://img.shields.io/coveralls/tunnckoCore/vinyl-filter-since.svg?style=flat - -[license-url]: https://github.com/tunnckoCore/vinyl-filter-since/blob/master/license.md -[license-img]: https://img.shields.io/badge/license-MIT-blue.svg?style=flat - -[travis-url]: https://travis-ci.org/tunnckoCore/vinyl-filter-since -[travis-img]: https://img.shields.io/travis/tunnckoCore/vinyl-filter-since.svg?style=flat - -[daviddm-url]: https://david-dm.org/tunnckoCore/vinyl-filter-since -[daviddm-img]: https://img.shields.io/david/tunnckoCore/vinyl-filter-since.svg?style=flat - -[author-gratipay]: https://gratipay.com/tunnckoCore -[author-twitter]: https://twitter.com/tunnckoCore -[author-github]: https://github.com/tunnckoCore -[author-npmjs]: https://npmjs.org/~tunnckocore - -[contrib-more]: http://j.mp/1stW47C -[contrib-graf]: https://github.com/tunnckoCore/vinyl-filter-since/graphs/contributors - -*** - -_Proudly generated by [docks(1)](https://github.com/tunnckoCore), March 31, 2015_ \ No newline at end of file diff --git a/test.js b/test.js index 99b69c9..fa993c5 100644 --- a/test.js +++ b/test.js @@ -1,61 +1,65 @@ -/** +/*! * vinyl-filter-since * - * Copyright (c) 2015 Charlike Mike Reagent, contributors. + * Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk) * Released under the MIT license. */ -'use strict'; +/* jshint asi:true */ -var assert = require('assert'); -var fs = require('fs'); -var path = require('path'); -var vinylFs = require('vinyl-fs'); -var vinylFilterSince = require('./'); -var through2 = require('through2'); +'use strict' -var fixture = path.join(__dirname, './package.json'); +var fs = require('fs') +var path = require('path') +var test = require('assertit') +var through = require('through2') +var vinylFs = require('vinyl-fs') +var vinylFilterSince = require('./index') -// testing framework -var lab = exports.lab = require('lab').script(); -var describe = lab.describe; -var it = lab.it; +var pkgJson = path.join(__dirname, './package.json') // DRY -function testit(lastUpdateDate, len, done) { - var stream = vinylFs.src('*.json'); - var files = []; +function plugin (lastUpdateDate, len, done) { + var stream = vinylFs.src('*.json') + var files = [] stream - .pipe(through2.obj()) + .pipe(through.obj()) .pipe(vinylFilterSince(lastUpdateDate)) - .pipe(through2.obj(function(file, enc, next) { - files.push(file); - next(); - })); - - stream.once('end', function _end() { - assert.strictEqual(files.length, len); - done(); - }); + .pipe(through.obj(function (file, enc, next) { + files.push(file) + next() + })) + + stream.once('end', function _end () { + test.equal(files.length, len) + done() + }) } -describe('vinyl-filter-since:', function() { - it('should throw TypeError if no Date or Number given', function(done) { - assert.throws(function _fixture() { - testit('foo bar', 0, function() {}); - }, /to be date or number/); - - assert.throws(function _fixture() { - testit([1, 2, 3], 0, function() {}); - }, TypeError); - - done(); - }); - it('should glob a file changed after since', function(done) { - testit(new Date((+fs.statSync(fixture).mtime) - 2200), 1, done); - }); - it('should not glob a file changed before since', function(done) { - testit(new Date((+fs.statSync(fixture).mtime) + 1300), 0, done); - }); -}); +test('vinyl-filter-since:', function () { + test('should throw TypeError if no Date object or Number given', function (done) { + function fixtureString () { + plugin('foo bar', 0, function () {}) + } + + function fixtureArray () { + plugin([1, 2, 3], 0, function () {}) + } + + test.throws(fixtureString, TypeError) + test.throws(fixtureString, /be date or number/) + test.throws(fixtureArray, TypeError) + test.throws(fixtureArray, /be date or number/) + done() + }) + test('should glob a file changed after if `since` is Date object', function (done) { + plugin(new Date((+fs.statSync(pkgJson).mtime) - 2200), 1, done) + }) + test('should glob a file changed after if `since` is Number', function (done) { + plugin(1436706945226, 1, done) + }) + test('should not glob a file if changed before', function (done) { + plugin(Date.now(), 0, done) + }) +})