Pattern Library Utilities

createFile

method
exports.createFile()

@param Type Description
filePath STRING relative path to file
cwd STRING current working directory
base STRING directory where we start looking for the file
type STRING stream|null
newDest STRING destination different from filePath

Creates a vinyl file

exports.createFile = function (filePath, cwd, base, type, newDest) {
  'use strict';
  var contents;

  if (type === 'stream') {
    contents = fs.createReadStream(filePath);
  }
  else {

    try {
      contents = fs.readFileSync(filePath);
    }
    catch (e) {
      throw new Error(filePath + ' cannot be read');
    }

  }

  // use new destination path if there is one
  filePath = newDest || filePath;

  return new File({
    path: filePath,
    cwd: cwd,
    base: base,
    contents: contents
  });

};

createNewFile

method
exports.createNewFile()

@param Type Description
filePath STRING relative path to file
cwd STRING current working directory
base STRING directory where we start looking for the file
contents STRING the file's contents

Creates a new vinyl file

exports.createNewFile = function (filePath, cwd, base, contents) {
  'use strict';

  return new File({
    path: filePath,
    cwd: cwd,
    base: base,
    contents: contents
  });

};