packages/touch/dist/commands/touch.js
function file(path, options) {
    try {
      try {
        fs.lstatSync(path);
      } catch (e) {
        // If the file doesn't exist and
        // the user doesn't want to create it,
        // we have no purpose in life. Goodbye.
        if (options.create === false) {
          throw new Error(e);
        } else {
          fs.closeSync(fs.openSync(path, 'wx'));
        }
      }

      var stat = fs.statSync(path);
      var dateToSet = options.date ? Date.create(options.date) : new Date();

      if (String(dateToSet) === 'Invalid Date') {
        throw new Error('touch: invalid date format ' + options.date);
      }

      // If -m, keep access time current.
      var atime = options.m === true ? new Date(stat.atime) : dateToSet;

      // If -a, keep mod time to current.
      var mtime = options.a === true ? new Date(stat.mtime) : dateToSet;

      if (options.reference !== undefined) {
        var reference = void 0;
        try {
          reference = fs.statSync(options.reference);
        } catch (e) {
          throw new Error('touch: failed to get attributes of ' + options.reference + ': No such file or directory');
        }
        atime = options.m === true ? atime : reference.atime;
        mtime = options.a === true ? mtime : reference.mtime;
      }

      fs.utimesSync(path, atime, mtime);
      fs.utimesSync(path, atime, mtime);
    } catch (e) {
      throw new Error(e);
    }
  }
function file(path, options) {
    try {
      try {
        fs.lstatSync(path);
      } catch (e) {
        // If the file doesn't exist and
        // the user doesn't want to create it,
        // we have no purpose in life. Goodbye.
        if (options.create === false) {
          throw new Error(e);
        } else {
          fs.closeSync(fs.openSync(path, 'wx'));
        }
      }

      var stat = fs.statSync(path);
      var dateToSet = options.date ? Date.create(options.date) : new Date();

      if (String(dateToSet) === 'Invalid Date') {
        throw new Error('touch: invalid date format ' + options.date);
      }

      // If -m, keep access time current.
      var atime = options.m === true ? new Date(stat.atime) : dateToSet;

      // If -a, keep mod time to current.
      var mtime = options.a === true ? new Date(stat.mtime) : dateToSet;

      if (options.reference !== undefined) {
        var reference = void 0;
        try {
          reference = fs.statSync(options.reference);
        } catch (e) {
          throw new Error('touch: failed to get attributes of ' + options.reference + ': No such file or directory');
        }
        atime = options.m === true ? atime : reference.atime;
        mtime = options.a === true ? mtime : reference.mtime;
      }

      fs.utimesSync(path, atime, mtime);
      fs.utimesSync(path, atime, mtime);
    } catch (e) {
      throw new Error(e);
    }
  }
function file ( path , options ) { try { try { fs . lstatSync ( path ) ; } catch ( e ) { // If the file doesn't exist and // the user doesn't want to create it, // we have no purpose in life. Goodbye. if ( options . create === false ) { throw new Error ( e ) ; } else { fs . closeSync ( fs . openSync ( path , 'wx' ) ) ; } } var stat = fs . statSync ( path ) ; var dateToSet = options . date ? Date . create ( options . date ) : new Date ( ) ; if ( String ( dateToSet ) === 'Invalid Date' ) { throw new Error ( 'touch: invalid date format ' + options . date ) ; } // If -m, keep access time current. var atime = options . m === true ? new Date ( stat . atime ) : dateToSet ; // If -a, keep mod time to current. var mtime = options . a === true ? new Date ( stat . mtime ) : dateToSet ; if ( options . reference !== undefined ) { var reference = void 0 ; try { reference = fs . statSync ( options . reference ) ; } catch ( e ) { throw new Error ( 'touch: failed to get attributes of ' + options . reference + ': No such file or directory' ) ; } atime = options . m === true ? atime : reference . atime ; mtime = options . a === true ? mtime : reference . mtime ; } fs . utimesSync ( path , atime , mtime ) ; fs . utimesSync ( path , atime , mtime ) ; } catch ( e ) { throw new Error ( e ) ; } }
Handler for a single file using touch.

@param {String} path
@param {Object} options
@api private
Handler for a single file using touch .