diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2eed47c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false + +[test/fixtures/*] +insert_final_newline = false +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes index 759c2c5..4a3f1d3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,13 +1,9 @@ # Enforce Unix newlines -*.* text eol=lf -*.css text eol=lf -*.html text eol=lf -*.js text eol=lf -*.json text eol=lf -*.less text eol=lf -*.md text eol=lf -*.yml text eol=lf +* text eol=lf +# binaries +*.ai binary +*.psd binary *.jpg binary *.gif binary *.png binary diff --git a/.gitignore b/.gitignore index 3281f18..9e685a4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.DS_Store *.sublime-* _gh_pages bower_components diff --git a/.jshintrc b/.jshintrc index 96d4b14..6e5a84a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -6,13 +6,13 @@ "eqnull": true, "esnext": true, "immed": true, - "latedef": true, + "latedef": false, "laxcomma": false, + "mocha": true, "newcap": true, "noarg": true, "node": true, "sub": true, "undef": true, - "unused": true, - "mocha": true + "unused": true } \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..efe94c0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +sudo: false +language: node_js +node_js: + - "0.10" + - "0.12" + - "iojs" +git: + depth: 10 \ No newline at end of file diff --git a/.verb.md b/.verb.md index c43de51..e264567 100644 --- a/.verb.md +++ b/.verb.md @@ -1,15 +1,11 @@ -# {%= name %} {%= badge("fury") %} +# {%= name %} {%= badge("fury") %} {%= badge("travis") %} > {%= description %} -## Install {%= include("install-npm", {save: true}) %} -## Run tests - -```bash -npm test -``` +## Running tests +{%= include("tests") %} ## Usage @@ -18,7 +14,7 @@ var gulpRoutes = require('{%= name %}'); ``` ## API -{%= comments("index.js") %} +{%= apidocs("index.js") %} ## Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue]({%= bugs.url %}) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index c9ff6c8..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1 +0,0 @@ -Please see the [Contributing to Assemble](http://assemble.io/contributing) guide for information on contributing to this project. diff --git a/LICENSE-MIT b/LICENSE similarity index 96% rename from LICENSE-MIT rename to LICENSE index 4ee4498..4df9bba 100644 --- a/LICENSE-MIT +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Brian Woodward +Copyright (c) 2014-2015, Brian Woodward. 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 84459c5..c6c6e1b 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,21 @@ -# gulp-routes [![NPM version](https://badge.fury.io/js/gulp-routes.svg)](http://badge.fury.io/js/gulp-routes) +# gulp-routes [![NPM version](https://badge.fury.io/js/gulp-routes.svg)](http://badge.fury.io/js/gulp-routes) [![Build Status](https://travis-ci.org/assemble/gulp-routes.svg)](https://travis-ci.org/assemble/gulp-routes) > Add middleware to run for specified routes in your gulp pipeline. -## Install ## Install with [npm](npmjs.org) ```bash npm i gulp-routes --save ``` -## Run tests +## Running tests +Install dev dependencies. ```bash -npm test +npm i -d && npm test ``` + ## Usage ```js @@ -22,20 +23,19 @@ var gulpRoutes = require('gulp-routes'); ``` ## API -### [.gulpRoutes](index.js#L28) +### [gulpRoutes](./index.js#L32) -Create a routes plugin that runs middleware defined on a router. +Returns a plugin function for running middleware defined on a router. -* `router` **{Object}**: Instance of an [en-route] router +* `router` **{Object}**: Instance of an [en-route] router. * `returns` **{Function}**: New function for creating a router stream. ```js -var gulpRoutes = require('gulp-routes'); var router = require('en-route'); -var routes = gulpRoutes(router); +var routes = require('gulp-routes')(router); ``` -### [.routes](index.js#L49) +### [.routes](./index.js#L53) Create a router stream to run middleware for the specified method. @@ -60,11 +60,11 @@ Pull requests and stars are always welcome. For bugs and feature requests, [plea + [twitter/assemble](http://twitter.com/assemble) ## License -Copyright (c) 2014 Brian Woodward +Copyright (c) 2015 Brian Woodward Released under the MIT license *** -_This file was generated by [verb](https://github.com/assemble/verb) on December 10, 2014._ +_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 01, 2015._ [en-route]: https://github.com/jonschlinkert/en-route diff --git a/index.js b/index.js index 8ad8611..b4d6519 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ /*! * gulp-routes * - * Copyright (c) 2014 Brian Woodward, contributors. - * Licensed under the MIT license. + * Copyright (c) 2014-2015, Brian Woodward. + * Licensed under the MIT License. */ 'use strict'; @@ -11,21 +11,25 @@ var through = require('through2'); var gutil = require('gulp-util'); /** - * Create a routes plugin that runs middleware defined on a router. + * Expose `gulpRoutes` plugin. + */ + +module.exports = gulpRoutes; + +/** + * Returns a plugin function for running middleware defined on a router. * * ```js - * var gulpRoutes = require('gulp-routes'); * var router = require('en-route'); - * var routes = gulpRoutes(router); + * var routes = require('gulp-routes')(router); * ``` * - * @name gulpRoutes - * @param {Object} `router` Instance of an [en-route] router + * @param {Object} `router` Instance of an [en-route] router. * @return {Function} New function for creating a router stream. * @api public */ -module.exports = function gulpRoutes(router) { +function gulpRoutes(router) { router = router || (this && this.router); if (!router) { throw new gutil.PluginError('gulp-routes', new Error('Expected a valid router object.')); @@ -46,14 +50,20 @@ module.exports = function gulpRoutes(router) { * @api public */ - return function routes (method) { + return function routes(method) { method = method || 'all'; return through.obj(function (file, encoding, cb) { + if (file.isNull() || !file.isBuffer()) { + this.push(file); + return cb(); + } + var stream = this; try { file.options = file.options || {}; file.options.method = method; + // run middleware router.handle(file, function (err) { if (err) { @@ -64,9 +74,9 @@ module.exports = function gulpRoutes(router) { cb(); } }); - } catch (ex) { - stream.emit('error', new gutil.PluginError('gulp-routes - handle', ex)); - cb(); + } catch (err) { + stream.emit('error', new gutil.PluginError('gulp-routes - handle', err)); + return cb(); } }); }; diff --git a/package.json b/package.json index 8695ab9..73b08b4 100644 --- a/package.json +++ b/package.json @@ -16,23 +16,26 @@ }, "license": { "type": "MIT", - "url": "https://github.com/assemble/gulp-routes/blob/master/LICENSE-MIT" + "url": "https://github.com/assemble/gulp-routes/blob/master/LICENSE" }, + "files": [ + "index.js" + ], "main": "index.js", "engines": { "node": ">=0.10.0" }, "scripts": { - "test": "mocha -R spec" + "test": "mocha" }, - "devDependencies": { - "en-route": "^0.3.3", - "mocha": "*", - "should": "*" - }, - "keywords": [], "dependencies": { - "gulp-util": "^3.0.1", + "gulp-util": "^3.0.4", + "should": "^5.0.1", "through2": "^0.6.3" + }, + "devDependencies": { + "en-route": "^0.4.0", + "mocha": "*", + "should": "^5.0.1" } } diff --git a/test.js b/test.js index 34255bd..16e167b 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,10 @@ -/** - * Assemble +/*! + * gulp-routes * - * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors - * Licensed under the MIT License (MIT). + * Copyright (c) 2014-2015, Brian Woodward. + * Licensed under the MIT License. */ + 'use strict'; var should = require('should');