scripts/build/plugins/gulpTouch.js

Summary

Maintainability
A
1 hr
Test Coverage
import PluginError from 'plugin-error';
import through from 'through2';
import fs from 'fs-extra';

export default function touch(mtime) {

  async function touchFile(file) {
    const fd = await fs.open(file.path, 'a');
    try {
      await fs.futimes(fd, mtime, mtime);
    } finally {
      await fs.close(fd);
    }
  }

  function processStream(file, encoding, callback) {
    if (file.isNull()) {
      callback();
      return;
    }
    if (file.isStream()) {
      this.emit('error', new PluginError('gulpTouch', 'Stream not supported'));
      callback();
      return;
    }
    touchFile(file)
      .catch(err => this.emit('error', err))
      .then(() => {
        this.push(file);
        callback();
      });
  }

  return through.obj(processStream);

};