Gulp task to process files available for writing

I am using Gulp on a VS2015 project to run jscs on JavaScript files with the option set fix

. The goal is to change the same file that is being read (namely, 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();
});

      

But I don't want to handle read-only files. Is there a way to detect this in Gulp on Windows?

+3


source to share


1 answer


There is a plugin that lets you work with a subset of files: gulp-filter . One option is to pass a filter function that will receive a vinyl file object , so for example you can use a property of stat.mode

that object that has permissions and does 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)

      

0


source







All Articles