gulp-concat-filenames
Advanced tools
Comparing version 1.0.0 to 1.1.0
27
index.js
@@ -10,9 +10,15 @@ var through = require('through'); | ||
var identity = function(x) { | ||
return x; | ||
}; | ||
var error = { | ||
noFilename: 'Missing fileName option for gulp-concat-filenames', | ||
noStreaming: 'Streaming not supported' | ||
noStreaming: 'Streaming not supported', | ||
badTemplate: 'Error in template function' | ||
}; | ||
opts = opts || {}; | ||
opts.template = opts.template || identity; | ||
if (!filename) { | ||
@@ -43,3 +49,18 @@ throw new PluginError('gulp-concat-filenames', error.noFilename); | ||
// Make sure template errors reach the output | ||
var safeTemplate = function(str) { | ||
var output; | ||
try { | ||
output = opts.template(str); | ||
} catch (e) { | ||
e.message = error.badTemplate + ': ' + e.message; | ||
return this.emit('error', new PluginError('gulp-concat-filenames', e)); | ||
} | ||
if (typeof output !== 'string') { | ||
return this.emit('error', new PluginError('gulp-concat-filenames', error.badTemplate)); | ||
} | ||
return output; | ||
}; | ||
requirePath = opts.root ? | ||
@@ -51,3 +72,3 @@ path.relative(opts.root, requirePath) : | ||
opts.prepend || '', | ||
requirePath.replace(/\\/g, '\/'), | ||
safeTemplate.call(this, requirePath.replace(/\\/g, '\/')), | ||
opts.append || '', | ||
@@ -54,0 +75,0 @@ opts.newLine |
{ | ||
"name": "gulp-concat-filenames", | ||
"description": "Similar to concat, but creates a file with a list of filenames,not file contents.", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "http://jesseharlin.net", | ||
"repository": "https://github.com/the-simian/gulp-concat-filenames", | ||
"author": "the-simian <harlinjesse@gmail.com>", | ||
"contributors": [{ | ||
"name" : "Jesse Harlin", | ||
"email" : "harlinjesse@gmail.com" | ||
}, { | ||
"name" : "Noam Youngerman", | ||
"email" : "noam@younger.mn" | ||
}], | ||
"main": "./index.js", | ||
"keywords": [ | ||
"gulpplugin", | ||
"gulpfriendly", | ||
"gulpfriendly", | ||
"concat filenames", | ||
@@ -23,3 +30,3 @@ "gulp" | ||
"gulp-coveralls": "^0.1.3", | ||
"gulp-istanbul": "^0.7.0", | ||
"gulp-istanbul": "^0.10.3", | ||
"gulp-mocha": "^2.0.1", | ||
@@ -38,3 +45,3 @@ "gulp-plato": "^1.0.2", | ||
"test": "gulp ci", | ||
"coveralls" : "gulp coveralls" | ||
"coveralls" : "gulp coveralls" | ||
}, | ||
@@ -41,0 +48,0 @@ "engineStrict": true, |
@@ -1,8 +0,8 @@ | ||
[![Build Status](https://travis-ci.org/the-simian/gulp-concat-filenames.svg?branch=master)](https://travis-ci.org/the-simian/gulp-concat-filenames) | ||
[![Build Status](https://travis-ci.org/the-simian/gulp-concat-filenames.svg?branch=master)](https://travis-ci.org/the-simian/gulp-concat-filenames) | ||
[![Coverage Status](https://coveralls.io/repos/the-simian/gulp-concat-filenames/badge.png?branch=coveralls)](https://coveralls.io/r/the-simian/gulp-concat-filenames?branch=coveralls) | ||
[![Coverage Status](https://coveralls.io/repos/the-simian/gulp-concat-filenames/badge.png?branch=coveralls)](https://coveralls.io/r/the-simian/gulp-concat-filenames?branch=coveralls) | ||
[![Code Climate](https://codeclimate.com/github/the-simian/gulp-concat-filenames/badges/gpa.svg)](https://codeclimate.com/github/the-simian/gulp-concat-filenames) | ||
[![Code Climate](https://codeclimate.com/github/the-simian/gulp-concat-filenames/badges/gpa.svg)](https://codeclimate.com/github/the-simian/gulp-concat-filenames) | ||
[![Codeship Status for the-simian/gulp-concat-filenames](https://www.codeship.io/projects/b7aaf400-3b02-0132-083a-261a2707f8ca/status)](https://www.codeship.io/projects/42521) | ||
[![Codeship Status for the-simian/gulp-concat-filenames](https://www.codeship.io/projects/b7aaf400-3b02-0132-083a-261a2707f8ca/status)](https://www.codeship.io/projects/42521) | ||
@@ -15,11 +15,9 @@ [![Dependency Status](https://david-dm.org/the-simian/gulp-concat-filenames.svg)](https://david-dm.org/the-simian/gulp-concat-filenames) | ||
| | | | ||
|--------------|---------------------------------------------------------------------------------------------------------------| | ||
| Package | gulp-concat-filenames | | ||
| Description | Similar to concat, but creates a list of names in the output file, rather than all the contents being merged. | | ||
| Node Version | >= 0.10 | | ||
|--------------|------------------------------------------------------------------------------------------------------| | ||
| Package | gulp-concat-filenames | | ||
| Description | Similar to concat, but creates a list of names in the output file, rather than contents being merged.| | ||
| Node Version | >= 0.10 | | ||
## Usage | ||
### Basic Usage, No options. | ||
@@ -49,19 +47,19 @@ ```js | ||
####Filename | ||
####Filename [**Required**] | ||
This first argment is the name of the output file the list fo filenames will be put into. This is required. | ||
This first argument is the name of the output file the list of filenames will be put into. | ||
#####Options | ||
#####Options [**Optional**] | ||
The second argument is optional, and is an object with the following properties: | ||
The second argument is optional (pun intended), and is an object with the following properties: | ||
- `newline` - The character to use in place of `\n` for a newline. The default value will be `\n` | ||
- `prepend` - Some text to prepend to every entry in the list of filenames | ||
- `append` - Some text to append to every intry in the list of filenames | ||
- `template` - a function that takes one parameter (the file name) and returns the string after some formatting. Can be used in addition to, or instead of, `append` and `prepend` | ||
- `root` - the root folder. Including this argument will return a list of relative paths instead of absolute paths. | ||
###Examples | ||
Given the file structure: | ||
@@ -109,8 +107,33 @@ | ||
Or you can use the template property, to format the output as well. | ||
```js | ||
function fileNameFormatter(filename) { | ||
return 'XXX--' + filename.toUpperCase() + '--YYY'; | ||
} | ||
var concatFilenames = require('gulp-concat-filenames'); | ||
var concatFilenamesOptions = { | ||
root: '/lib', | ||
template: fileNameFormatter // Pass in a function | ||
}; | ||
function fileManifest(){ | ||
gulp | ||
.src('./lib/**/*.*') | ||
.pipe(concatFilenames('manifest.txt', concatFilenamesOptions)) | ||
.pipe(gulp.dest('./output/')); | ||
} | ||
gulp.task('file-manifest', fileManifest); | ||
``` | ||
running `gulp file-manifest` now produces a file called `manifest.txt` with the contents | ||
``` | ||
XXX--ONE.TXT--YYY | ||
XXX--TWO.TXT--YYY | ||
``` |
@@ -153,4 +153,71 @@ 'use strict'; | ||
}); | ||
describe('When I provide a formatting function', function () { | ||
it('then it will apply that function to each entry', function (done) { | ||
var expectedFilenames = ([ | ||
'XXX../test/fixtures/fork.txtYYY', | ||
'XXX../test/fixtures/knife.jsYYY', | ||
'XXX../test/fixtures/spoon.htmlYYY', | ||
].join('\n') + '\n').toString().toUpperCase(); | ||
gulp | ||
.src(fixtures('*')) | ||
.pipe(concatFilenames('mainfest.txt', { | ||
root: 'fixtures', | ||
template: function(filename) { | ||
return 'XXX' + filename.toUpperCase() + 'YYY'; | ||
} | ||
})) | ||
.pipe(assert.first(function (d) { | ||
var contents = d.contents.toString(); | ||
expect(contents) | ||
.to | ||
.equal(expectedFilenames); | ||
})) | ||
.pipe(assert.end(done)); | ||
}); | ||
}); | ||
describe('When I provide a formatting function with a syntax error', function () { | ||
it('then it will fail and throw an error', function (done) { | ||
gulp | ||
.src(fixtures('*')) | ||
.pipe(concatFilenames('mainfest.txt', { | ||
root: 'fixtures', | ||
template: function(filename) { | ||
/* jshint ignore:start */ | ||
y = 0; // deliberate syntax error | ||
/* jshint ignore:end */ | ||
return filename; | ||
} | ||
})) | ||
.on('error', function (err) { | ||
expect(err.message).to.have.string('Error in template function'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe('When I provide a formatting function that does not return a string', function () { | ||
it('then it will fail and throw an error', function (done) { | ||
gulp | ||
.src(fixtures('*')) | ||
.pipe(concatFilenames('mainfest.txt', { | ||
root: 'fixtures', | ||
template: function() { | ||
return 5; | ||
} | ||
})) | ||
.on('error', function (err) { | ||
expect(err.message).to.equal('Error in template function'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
20862
318
137