gulp-execa

Gulp.js command execution for humans
授权协议 Apache-2.0 License
开发语言 SHELL
所属分类 应用工具、 终端/远程登录
软件类型 开源软件
地区 不详
投 递 者 何昆
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Build

Gulp.js command execution for humans.

As opposed to similar plugins or tochild_process.exec(),this uses Execa which provides:

gulp-execa adds Gulp-specific features toExeca including:

Commands can be executed either directly or inside afiles stream. Instreaming mode, unlike other libraries:

Example

gulpfile.js:

import gulp from 'gulp'
import { task, exec, stream } from 'gulp-execa'

export const audit = task('npm audit')

export const outdated = async () => {
  await exec('npm outdated')
}

export const sort = () =>
  gulp
    .src('*.txt')
    .pipe(stream(({ path }) => `sort ${path}`))
    .pipe(gulp.dest('sorted'))

Demo

You can try this library:

Install

npm install -D gulp-execa

This plugin requires Gulp 4.

This package is an ES module and must be loaded usingan import or import() statement,not require().

Methods

task(command, [options])

Returns a Gulp task that executes command.

import { task } from 'gulp-execa'

export const audit = task('npm audit')

exec(command, [options])

Executes command. The return value is both a promise and achild_process instance.

The promise will be resolved with thecommand result. Ifthe command failed, the promise will be rejected with a niceerror. If thereject: false option was used,the promise will be resolved with that error instead.

import { exec } from 'gulp-execa'

export const outdated = async () => {
  await exec('npm outdated')
}

stream(function, [options])

Returns a stream that executes a command on each input file.

function must:

  • take a Vinyl fileas argument. The most useful property is file.path butother propertiesare available as well.
  • return either:
    • a command string
    • an options object with a command property
    • undefined
import gulp from 'gulp'
import { stream } from 'gulp-execa'

export const sort = () =>
  gulp
    .src('*.txt')
    .pipe(stream(({ path }) => `sort ${path}`))
    .pipe(gulp.dest('sorted'))

Each file in the stream will spawn a separate process. This can consume lots ofresources so you should only use this method when there are no alternatives suchas:

  • firing a command programmatically instead of spawning a child process
  • passing several files, a directory or a globbing pattern as arguments to thecommand

The verbose,stdout,stderr,all andstdio options cannot be usedwith this method.

Command

By default no shell interpreter (like Bash or cmd.exe) is used. This meanscommand must be just the program and its arguments. No escaping/quoting isneeded, except for significant spaces (with a backslash).

Shell features such as globbing, variables and operators (like && > ;)should not be used. All of this can be done directly in Node.js instead.

Shell interpreters are slower, less secure and less cross-platform. However, youcan still opt-in to using them with theshell option.

import { writeFileStream } from 'fs'

import gulp from 'gulp'
import { task } from 'gulp-execa'

// Wrong
// export const check = task('npm audit && npm outdated')

// Correct
export const check = gulp.series(task('npm audit'), task('npm outdated'))

// Wrong
// export const install = task('npm install > log.txt')

// Correct
export const install = task('npm install', {
  stdout: writeFileStream('log.txt'),
})

Options

options is an optional object.

All Execa options can be used.Please refer to its documentation for a list of possible options.

The following options are available as well.

echo

Type: boolean
Default: true for task() and exec(),false for stream().

Whether the command should be printed on the console.

$ gulp audit
[13:09:39] Using gulpfile ~/code/gulpfile.js
[13:09:39] Starting 'audit'...
[13:09:39] [gulp-execa] npm audit
[13:09:44] Finished 'audit' after 4.96 s

verbose

Type: boolean
Default: true for task() and exec(),false for stream().

Whether both the command and its output (stdout/stderr) should be printedon the console instead of being returned in JavaScript.

$ gulp audit
[13:09:39] Using gulpfile ~/code/gulpfile.js
[13:09:39] Starting 'audit'...
[13:09:39] [gulp-execa] npm audit

                        == npm audit security report ===

found 0 vulnerabilities
 in 27282 scanned packages
[13:09:44] Finished 'audit' after 4.96 s

result

Type: string
Value: 'replace' or 'save'
Default: 'replace'

