Skip to content

Commit 7bf1a41

Browse files
committed
initial commit
0 parents  commit 7bf1a41

7 files changed

+149
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = tab
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
node_modules

LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2013 [Hector Parra](http://hectorparra.com/)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# gulp-cli
2+
3+
CLI program piping plugin for [gulp](https://github.com/wearefractal/gulp). Uses [spawn](http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).
4+
5+
**This plugin has NOT been test thoroughly**
6+
7+
## Usage
8+
9+
gulp-cli options follow spawn's conventions.
10+
11+
Not all CLI programs support piping. In fact, many newer ones don't. Some programs require that you pass certain arguments if you intend to use stdin and/or stdout. Please check the documentation of the program you intend to use to ensure piping is supported.
12+
13+
The following example pipes image files to ImageMagick's `convert`. In the case of `convert`, you must specify a `-` before arguments and after arguments if you wish to use stdin and stdout, respectively.
14+
15+
```javascript
16+
var cli = require("gulp-cli");
17+
18+
// example using ImageMagick's convert
19+
gulp.src("./src/images/*.{jpg,png,gif}")
20+
.pipe(cli({
21+
cmd: "convert",
22+
args: [
23+
"-",
24+
"-resize",
25+
"50%",
26+
"-"
27+
]
28+
}))
29+
.pipe(gulp.dest("./dist/images/"));
30+
```
31+
32+
## The UNIX Pipe Philosophy
33+
34+
If you write CLI programs please consider taking the time to support stdin & stdout. Piping is one of the reasons UNIX systems have endured the test of time. There is no reason to reinvent the wheel.

index.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var fs = require("fs");
2+
var es = require("event-stream");
3+
var clone = require("clone");
4+
var cp = require("child_process");
5+
6+
module.exports = function(options) {
7+
"use strict";
8+
9+
// generic cli plugin
10+
function cli(file, callback) {
11+
12+
// clone file object, reset buffer
13+
var newFile = clone(file);
14+
newFile.contents = new Buffer(0);
15+
16+
// cli program
17+
var program = cp.spawn(options.cmd, options.args);
18+
19+
// when program receives data add it to newFile buffer
20+
program.stdout.on("data", function (buffer) {
21+
newFile.contents = Buffer.concat([
22+
newFile.contents,
23+
buffer
24+
]);
25+
});
26+
27+
// when program finishes call callback
28+
program.stdout.on("end", function (close) {
29+
callback(null, newFile);
30+
});
31+
32+
// "execute"
33+
// write file buffer to program
34+
program.stdin.write(file.contents, function () {
35+
program.stdin.end();
36+
});
37+
}
38+
39+
return es.map(cli);
40+
}

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "gulp-cli",
3+
"description": "cli plugin for gulp",
4+
"version": "0.1.",
5+
"homepage": "https://github.com/hparra/gulp-cli",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/hparra/gulp-cli.git"
9+
},
10+
"author": {
11+
"name": "Hector Parra",
12+
"url": "http://hectorparra.com/"
13+
},
14+
"main": "./index.js",
15+
"keywords": [
16+
"gulpplugin",
17+
"cli",
18+
"shell",
19+
"exec"
20+
],
21+
"dependencies": {
22+
"event-stream": "*"
23+
},
24+
"devDependencies": {
25+
"mocha": "*",
26+
"should": "*",
27+
"clone": "~0.1.11",
28+
"event-stream": "~3.0.16"
29+
},
30+
"scripts": {
31+
"test": "mocha"
32+
},
33+
"engines": {
34+
"node": ">= 0.4.0"
35+
},
36+
"licenses": [
37+
{
38+
"type": "MIT"
39+
}
40+
]
41+
}

0 commit comments

Comments
 (0)