Пример #1
0
function mkdir (path, mode, callback) {
  if (typeof mode === 'function' && !callback) {
    callback = mode;
    mode = '0777';
  }

  var mkdirCallback = function (err) {
    if (err) {
      callback(err);
      return;
    }
    fs.mkdir(path, mode, function (err) {
      if (err && err.code == 'EEXIST') {
        callback(null);
        return;
      }
      callback(err);
    });
  };

  fs.exists(path, function (exists) {
    if (exists) {
      callback(null);
      return;
    }
    var parent = dirname(path);
    mkdir(parent, mode, mkdirCallback);
  });
}
Пример #2
0
/**
 * Creates the migrations directory if needed
 *
 * @param {String} dir
 * @param {Function} cb
 * @api Private
 */
function ensureExistingMigrationsDir (dir, cb) {
  fs.exists(dir, function (exists) {
    if (!exists) {
      fs.mkdirp(dir, function (err) {
        cb(err);
      });
    } else {
      cb(null);
    }
  });
}
Пример #3
0
exports.template = function (cb) {
  if (!cb || typeof cb !== 'function') {
    throw new Error('Missing callback!');
  }
  var path = this.templatePath();
  fs.exists(path, function (exists) {
    if (!exists) {
      cb(new Error('Could not find template: "' + path + '"'));
      return;
    }
    fs.readFile(path, 'utf8', function (err, content) {
      cb(err, content);
    });
  });
  return this;
};
Пример #4
0
 exists: q.denodeify(function (file, cb) {
   fs.exists(file, function (exists) { cb(null, exists); });
 }),