How to use the hexo-fs.exists function in hexo-fs

To help you get started, we’ve selected a few hexo-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hexojs / hexo / lib / plugins / tag / include_code.js View on Github external
}

  let title = '';
  let path = '';
  if (rCaptionTitleFile.test(arg)) {
    const match = arg.match(rCaptionTitleFile);
    title = match[1];
    path = match[3];
  }

  // Exit if path is not defined
  if (!path) return;

  const src = join(ctx.source_dir, codeDir, path);

  return fs.exists(src).then(exist => {
    if (exist) return fs.readFile(src);
  }).then(code => {
    if (!code) return;

    code = stripIndent(code).trim();

    if (!config.enable) {
      return `<pre><code>${code}</code></pre>`;
    }

    // If the title is not defined, use file name instead
    title = title || basename(path);

    // If the language is not defined, use file extension instead
    lang = lang || extname(path).substring(1);
github jaredly / hexo-admin / update.js View on Github external
fs.writeFile(full_source, raw, function(err){
      if (err) return callback(err);

      if (full_source !== prev_full) {
        fs.unlinkSync(prev_full)
        // move asset dir
        var assetPrev = removeExtname(prev_full);
        var assetDest = removeExtname(full_source);
        fs.exists(assetPrev).then(function(exist) {
          if (exist) {
            fs.copyDir(assetPrev, assetDest).then(function() {
              fs.rmdir(assetPrev);
            });
          }
        });
      }
      hexo.source.process([post.source]).then(function () {
  //      console.log(post.full_source, post.source)
        callback(null, hexo.model(model).get(id));
      });
    });
  });
github hexojs / hexo-deployer-git / test / deployer.js View on Github external
}).then(() => {
        const isExtHidFileExists = fs.exists(pathFn.join(validateDir, extendDirName, 'hid'));
        const isExtHidFile2Exists = fs.exists(pathFn.join(validateDir, extendDirName, 'hid2'));
        const isPubHidFileExists = fs.exists(pathFn.join(validateDir, 'hid'));

        return Promise.all([isExtHidFileExists, isExtHidFile2Exists, isPubHidFileExists]);
      }).then(statusLists => {
        statusLists.forEach(statusItem => {
github hexojs / hexo / lib / plugins / console / config.js View on Github external
if (!key) {
    console.log(this.config);
    return Promise.resolve();
  }

  if (!value) {
    value = getProperty(this.config, key);
    if (value) console.log(value);
    return Promise.resolve();
  }

  const configPath = this.config_path;
  const ext = extname(configPath);

  return fs.exists(configPath).then(exist => {
    if (!exist) return {};
    return this.render.render({path: configPath});
  }).then(config => {
    if (!config) config = {};

    setProperty(config, key, castValue(value));

    const result = ext === '.json' ? JSON.stringify(config) : yaml.dump(config);

    return fs.writeFile(configPath, result);
  });
}
github hexojs / hexo / lib / plugins / console / clean.js View on Github external
function deletePublicDir(ctx) {
  const publicDir = ctx.public_dir;

  return fs.exists(publicDir).then(exist => {
    if (!exist) return;

    return fs.rmdir(publicDir).then(() => {
      ctx.log.info('Deleted public folder.');
    });
  });
}
github hexojs / hexo / lib / plugins / console / clean.js View on Github external
function deleteDatabase(ctx) {
  const dbPath = ctx.database.options.path;

  return fs.exists(dbPath).then(exist => {
    if (!exist) return;

    return fs.unlink(dbPath).then(() => {
      ctx.log.info('Deleted database.');
    });
  });
}
github hexojs / hexo / lib / cli / find_pkg.js View on Github external
function findPkg(path){
  var pkgPath = pathFn.join(path, 'package.json');

  return fs.exists(pkgPath).then(function(exist){
    return exist ? checkPkg(pkgPath) : false;
  }).then(function(exist){
    if (exist) return path;

    var parent = pathFn.dirname(path);
    if (parent === path) return;

    return findPkg(parent);
  });
}
github hexojs / hexo / lib / hexo / post.js View on Github external
function createAssetFolder(path, assetFolder) {
  if (!assetFolder) return Promise.resolve();

  const target = removeExtname(path);

  return fs.exists(target).then(exist => {
    if (!exist) return fs.mkdirs(target);
  });
}
github Tencent / feflow / lib / internal / generator / generator.js View on Github external
getLocal(name) {
    const pluginDir = this.ctx.pluginDir;
    const path = pathFn.join(pluginDir, name, 'package.json');
    return fs.exists(path).then(function (exist) {
      if (!exist) return;

      return fs.readFile(path).then(function (content) {
        const pkg = JSON.parse(content);
        return pkg.version;
      });
    });
  }
github hexojs / hexo / lib / hexo / load_scripts.js View on Github external
], function(scriptDir){
    return scriptDir ? fs.exists(scriptDir) : false;
  }).map(function(scriptDir){
    var scriptPath = '';