With stream(), whether the command result should:

  • replace the file's contents
  • save: be pushedto the file.execa array property
import gulp from 'gulp'
import { stream } from 'gulp-execa'
import through from 'through2'

export const task = () =>
  gulp
    .src('*.js')
    // Prints the number of lines of each file
    .pipe(stream(({ path }) => `wc -l ${path}`, { result: 'save' }))
    .pipe(
      through.obj((file, encoding, func) => {
        console.log(file.execa[0].stdout)
        func(null, file)
      }),
    )

from

Type: string
Value: 'stdout', 'stderr' or 'all'
Default: 'stdout'

Which output stream to use with result: 'replace'.

import gulp from 'gulp'
import { stream } from 'gulp-execa'
import through from 'through2'

export const task = () =>
  gulp
    .src('*.js')
    // Prints the number of lines of each file, including `stderr`
    .pipe(
      stream(({ path }) => `wc -l ${path}`, { result: 'replace', from: 'all' }),
    )
    .pipe(
      through.obj((file, encoding, func) => {
        console.log(file.contents.toString())
        func(null, file)
      }),
    )

maxConcurrency

Type: integer
Default: 100

With stream(), how many commands to run in parallelat once.

See also

Support

For any question, don't hesitate to submit an issue on GitHub.

Everyone is welcome regardless of personal background. We enforce aCode of conduct in order to promote a positive andinclusive environment.

Contributing

This project was made with ❤️ . The simplest way to give back is by starring andsharing it online.

If the documentation is unclear or has a typo, please click on the page's Editbutton (pencil icon) and suggest a correction.

If you would like to help us fix a bug or add a new feature, please check ourguidelines. Pull requests are welcome!

Thanks go to our wonderful contributors:

ehmicky
ehmicky

�� �� �� ��
Jonathan Haines
Jonathan Haines

