Socket
Socket
Sign inDemoInstall

gulp-shell

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-shell - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

13

gulpfile.js

@@ -1,6 +0,9 @@

var gulp = require('gulp')
var shell = require('./')
const gulp = require('gulp')
const shell = require('./')
var paths = {
js: ['*.js', 'test/*.js']
const paths = {
js: [
'*.js',
'test/*.js'
]
}

@@ -18,4 +21,4 @@

gulp.task('watch', function () {
gulp.task('watch', () => {
gulp.watch(paths.js, ['default'])
})

@@ -1,9 +0,9 @@

var _ = require('lodash')
var async = require('async')
var gutil = require('gulp-util')
var path = require('path')
var spawn = require('child_process').spawn
var through = require('through2')
const _ = require('lodash')
const async = require('async')
const gutil = require('gulp-util')
const path = require('path')
const spawn = require('child_process').spawn
const through = require('through2')
var PLUGIN_NAME = 'gulp-shell'
const PLUGIN_NAME = 'gulp-shell'

@@ -32,6 +32,6 @@ function normalizeCommands (commands) {

var pathToBin = path.join(process.cwd(), 'node_modules', '.bin')
var pathName = /^win/.test(process.platform) ? 'Path' : 'PATH'
var newPath = pathToBin + path.delimiter + process.env[pathName]
options.env = _.extend(process.env, _.fromPairs([[pathName, newPath]]), options.env)
const pathToBin = path.join(process.cwd(), 'node_modules', '.bin')
const pathName = /^win/.test(process.platform) ? 'Path' : 'PATH'
const newPath = pathToBin + path.delimiter + process.env[pathName]
options.env = _.extend({}, process.env, {[pathName]: newPath}, options.env)

@@ -42,4 +42,4 @@ return options

function runCommands (commands, options, file, done) {
async.eachSeries(commands, function (command, done) {
var context = _.extend({file: file}, options.templateData)
async.eachSeries(commands, (command, done) => {
const context = _.extend({file}, options.templateData)
command = gutil.template(command, context)

@@ -51,3 +51,3 @@

var child = spawn(command, {
const child = spawn(command, {
env: options.env,

@@ -59,3 +59,3 @@ cwd: gutil.template(options.cwd, context),

child.on('exit', function (code) {
child.on('exit', (code) => {
if (code === 0 || options.ignoreErrors) {

@@ -65,9 +65,9 @@ return done()

var context = _.extend({
command: command,
file: file,
error: {code: code}
const context = _.extend({
command,
file,
error: {code}
}, options.templateData)
var message = gutil.template(options.errorMessage, context)
const message = gutil.template(options.errorMessage, context)

@@ -83,10 +83,8 @@ done(new gutil.PluginError(PLUGIN_NAME, message))

var stream = through.obj(function (file, _encoding, done) {
var self = this
runCommands(commands, options, file, function (error) {
const stream = through.obj(function (file, _encoding, done) {
runCommands(commands, options, file, (error) => {
if (error) {
self.emit('error', error)
this.emit('error', error)
} else {
self.push(file)
this.push(file)
}

@@ -102,8 +100,6 @@ done()

shell.task = function (commands, options) {
return function (done) {
runCommands(normalizeCommands(commands), normalizeOptions(options), null, done)
}
shell.task = (commands, options) => (done) => {
runCommands(normalizeCommands(commands), normalizeOptions(options), null, done)
}
module.exports = shell
{
"name": "gulp-shell",
"version": "0.6.0",
"version": "0.6.1",
"description": "A handy command line interface for gulp",

@@ -40,3 +40,6 @@ "main": "index.js",

"through2": "^2.0.3"
},
"engines": {
"node": ">=4"
}
}
# gulp-shell
[![NPM version][npm-image]][npm-url]
[![Standard - JavaScript Style Guide][standard-image]][standard-url]
[![Build Status][travis-image]][travis-url]
[![Coveralls Status][coveralls-image]][coveralls-url]
[![Dependency Status][david-dm-image]][david-dm-url]
[![Downloads][downloads-image]][npm-url]
[![NPM version](https://img.shields.io/npm/v/gulp-shell.svg)](https://npmjs.org/package/gulp-shell)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](http://standardjs.com/)
[![Build Status](https://img.shields.io/travis/sun-zheng-an/gulp-shell/master.svg)](https://travis-ci.org/sun-zheng-an/gulp-shell)
[![Coveralls Status](https://img.shields.io/coveralls/sun-zheng-an/gulp-shell/master.svg)](https://coveralls.io/r/sun-zheng-an/gulp-shell)
[![Dependency Status](https://img.shields.io/david/sun-zheng-an/gulp-shell.svg)](https://david-dm.org/sun-zheng-an/gulp-shell)
[![Downloads](https://img.shields.io/npm/dm/gulp-shell.svg)](https://npmjs.org/package/gulp-shell)
[npm-url]: https://npmjs.org/package/gulp-shell
[npm-image]: https://img.shields.io/npm/v/gulp-shell.svg
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: http://standardjs.com/
[travis-url]: https://travis-ci.org/sun-zheng-an/gulp-shell
[travis-image]: https://img.shields.io/travis/sun-zheng-an/gulp-shell/master.svg
[coveralls-url]: https://coveralls.io/r/sun-zheng-an/gulp-shell
[coveralls-image]: https://img.shields.io/coveralls/sun-zheng-an/gulp-shell/master.svg
[david-dm-url]: https://david-dm.org/sun-zheng-an/gulp-shell
[david-dm-image]: https://img.shields.io/david/sun-zheng-an/gulp-shell.svg
[downloads-image]: https://img.shields.io/npm/dm/gulp-shell.svg
> A handy command line interface for gulp

@@ -33,22 +21,13 @@

```js
var gulp = require('gulp')
var shell = require('gulp-shell')
const gulp = require('gulp')
const shell = require('gulp-shell')
gulp.task('example', function () {
gulp.task('example', () => {
return gulp.src('*.js', {read: false})
.pipe(shell([
'echo <%= f(file.path) %>',
'ls -l <%= file.path %>'
], {
templateData: {
f: function (s) {
return s.replace(/$/, '.bak')
}
}
}))
.pipe(shell([
'echo <%= file.path %>'
]))
})
```
If you just want to execute a series of commands only once, ~~starting the stream with `gulp.src('')`~~ should do the trick. However, [this is an anti-pattern](https://github.com/sun-zheng-an/gulp-shell/issues/55), and **it won't work in `gulp 4.0`** .
Or you can use this shorthand:

@@ -63,5 +42,5 @@

You can find more examples in the [gulpfile][] of this project.
You can find more examples in the [gulpfile](https://github.com/sun-zheng-an/gulp-shell/blob/master/gulpfile.js) of this project.
[gulpfile]: https://github.com/sun-zheng-an/gulp-shell/blob/master/gulpfile.js
**WARNING**: Running commands like ~~`gulp.src('').pipe(shell('whatever'))`~~ is [considered as an anti-pattern](https://github.com/sun-zheng-an/gulp-shell/issues/55). **PLEASE DON'T DO THAT ANYMORE**.

@@ -78,2 +57,4 @@ ## API

**WARNING**: [Using command templates can be extremely dangerous](https://github.com/sun-zheng-an/gulp-shell/issues/83). Don't shoot yourself in the foot by ~~passing arguments like `$(rm -rf $HOME)`~~.
#### options.cwd

@@ -145,2 +126,2 @@

[template]: http://lodash.com/docs#template
[file]: https://github.com/wearefractal/vinyl
[file]: https://github.com/wearefractal/vinyl
/* eslint-env mocha */
var gutil = require('gulp-util')
var join = require('path').join
var expect = require('chai').expect
const gutil = require('gulp-util')
const join = require('path').join
const expect = require('chai').expect
var shell = require('..')
const shell = require('..')

@@ -12,7 +12,7 @@ function expectToBeOk (stream, done) {

.on('error', done)
.on('data', function () { done() })
.on('data', () => { done() })
}
describe('gulp-shell(commands, options)', function () {
var fakeFile = new gutil.File({
describe('gulp-shell(commands, options)', () => {
const fakeFile = new gutil.File({
cwd: __dirname,

@@ -23,14 +23,14 @@ base: __dirname,

it('throws when `commands` is missing', function () {
it('throws when `commands` is missing', () => {
expect(shell).to.throw('Missing commands')
})
it('works when `commands` is a string', function () {
it('works when `commands` is a string', () => {
expect(shell.bind(null, 'true')).to.not.throw()
})
it('passes file through', function (done) {
var stream = shell(['true'])
it('passes file through', (done) => {
const stream = shell(['true'])
stream.on('data', function (file) {
stream.on('data', (file) => {
expect(file).to.equal(fakeFile)

@@ -43,5 +43,5 @@ done()

it('executes command after interpolation', function (done) {
var stream = shell([
'test <%= file.path %> = ' + fakeFile.path
it('executes command after interpolation', (done) => {
const stream = shell([
`test <%= file.path %> = ${fakeFile.path}`
])

@@ -54,5 +54,5 @@

it('prepends `./node_modules/.bin` to `PATH`', function (done) {
var stream = shell([
'echo $PATH | grep -q "' + join(process.cwd(), 'node_modules/.bin') + '"'
it('prepends `./node_modules/.bin` to `PATH`', (done) => {
const stream = shell([
`echo $PATH | grep -q "${join(process.cwd(), 'node_modules/.bin')}"`
], {shell: 'bash'})

@@ -65,5 +65,5 @@

describe('.task(commands, options)', function () {
it('returns a function which returns a callback', function (done) {
var task = shell.task(['echo hello world'])
describe('.task(commands, options)', () => {
it('returns a function which returns a callback', (done) => {
const task = shell.task(['echo hello world'])

@@ -76,7 +76,7 @@ expect(task).to.be.a('function')

describe('options', function () {
describe('cwd', function () {
it('sets the current working directory when `cwd` is a string', function (done) {
var stream = shell([
'test $PWD = ' + join(__dirname, '../..')
describe('options', () => {
describe('cwd', () => {
it('sets the current working directory when `cwd` is a string', (done) => {
const stream = shell([
`test $PWD = ${join(__dirname, '../..')}`
], {cwd: '..'})

@@ -89,5 +89,5 @@

it('uses the process current working directory when `cwd` is not passed', function (done) {
var stream = shell([
'test $PWD = ' + join(__dirname, '..')
it('uses the process current working directory when `cwd` is not passed', (done) => {
const stream = shell([
`test $PWD = ${join(__dirname, '..')}`
])

@@ -101,5 +101,5 @@

describe('shell', function () {
it('changes the shell', function (done) {
var stream = shell([
describe('shell', () => {
it('changes the shell', (done) => {
const stream = shell([
'[[ $0 = bash ]]'

@@ -114,5 +114,5 @@ ], {shell: 'bash'})

describe('quiet', function () {
it("won't output anything when `quiet` == true", function (done) {
var stream = shell(['echo cannot see me!'], {quiet: true})
describe('quiet', () => {
it("won't output anything when `quiet` == true", (done) => {
const stream = shell(['echo cannot see me!'], {quiet: true})

@@ -125,7 +125,7 @@ expectToBeOk(stream, done)

describe('ignoreErrors', function () {
it('emits error by default', function (done) {
var stream = shell(['false'])
describe('ignoreErrors', () => {
it('emits error by default', (done) => {
const stream = shell(['false'])
stream.on('error', function () {
stream.on('error', () => {
done()

@@ -137,10 +137,10 @@ })

it("won't emit error when `ignoreErrors` == true", function (done) {
var stream = shell(['false'], {ignoreErrors: true})
it("won't emit error when `ignoreErrors` == true", (done) => {
const stream = shell(['false'], {ignoreErrors: true})
stream.on('error', function () {
stream.on('error', () => {
throw new Error()
})
stream.on('data', function () {
stream.on('data', () => {
done()

@@ -153,8 +153,8 @@ })

describe('errorMessage', function () {
it('allows for custom messages', function (done) {
var errorMessage = 'foo'
var stream = shell(['false'], {errorMessage: errorMessage})
describe('errorMessage', () => {
it('allows for custom messages', (done) => {
const errorMessage = 'foo'
const stream = shell(['false'], {errorMessage})
stream.on('error', function (error) {
stream.on('error', (error) => {
expect(error.message).to.equal(errorMessage)

@@ -167,8 +167,8 @@ done()

it('includes the error object in the error context', function (done) {
var errorMessage = 'Foo <%= error.code %>'
var expectedMessage = 'Foo 2'
var stream = shell(['exit 2'], {errorMessage: errorMessage})
it('includes the error object in the error context', (done) => {
const errorMessage = 'Foo <%= error.code %>'
const expectedMessage = 'Foo 2'
const stream = shell(['exit 2'], {errorMessage})
stream.on('error', function (error) {
stream.on('error', (error) => {
expect(error.message).to.equal(expectedMessage)

@@ -175,0 +175,0 @@ done()

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc