選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # node-fileset [![Build Status](https://secure.travis-ci.org/mklabs/node-fileset.png)](http://travis-ci.org/mklabs/node-fileset)
  2. Exposes a basic wrapper on top of
  3. [Glob](https://github.com/isaacs/node-glob) /
  4. [minimatch](https://github.com/isaacs/minimatch) combo both written by
  5. @isaacs. Glob now uses JavaScript instead of C++ bindings which makes it
  6. usable in Node.js 0.6.x and Windows platforms.
  7. [![NPM](https://nodei.co/npm/fileset.png?downloads=true&stars=true)](https://nodei.co/npm/fileset/)
  8. Adds multiples patterns matching and exlude ability. This is
  9. basically just a sugar API syntax where you can specify a list of includes
  10. and optional exclude patterns. It works by setting up the necessary
  11. miniglob "fileset" and filtering out the results using minimatch.
  12. *[Changelog](https://github.com/mklabs/node-fileset/blob/master/CHANGELOG.md#changelog)*
  13. ## Install
  14. npm install fileset
  15. ## Usage
  16. Can be used with callback or emitter style.
  17. * **include**: list of glob patterns `foo/**/*.js *.md src/lib/**/*`
  18. * **exclude**: *optional* list of glob patterns to filter include
  19. results `foo/**/*.js *.md`
  20. * **callback**: *optional* function that gets called with an error if
  21. something wrong happend, otherwise null with an array of results
  22. The callback is optional since the fileset method return an instance of
  23. EventEmitter which emit different events you might use:
  24. * *match*: Every time a match is found, miniglob emits this event with
  25. the pattern.
  26. * *include*: Emitted each time an include match is found.
  27. * *exclude*: Emitted each time an exclude match is found and filtered
  28. out from the fileset.
  29. * *end*: Emitted when the matching is finished with all the matches
  30. found, optionally filtered by the exclude patterns.
  31. #### Callback
  32. ```js
  33. var fileset = require('fileset');
  34. fileset('**/*.js', '**.min.js', function(err, files) {
  35. if (err) return console.error(err);
  36. console.log('Files: ', files.length);
  37. console.log(files);
  38. });
  39. ```
  40. #### Event emitter
  41. ```js
  42. var fileset = require('fileset');
  43. fileset('**.coffee README.md *.json Cakefile **.js', 'node_modules/**')
  44. .on('match', console.log.bind(console, 'error'))
  45. .on('include', console.log.bind(console, 'includes'))
  46. .on('exclude', console.log.bind(console, 'excludes'))
  47. .on('end', console.log.bind(console, 'end'));
  48. ```
  49. `fileset` returns an instance of EventEmitter, with an `includes` property
  50. which is the array of Fileset objects (inheriting from
  51. `miniglob.Miniglob`) that were used during the mathing process, should
  52. you want to use them individually.
  53. Check out the
  54. [tests](https://github.com/mklabs/node-fileset/tree/master/tests) for
  55. more examples.
  56. ## Sync usage
  57. ```js
  58. var results = fileset.sync('*.md *.js', 'CHANGELOG.md node_modules/**/*.md node_modules/**/*.js');
  59. ```
  60. The behavior should remain the same, although it lacks the last `options` arguments to pass to internal `glob` and `minimatch` dependencies.
  61. ## Tests
  62. Run `npm test`
  63. ## Why
  64. Mainly for a build tool with cake files, to provide me an easy way to get
  65. a list of files by either using glob or path patterns, optionally
  66. allowing exclude patterns to filter out the results.
  67. All the magic is happening in
  68. [Glob](https://github.com/isaacs/node-glob) and
  69. [minimatch](https://github.com/isaacs/minimatch). Check them out!