Rename one file during copying process with Gulp

357 views Asked by At

I want to automate the process of packing my extension for Chrome and Firefox and for that I'm using Gulp. I have two different manifest files, one for Chrome and one for Firefox (manifest.json and manifestff.json) in the root directory of the project. Now, I want to:

  1. Copy everything needed to directory for Chrome extension.
  2. Do the same thing for Firefox extension except that I want to rename manifestff.json into manifest.json in the process.

Here is my current task for packing extension for Firefox:

gulp.task('pack-firefox', () => {
    return gulp.src([
        'manifestff.json',
        'index.html',
        './public/**'
    ], {'base': '.'})
    .pipe(gulp.dest('./ff'));
}

Is it possible to specify (with additional .pipe()) that I want to copy manifestff.json as manifest.json?

1

There are 1 answers

0
Mark On BEST ANSWER

Look into gulp-if

const gulp = require('gulp');
const rename = require('gulp-rename');
const gulpIF = require('gulp-if');


gulp.task('pack-firefox', () => {
  return gulp.src([
    'manifestff.json',
    'index.html',
    './public/**'
  ], { 'base': '.' })
    .pipe(gulpIF(function (file) { return file.path.match('manifestff.json') }, rename('manifest.json')))
    .pipe(gulp.dest('./ff'));
});