├── .travis.yml ├── .gitignore ├── .npmignore ├── .jshintrc ├── index.js ├── package.json ├── LICENSE ├── examples ├── gulpfile.js ├── index.html └── second.html ├── test └── main.js └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "8" 5 | - "6" 6 | - "4" 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | .DS_store 10 | 11 | pids 12 | logs 13 | results 14 | 15 | npm-debug.log 16 | node_modules 17 | *.sublime* 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | .DS_store 10 | 11 | pids 12 | logs 13 | results 14 | 15 | npm-debug.log 16 | node_modules 17 | *.sublime* 18 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "freeze": true, 6 | "indent": 2, 7 | "newcap": false, 8 | "quotmark": "single", 9 | "maxdepth": 5, 10 | "maxstatements": 50, 11 | "maxlen": 100, 12 | "eqnull": true, 13 | "funcscope": true, 14 | "strict": true, 15 | "undef": true, 16 | "unused": true, 17 | "node": true, 18 | "mocha": true, 19 | "esversion": 6 20 | } 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const open = require('opn'); 4 | const through = require('through2'); 5 | const log = require('plugin-log'); 6 | 7 | const colors = log.colors; 8 | 9 | module.exports = function(opts) { 10 | opts = opts || {}; 11 | 12 | return through.obj(function(file, enc, cb) { 13 | let uri = opts.uri; 14 | 15 | if (file.path && !uri) { 16 | uri = file.path; 17 | } 18 | 19 | if (opts.app) { 20 | log(colors.blue('Opening', colors.green(uri), 'using the app', 21 | colors.green(opts.app))); 22 | // Open with the given app 23 | open(uri, {app: opts.app, wait: false}); 24 | return cb(null, file); 25 | 26 | } 27 | log(colors.blue('Opening', colors.green(uri), 'using the', 28 | colors.green('default OS app'))); 29 | // Open with the default app defined by the os 30 | open(uri, {wait: false}); 31 | return cb(null, file); 32 | 33 | }); 34 | }; 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-open", 3 | "description": "Open files and URLs with gulp", 4 | "version": "3.0.1", 5 | "homepage": "http://github.com/stevelacy/gulp-open", 6 | "repository": { 7 | "type": "git", 8 | "url": "http://github.com/stevelacy/gulp-open.git" 9 | }, 10 | "author": "Steve Lacy (http://slacy.me/)", 11 | "main": "./index.js", 12 | "dependencies": { 13 | "opn": "^5.3.0", 14 | "plugin-log": "^0.1.0", 15 | "through2": "^2.0.3" 16 | }, 17 | "devDependencies": { 18 | "jshint": "^2.9.5", 19 | "mocha": "^5.0.5", 20 | "should": "^13.2.1" 21 | }, 22 | "scripts": { 23 | "pretest": "jshint index.js test", 24 | "test": "mocha --reporter spec" 25 | }, 26 | "engines": { 27 | "node": ">=4" 28 | }, 29 | "keywords": [ 30 | "gulp", 31 | "open", 32 | "node-open", 33 | "gulpplugin", 34 | "gulp-plugin" 35 | ], 36 | "license": "MIT" 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Steve Lacy me@slacy.me 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. 21 | -------------------------------------------------------------------------------- /examples/gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const os = require('os'); 4 | const gulp = require('gulp'); 5 | const open = require('../'); 6 | 7 | 8 | // Default usage: 9 | // Open one file with default application 10 | 11 | gulp.task('open', function() { 12 | gulp.src('./index.html') 13 | .pipe(open()); 14 | }); 15 | 16 | 17 | const browser = os.platform() === 'linux' ? 'google-chrome' : ( 18 | os.platform() === 'darwin' ? 'google chrome' : ( 19 | os.platform() === 'win32' ? 'chrome' : 'firefox')); 20 | 21 | gulp.task('browser', function() { 22 | gulp.src('./*.html') 23 | .pipe(open({app: browser})); 24 | }); 25 | 26 | // Simple usage, no options. 27 | // This will use the uri in the default browser 28 | 29 | gulp.task('uri', function() { 30 | gulp.src('') 31 | .pipe(open({uri: 'http://www.google.com'})); 32 | }); 33 | 34 | // Open an URL in a given browser: 35 | 36 | gulp.task('app', function() { 37 | const options = { 38 | uri: 'localhost:3000', 39 | app: 'firefox' 40 | }; 41 | gulp.src(__filename) 42 | .pipe(open(options)); 43 | }); 44 | 45 | // Run the task with gulp 46 | 47 | gulp.task('default', ['open', 'uri', 'app', 'browser']); 48 | -------------------------------------------------------------------------------- /test/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const gulpopen = require('../'); 4 | const os = require('os'); 5 | 6 | describe('gulp-open', function() { 7 | 8 | const browser = os.platform() === 'linux' ? 'google-chrome' : ( 9 | os.platform() === 'darwin' ? 'google chrome' : ( 10 | os.platform() === 'win32' ? 'chrome' : 'firefox')); 11 | 12 | describe('opening files', function() { 13 | it('should open a stream of files with the default application', function(done) { 14 | gulpopen('<%= file.path%>', {}, done()); 15 | }); 16 | 17 | it('should open a stream of files with a defined application', function(done) { 18 | gulpopen('<%= file.path%>', {app: browser}, done()); 19 | }); 20 | 21 | it('should open a stream of files with a browser using the options', function(done) { 22 | gulpopen({}, {uri: __dirname + '/../package.json', app: browser}, done()); 23 | }); 24 | }); 25 | 26 | describe('opening urls', function() { 27 | it('should open a website in a browser using the options', function(done) { 28 | gulpopen({}, {uri: 'http://localhost:3000'}, done()); 29 | }); 30 | 31 | it('should open a website in a browser using chrome or firefox', function(done) { 32 | gulpopen({}, {uri: 'https://www.google.com', app: browser}, done()); 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-open 2 | 3 | > Version 3.0.0+ removes support for node < v4 4 | 5 | [![Build Status](https://travis-ci.org/stevelacy/gulp-open.png?branch=master)](https://travis-ci.org/stevelacy/gulp-open) 6 | [![NPM version](https://badge.fury.io/js/gulp-open.png)](http://badge.fury.io/js/gulp-open) 7 | 8 | ## Information 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
Packagegulp-open
DescriptionOpen files and URLs with gulp
Node Version>= 4
Gulp Version3.x
27 | 28 | ## Usage 29 | 30 | #### Install 31 | npm install gulp-open --save 32 | 33 | ## Example 34 | 35 | ```javascript 36 | 'use strict'; 37 | 38 | var os = require('os'); 39 | var gulp = require('gulp'); 40 | var open = require('gulp-open'); 41 | 42 | 43 | // Default usage: 44 | // Open one file with default application 45 | 46 | gulp.task('open', function(){ 47 | gulp.src('./index.html') 48 | .pipe(open()); 49 | }); 50 | 51 | 52 | var browser = os.platform() === 'linux' ? 'google-chrome' : ( 53 | os.platform() === 'darwin' ? 'google chrome' : ( 54 | os.platform() === 'win32' ? 'chrome' : 'firefox')); 55 | 56 | gulp.src('./package.json').pipe(open({app: 'chrome'})); 57 | 58 | gulp.task('browser', function(){ 59 | gulp.src('./second.html') 60 | .pipe(open({app: browser})); 61 | }); 62 | 63 | // Simple usage, no options. 64 | // This will use the uri in the default browser 65 | 66 | gulp.task('uri', function(){ 67 | gulp.src(__filename) 68 | .pipe(open({uri: 'http://www.google.com'})); 69 | }); 70 | 71 | // Open an URL in a given browser: 72 | 73 | gulp.task('app', function(){ 74 | var options = { 75 | uri: 'localhost:3000', 76 | app: 'firefox' 77 | }; 78 | gulp.src(__filename) 79 | .pipe(open(options)); 80 | }); 81 | 82 | // Run the task with gulp 83 | 84 | gulp.task('default', ['open', 'uri', 'app', 'browser']); 85 | 86 | ``` 87 | #### You can view more examples in the [example folder.](https://github.com/stevelacy/gulp-open/tree/master/examples) 88 | 89 | 90 | ## Options 91 | `Object, {app, uri}` 92 | 93 | `.pipe(open(options))` 94 | 95 | ### Options.app 96 | `String, local application` 97 | 98 | NOTE: If the ``options.app`` is not defined, the Default application will be used for the filetype/URL. 99 | 100 | ```javascript 101 | 102 | 'google-chrome' // Linux 103 | 'chrome' // Windows 104 | 'google chrome' or 'Google Chrome' // OSX 105 | 'firefox' 106 | 107 | // Example: 108 | 109 | .pipe(open({uri: 'file:///etc/resolv.conf', app: 'google-chrome'})); 110 | 111 | ``` 112 | 113 | #### Note for OSX-Users: 114 | You might have to use an absolute path. 115 | 116 | ```javascript 117 | var options = { 118 | uri: 'localhost:3000', 119 | app: '/Applications/Google\ Chrome.app' 120 | }; 121 | gulp.src('./') 122 | .pipe(open(options)); 123 | ``` 124 | 125 | ### Options.uri 126 | `String, any valid uri (url, file protocol, or full path)` 127 | 128 | #### Note for windows users: 129 | URLs may not have a default application. If the task is running without opening in a browser try setting the options.app. 130 | Google Chrome: "chrome" 131 | Firefox: "firefox" 132 | 133 | ```javascript 134 | 135 | 'http://localhost:3000' 136 | 137 | // Example: 138 | gulp.src('') 139 | .pipe(open({app: 'google-chrome', uri: 'http://localhost:3000'})); 140 | ``` 141 | ## LICENSE 142 | 143 | (MIT License) 144 | 145 | Copyright (c) 2015 Steve Lacy slacy.me 146 | 147 | Permission is hereby granted, free of charge, to any person obtaining 148 | a copy of this software and associated documentation files (the 149 | "Software"), to deal in the Software without restriction, including 150 | without limitation the rights to use, copy, modify, merge, publish, 151 | distribute, sublicense, and/or sell copies of the Software, and to 152 | permit persons to whom the Software is furnished to do so, subject to 153 | the following conditions: 154 | 155 | The above copyright notice and this permission notice shall be 156 | included in all copies or substantial portions of the Software. 157 | 158 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 159 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 160 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 161 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 162 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 163 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 164 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 165 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | gulp-open example file 6 | 7 | 8 | 9 |

gulp-open example

10 |
var gulp = require("gulp");
11 | var open = require("../");
12 | 
13 | gulp.task("simple", function(){
14 |   gulp.src("./index.html")
15 |   .pipe(open());
16 | });
17 | 
18 | gulp.task("template", function(){
19 |   gulp.src("./second.html")
20 |   .pipe(open("<%file.path%>"));
21 | });
22 | 
23 | gulp.task("open", function(){
24 |   var options = {
25 |     app: "google-chrome"
26 |   };
27 |   gulp.src("./*.html")
28 |   .pipe(open("file://<%= file.path %>", options));
29 | });
30 | 
31 | 
32 | 
33 | gulp.task("default", function(){
34 |   gulp.run("simple", "template","open");
35 | });
36 | 
37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /examples/second.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | gulp-open example file 6 | 7 | 8 | 9 |

Second gulp-open example file

10 |
var gulp = require("gulp");
11 | var open = require("../");
12 | 
13 | gulp.task("simple", function(){
14 |   gulp.src("./index.html")
15 |   .pipe(open());
16 | });
17 | 
18 | gulp.task("template", function(){
19 |   gulp.src("./second.html")
20 |   .pipe(open("<%file.path%>"));
21 | });
22 | 
23 | gulp.task("open", function(){
24 |   var options = {
25 |     app: "google-chrome"
26 |   };
27 |   gulp.src("./*.html")
28 |   .pipe(open("file://<%= file.path %>", options));
29 | });
30 | 
31 | 
32 | 
33 | gulp.task("default", function(){
34 |   gulp.run("simple", "template","open");
35 | });
36 | 
37 | 38 | 39 | 40 | 41 | 42 | 43 | --------------------------------------------------------------------------------