juanfran / gulp-jade-inheritance

Gulp plugin to rebuild jade files and other files that have extended or included those files
34 stars 32 forks source link

Skipping jadeInheritance() on initial launch #6

Closed piotrd closed 9 years ago

piotrd commented 9 years ago

Hi there. I have a project with quite a lot of views (>130 jade files). Analyzing all of them by jadeInheritance() is not needed on initial run, since all of them need to be compiled by jade anyway. I was trying to find a way to skip jadeInheritance() on first build and run it subsequently on the changed files only, but so far I got nowhere.

Does anyone have any idea of how to achieve that?

For reference, here is my task:

gulp.task('views', [], function() {
  var srcPath = config.app('/views/**/*.jade');
  var destPath = config.dist('views/');

  return gulp.src(srcPath)
    .pipe(newer({dest: destPath, ext: '.html'}))
    .pipe(cached('jade'))

    //I'd like to skip this on initial run
    .pipe(jadeInheritance({basedir: config.app('/views')}))

    .pipe(filter(function (file) {
      return !/\/_/.test(file.path) && !/^_/.test(file.relative);
    }))
    .pipe(jade())
    .on('error', handleErrors)
    .pipe(gulpIf(config.htmlmin, htmlmin({collapseWhitespace: true})))
    .on('error', handleErrors)
    .pipe(gulp.dest(destPath));
});
piotrd commented 9 years ago

I finally ended up with using node.js' fs module like this:

gulp.task('views', [], function() {
  var srcPath = config.app('/views/**/*.jade');
  var destPath = config.dist('views/');
  var destPathExists = false;
  try {
    destPathExists = fs.statSync(destPath).isDirectory();
  } catch (ex) {
  }

  return gulp.src(srcPath)
    .pipe(newer({dest: destPath, ext: '.html'}))

    //filter out unchanged partials, but it only works when watching
    .pipe(cached('jade'))

    .pipe(gulpif(destPathExists, jadeInheritance({basedir: config.app('/views')})))

    //filter out partials (folders and files starting with "_" )
    .pipe(filter(function (file) {
      return !/\/_/.test(file.path) && !/^_/.test(file.relative);
    }))
    .pipe(jade())
    .on('error', handleErrors)
    .pipe(gulpif(config.htmlmin, htmlmin({collapseWhitespace: true})))
    .on('error', handleErrors)
    .pipe(gulp.dest(destPath));
});