Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ianstormtaylor committed Mar 6, 2014
0 parents commit 4685621
Show file tree
Hide file tree
Showing 35 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions History.md
@@ -0,0 +1,4 @@

0.0.1 - March 6, 2013
------------------------
:sparkles:
8 changes: 8 additions & 0 deletions Makefile
@@ -0,0 +1,8 @@

node_modules: package.json
@npm install

test: node_modules
@./node_modules/.bin/mocha --reporter spec

.PHONY: test
58 changes: 58 additions & 0 deletions Readme.md
@@ -0,0 +1,58 @@

# metalsmith-ignore

A Metalsmith plugin to ignore files that match a pattern.

## Installation

$ npm install metalsmith-ignore

## CLI Usage

Install via npm and then add the `metalsmith-ignore` key to your `metalsmith.json` plugins. The simplest case just ignores a single pattern:

```json
{
"plugins": {
"metalsmith-ignore": "drafts/*"
}
}
```

But you can also pass an array of patterns to ignore:

```json
{
"plugins": {
"metalsmith-ignore": [
"drafts/*",
"unfinished/*"
]
}
}
```

## Javascript Usage

Pass the options to `Metalsmith#use`:

```js
var ignore = require('metalsmith-ignore');

metalsmith.use(ignore('drafts/*'));
```

You can also pass an array of patterns to ignore:

```js
var ignore = require('metalsmith-ignore');

metalsmith.use(ignore([
'drafts/*',
'unfinished/*'
]));
```

## License

MIT
36 changes: 36 additions & 0 deletions lib/index.js
@@ -0,0 +1,36 @@

var Match = require('minimatch').Minimatch;

/**
* Expose `plugin`.
*/

module.exports = plugin;

/**
* Metalsmith plugin to ignore files that match a pattern.
*
* @param {String or Array or Object} opts
* @return {Function}
*/

function plugin(opts){
debugger;
if ('string' == typeof opts) opts = [opts];
if (opts instanceof Array) opts = { patterns: opts };
opts = opts || {};

var patterns = opts.patterns || [];
var matchers = patterns.map(function(str){
return new Match(str);
});

return function(files, metalsmith, done){
setImmediate(done);
for (var file in files) {
for (var i = 0, matcher; matcher = matchers[i]; i++) {
if (matcher.match(file)) delete files[file];
}

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Mar 7, 2014

multimatch might be useful here.

This comment has been minimized.

Copy link
@ianstormtaylor

ianstormtaylor Mar 7, 2014

Author Contributor

nice! that's exactly what i wanted :) 0045af4

}
};
}
16 changes: 16 additions & 0 deletions package.json
@@ -0,0 +1,16 @@
{
"name": "metalsmith-ignore",
"description": "A Metalsmith plugin to ignore files that match a pattern.",
"repository": "git://github.com/segmentio/metalsmith-ignore.git",
"version": "0.0.1",
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"minimatch": "^0.2.14"
},
"devDependencies": {
"mocha": "1.x",
"metalsmith": "^0.2.0",
"assert-dir-equal": "^0.1.0"
}
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions test/index.js
@@ -0,0 +1,36 @@

var equal = require('assert-dir-equal');
var Metalsmith = require('metalsmith');
var ignore = require('..');

describe('metalsmith-ignore', function(){
it('should ignore a patterns', function(done){
var m = Metalsmith('test/fixtures/object').use(ignore({
patterns: ['ignored.*', 'removed.*']
}));

m.build(function(err){
if (err) return done(err);
equal('test/fixtures/object/build', 'test/fixtures/object/expected');
done();
});
});

it('should take an array shorthand', function(done){
var m = Metalsmith('test/fixtures/array').use(ignore(['ignored.*', 'removed.*']));
m.build(function(err){
if (err) return done(err);
equal('test/fixtures/array/build', 'test/fixtures/array/expected');
done();
});
});

it('should take a string shorthand', function(done){
var m = Metalsmith('test/fixtures/string').use(ignore('ignored.*'));
m.build(function(err){
if (err) return done(err);
equal('test/fixtures/string/build', 'test/fixtures/string/expected');
done();
});
});
});

0 comments on commit 4685621

Please sign in to comment.