Created
July 27, 2014 16:12
-
-
Save stephenmathieson/4c296844ce376713500a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/.gitignore b/.gitignore | |
index 3c3629e..dd87e2d 100644 | |
--- a/.gitignore | |
+++ b/.gitignore | |
@@ -1 +1,2 @@ | |
node_modules | |
+build | |
diff --git a/Makefile b/Makefile | |
index 20f657b..5a517e2 100644 | |
--- a/Makefile | |
+++ b/Makefile | |
@@ -1,5 +1,12 @@ | |
+build: lib/index.js | |
+ @mkdir -p build | |
+ @node_modules/.bin/regenerator $^ > build/index.js | |
+ | |
test: | |
@node_modules/.bin/mocha --harmony | |
-.PHONY: test | |
+clean: | |
+ @rm -rf build | |
+ | |
+.PHONY: test clean | |
diff --git a/index.js b/index.js | |
index 676426a..1799b37 100644 | |
--- a/index.js | |
+++ b/index.js | |
@@ -1,26 +1,4 @@ | |
-/** | |
- * Module dependencies. | |
- */ | |
- | |
-var read = require('co-read'); | |
- | |
-/** | |
- * Create a co generator stream from a node stream. | |
- * | |
- * @param {Stream} stream | |
- * @return {GeneratorFunction} | |
- * @api public | |
- */ | |
- | |
-module.exports = function(stream){ | |
- return function*(end){ | |
- if (end) { | |
- if (stream.end) stream.end(); | |
- else if (stream.close) stream.close(); | |
- else if (stream.destroy) stream.destroy(); | |
- return; | |
- } | |
- return yield read(stream); | |
- }; | |
-}; | |
+module.exports = require('generator-supported') | |
+ ? require('./lib') | |
+ : require('./build'); | |
diff --git a/lib/index.js b/lib/index.js | |
new file mode 100644 | |
index 0000000..676426a | |
--- /dev/null | |
+++ b/lib/index.js | |
@@ -0,0 +1,26 @@ | |
+ | |
+/** | |
+ * Module dependencies. | |
+ */ | |
+ | |
+var read = require('co-read'); | |
+ | |
+/** | |
+ * Create a co generator stream from a node stream. | |
+ * | |
+ * @param {Stream} stream | |
+ * @return {GeneratorFunction} | |
+ * @api public | |
+ */ | |
+ | |
+module.exports = function(stream){ | |
+ return function*(end){ | |
+ if (end) { | |
+ if (stream.end) stream.end(); | |
+ else if (stream.close) stream.close(); | |
+ else if (stream.destroy) stream.destroy(); | |
+ return; | |
+ } | |
+ return yield read(stream); | |
+ }; | |
+}; | |
diff --git a/package.json b/package.json | |
index 51ca542..d7f453a 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -5,13 +5,15 @@ | |
"repository": "juliangruber/co-from-stream", | |
"license": "MIT", | |
"dependencies": { | |
- "co-read": "0.0.1" | |
+ "co-read": "0.0.1", | |
+ "generator-supported": "0.0.1" | |
}, | |
"devDependencies": { | |
"co": "~3.0.2", | |
- "mocha": "~1.17.1" | |
+ "mocha": "~1.17.1", | |
+ "regenerator": "^0.4.12" | |
}, | |
"scripts": { | |
"test": "make test" | |
} | |
-} | |
\ No newline at end of file | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment