From f8dbacd1b77cd0e24d24795ae0af8c5e6fc15cb2 Mon Sep 17 00:00:00 2001 From: contra Date: Thu, 4 Jul 2013 01:29:17 -0700 Subject: [PATCH] New: First implementation --- .gitignore | 6 +++++ .npmignore | 6 +++++ .travis.yml | 7 +++++ LICENSE | 20 ++++++++++++++ README.md | 56 +++++++++++++++++++++++++++++++++++++++ index.js | 2 ++ lib/main.coffee | 23 ++++++++++++++++ package.json | 31 ++++++++++++++++++++++ test/fixtures/test.coffee | 1 + test/main.coffee | 19 +++++++++++++ 10 files changed, 171 insertions(+) create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 .travis.yml create mode 100755 LICENSE create mode 100644 README.md create mode 100644 index.js create mode 100644 lib/main.coffee create mode 100644 package.json create mode 100644 test/fixtures/test.coffee create mode 100644 test/main.coffee diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5ef13a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +*.log +node_modules +build +*.node +components \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..b5ef13a --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +.DS_Store +*.log +node_modules +build +*.node +components \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..19b37b8 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - 0.6 + - 0.7 + - 0.8 + - 0.9 + - 0.10 \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..4f482f9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2013 Fractal + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3cdab4 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +[![Build Status](https://travis-ci.org/wearefractal/glob-stream.png?branch=master)](https://travis-ci.org/wearefractal/glob-stream) + +## Information + + + + + + + + + + + + + +
Packageglob-stream
DescriptionFile system globs as a stream
Node Version>= 0.4
+ +This is a simple wrapper around node-glob to make it streamy. + +## Usage + +```javascript +var gs = require('glob-stream'); + +var stream = gs.create("./files/**/*.coffee", {options - read node-glob docs}); + +stream.on('data', function(fileName){ + // fileName == full path +}); +``` + +## LICENSE + +(MIT License) + +Copyright (c) 2013 Fractal + +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. diff --git a/index.js b/index.js new file mode 100644 index 0000000..4838e6f --- /dev/null +++ b/index.js @@ -0,0 +1,2 @@ +require('coffee-script'); +module.exports = require('./lib/main'); diff --git a/lib/main.coffee b/lib/main.coffee new file mode 100644 index 0000000..736114f --- /dev/null +++ b/lib/main.coffee @@ -0,0 +1,23 @@ +es = require 'event-stream' +glob = require 'glob' + +module.exports = + create: (globb, opt={}) -> + throw new Error "Invalid or missing glob string" unless typeof globb is 'string' + + opt.silent ?= true + opt.nonull ?= false + + stream = es.pause() + + globber = new glob.Glob globb, opt + globber.on 'error', (e) -> + stream.emit 'error', e + + globber.on 'end', -> + stream.emit 'end' + + globber.on 'match', (filename) -> + stream.emit 'data', filename + + return stream \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..2f3ddb4 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name":"glob-stream", + "description":"File system globs as a stream", + "version":"0.0.0", + "homepage":"http://github.com/wearefractal/glob-stream", + "repository":"git://github.com/wearefractal/glob-stream.git", + "author":"Fractal (http://wearefractal.com/)", + "main":"./index.js", + + "dependencies":{ + "coffee-script":"*", + "glob":"*", + "event-stream":"*" + }, + "devDependencies":{ + "mocha":"*", + "should":"*" + }, + "scripts":{ + "test":"mocha --compilers coffee:coffee-script" + }, + "engines":{ + "node":">= 0.4.0" + }, + "licenses":[ + { + "type":"MIT", + "url":"http://github.com/wearefractal/glob-stream/raw/master/LICENSE" + } + ] +} diff --git a/test/fixtures/test.coffee b/test/fixtures/test.coffee new file mode 100644 index 0000000..a8a9406 --- /dev/null +++ b/test/fixtures/test.coffee @@ -0,0 +1 @@ +this is a test \ No newline at end of file diff --git a/test/main.coffee b/test/main.coffee new file mode 100644 index 0000000..f0d0bff --- /dev/null +++ b/test/main.coffee @@ -0,0 +1,19 @@ +gs = require '../' +should = require 'should' +require 'mocha' + +{join} = require 'path' + +# TODO: test back-pressure + +describe 'glob-stream', -> + describe 'create()', -> + it 'should return a file name stream from a glob', (done) -> + stream = gs.create join __dirname, "./fixtures/*.coffee" + should.exist stream + stream.on 'error', (err) -> throw err + stream.on 'data', (file) -> + should.exist file + String(file).should.equal join __dirname, "./fixtures/test.coffee" + + stream.on 'end', -> done() \ No newline at end of file