• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Klathmon/gulp-run-command: A simple way to run command-line programs from gulp i ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

Klathmon/gulp-run-command

开源软件地址(OpenSource Url):

https://github.com/Klathmon/gulp-run-command

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

gulp-run-command

js-standard-style

A simple way to run command-line programs from gulp in a cross-platform way.

Installation

npm install gulp-run-command

Usage

import gulp from 'gulp'
import run from 'gulp-run-command' // or `var run = require('gulp-run-command').default` for ES5

gulp.task('clean', run('rm -rf build'))
gulp.task('build', ['clean'], run('babel index.js --out-file index.es5.js', {
  env: { NODE_ENV: 'production' }
}))

API

run(command, options)

commands

type: Array or String

A command will be run "as if you typed it in the console". An array of commands will be run sequentially (waiting for each to finish before the next begins), stdin will be blank for all commands. Commands will be run like they are from npm scripts, locally installed modules can be run without having to prefix node_modules/.bin.

options.quiet

type: Boolean
default: false

Setting to true will ignore all output from the command (both stdout and stderr)

options.ignoreErrors

type: Boolean
default: false

Setting to true will ignore any errors that the command throws. It will also ignore return values.

options.cwd

type: String
default: process.cwd()

Sets the current working directory for the command. This is where the node_modules/.bin is searched for as well to be added to the path.

options.timeout

type: Number
default: undefined (no timeout)

The max time (in milliseconds) that the command is allowed to run

options.env

type: Object
default: {}

This object will be added to the normal environment, overwriting defaults with what you pass in. So if your "main" environment includes NODE_ENV="development" and you pass in { NODE_ENV: 'production'} the command will be run with NODE_ENV="production".

FAQ

Why?
I loved Gulp's dependency management and plugin ecosystem, but I hated having to use file streams or plugins which wrap my tools which are often out of date, buggy, or missing functionality. This plugin lets you define gulp tasks as command line commands which will be run. Most tools have a command line interface, so you are cutting out several unnecessary layers and giving yourself more flexibility.

What not just use gulp-shell?
gulp-shell is great, but sadly it uses child_process.exec. That means that output from the plugin is buffered and only output in chunks. This causes issues with command line applications that are expecting direct access to the console. (it also has a tendency to strip colors from the output). This uses child_process.spawn which is more difficult to use, but works much better.

Can you add this new feature?
Maybe... I'm trying to keep this a small single-purpose plugin, but if you want a feature feel free to open an issue and I'll take a look.

Gulp@4 support
In order to use gulp-run-command with Gulp@4, you need to call the return function after passing the command and options (formally known as currying). For example:

gulp.task('clean', async () => run('echo "Hello World!"')());

Inspiration

  • gulp-shell came up with the idea, I just changed it's underlying implementation.

Contributing

The code is written in ES6 using Javascript Standard Style. Feel free to make PRs adding features you want, but please try to follow Standard. Also, codumentation/readme PRs are more then welcome!

License

MIT Copyright (c) Gregory Benner




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap