吞吐任务来处理可写的文件 [英] gulp task to process files that are writable

查看:108
本文介绍了吞吐任务来处理可写的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS2015项目中使用Gulp,通过运行 jscs JavaScript文件,修复选项集。目的是修改读取的文件(即源文件和目标文件相同)。

I'm using Gulp in a VS2015 project to run jscs on JavaScript files with the fix option set. The intention is to modify the same file that is read (viz., source and destination are the same).

var gulp = require('gulp');
var jscs = require('gulp-jscs');
var chmod = require('gulp-chmod');
var exec = require('gulp-exec');

var ourJsFiles = // an array of files and globbed paths 

gulp.task('jscs', function (callback) {
   ourJsFiles.forEach(function (fn) {
      gulp.src(fn, { base: './' })
         .pipe(jscs({
            "preset": "google",
            "maximumLineLength": 160,
            "validateIndentation": 3,
            "fix": true
         }))
         .pipe(gulp.dest('./'));
   });
   callback();
});

但我不想 处理任何只读的文件。有没有一种方法可以在Windows上的Gulp中检测到这一点?

But I do not want to process any files that are read-only. Is there already a way to detect this in Gulp on Windows?

推荐答案

有一个插件允许您使用子集文件: gulp-filter
其中一个选项是传递过滤器函数,它将接收乙烯基文件对象,所以例如您可以使用该对象的 stat.mode 属性来拥有权限并执行如下操作:

There is a plugin which allows you to work with subset of files: gulp-filter. One of options is to pass filter function which will receive vinyl file object, so for e.g. you could use stat.mode property of that object which holds permissions and do something like:

var filter = require('gulp-filter');
...
var writableFiles = filter(function (file) {
        //https://github.com/nodejs/node-v0.x-archive/issues/3045
        var numericPermission = '0'+(e.stat.mode & parseInt('777', 8)).toString(8);
        return numericPermission[1]==='6'
    });
...
gulp.src(....)
    .pipe(writableFiles)

这篇关于吞吐任务来处理可写的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