��
  • Gulp 基于 node 平台开发的前端构建工具 将机械化操作编写成任务,想要执行机械化操作时执行一个命令行任务就会自动执行了。 用机器代替手工,提高效率。 Gulp能做什么 项目上线, html 、css、js文件压缩合并 语法转换(es6->es5、less->css…) 公共文件抽离 修改文件浏览器自动刷新 Gulp使用场景 项目的工程模块依赖比较简单,甚至没有模块化的概念。 只需要进行简单

  • gulp-useref的作用 它可以把html里零碎的这些引入合并成一个文件,但是它不负责代码压缩。 var gulp = require('gulp'), useref = require('gulp-useref'); gulp.task('default', function () { return gulp.src('app/*.html'

  • 什么是Gulp?如何使用Gulp Gulp 是基于node.js的一个前端自动化构建工具,开发这可以使用它构建自动化工作流程(前端集成开发环境)。  使用gulp你可以简化工作量,让你把重点放在功能的开发上,从而提高你的开发效率和工作质量。  例如:你可以用gulp可以网页自动刷新,和MVVM开发模式很相似,如果你对vue.js有所了解的话,那么你一定不会陌生。你也可以使用gulp对sass进行预

  • gulp-replace功能:替换目标文件中的文本 gulpfile.js: var gulp = require('gulp'); var replace = require('gulp-replace'); gulp.task('replaceTask',function(){ gulp.src('src/*.js') .pipe(replace(/console/gi,'aler

  • gulp-useref的作用 它可以把html里零碎的这些引入合并成一个文件,但是它不负责代码压缩。 var gulp = require('gulp'), useref = require('gulp-useref'); gulp.task('default', function () { return gulp.src('app/*.html'

  • 简介: 使用gulp-autoprefixer根据设置浏览器版本自动处理浏览器前缀。使用她我们可以很潇洒地写代码,不必考虑各浏览器兼容前缀。【特别是开发移动端页面时,就能充分体现它的优势。例如兼容性不太好的flex布局。】 1、安装nodejs/全局安装gulp/项目安装gulp/创建package.json和gulpfile.js文件 1.1、安装,全局的gulp cnpm instal

  • 概念: The gulp plugin gulp-order allows you to reorder a stream of files using the same syntax as of gulp.src,这是官方定义,简单来说,就是按给定的顺序整理需要处理的文件集。 用法: var order = require("gulp-order"); var coffee = require(

  • 概念 gulp.filter可以虚拟文件流中过滤特定的文件,可以当做是gulp.src的二次过滤,并且还可以restore操作恢复过滤前的gulp.src一次过滤的虚拟文件流。 安装 $ npm install –save-dev gulp-filter 使用 1.只过滤文件 You may want to just filter the stream content: const gulp =

  • gulp  :项目自动化构建打包工具(将我们本地的项目打包成放在外网的项目)     gulp项目目录结构        -gulp_demp(项目名)           -src              -css             -js             -pages    //html             -sass           package.json   //

  • 概念 spritesmith的作用就是拼接图片并生成样式表,并且还能输出SASS,Stylus,LESS甚至是JSON。github地址:https://github.com/twolfson/gulp.spritesmith Getting Started 1. Install the module with: npm install gulp.spritesmith var gulp = r

  • 概念 用来将HTML 文件中(或者templates/views)中没有优化的script 和stylesheets 替换为优化过的版本 gulp-usemin根据预先在html文件(或者其它模板/视图中的文件)中声明好的blocks来执行一系列任务(例如合并文件并重全名、排除一些只在开发过程中引入的脚本以及将css和js中的代码提取出来内嵌在html文件中)来处理未优化的样式和脚本。然后我们可以

 相关资料
  • 这篇快速上手指南将教你如何使用Gulp构建TypeScript,和如何在Gulp管道里添加Browserify,uglify或Watchify。 本指南还会展示如何使用Babelify来添加Babel的功能。 这里假设你已经在使用Node.js和npm了。 我们首先创建一个新目录。 命名为proj,也可以使用任何你喜欢的名字。 mkdir proj cd proj 我们将以下面的结构开始我们的工程

  • 更改历史 * 2017-11-12 杨海月 增加xxx内容,更改xxx内容,删除xxx内容 * 2017-11-01 胡小根 初始化文档 第一章 历史、现状及发展 1.1 gulp历史 gulp是前端开发过程中一种基于流的 代码构建工具 ,是自动化项目的构建利器;它不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成;使用它,不仅可

  • 问题内容: 我想遍历一个对象,并在每次迭代时将文件路径数组传递给gulp.src,然后对这些文件进行一些处理。下面的代码仅用于说明目的,因为return语句会在第一次通过时终止循环,因此实际上将无法工作。 这是基本思想。有关如何执行此操作的任何想法? 问题答案: 我能够使用合并流实现这一目标。如果有人感兴趣,这里是代码。这个想法是在循环内创建一个流数组,并在完成迭代后合并它们:

  • 我安装了gulp,但我不能使用“gulp”命令,因为它会给我“-bash:gulp:command not found”错误。当我使用“NPX GULP”,然后它的工作,但我不知道为什么。

  • gulp-concat:文件合并 gulp-connect:在本地开启一个websocket服务,使用liveReload实现实时更新 gulp-watch:监听文件的变化,配合connect实现服务自动刷新 gulp-plumber:实时更新错误不会导致终端gulp运行开启的服务断开 gulp-livereload:即时重整 gulp-clean:清理档案 gulp-load-plugins:自

  • gulp-load-plugins Automatically load any gulp plugins in your package.json Install $ npm install --save-dev gulp-load-plugins Given a package.json file that has some dependencies within: { "depen

  • Glup 简明使用教程 安装: $ npm install gulp -g $ npm install gulp --save-dev 安装gulp插件 编译Sass(gulp-sass) (gulp-ruby-sass) 编译Less(gulp-less) Autoprefixer (gulp-autoprefixer) 缩小化(minify)CSS (gulp-minify-css) JSH

  • 支援 Gulp 4.0,允许嵌套配置任务及组态。以优雅、直觉的方式,重复使用 gulp 任务。 编码的时候你遵守 DRY 原则,那编写 gulpfile.js 的时候,为什么不呢? 功能 支援 Gulp 4.0, 自动载入本地 recipe, 支援透过 npm 安装 plugin, 支援嵌套任务并且允许子任务继承组态配置, 支援向前、向后参照任务, 透过组态配置即可处理串流:譬如 merge, q