How to use the hexo-fs.stat 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 / box / index.js View on Github external
Box.prototype.process = function(callback) {
  const { base, Cache, context: ctx } = this;

  return stat(base).then(stats => {
    if (!stats.isDirectory()) return;

    // Check existing files in cache
    const relativeBase = escapeBackslash(base.substring(ctx.base_dir.length));
    const cacheFiles = Cache.filter(item => item._id.startsWith(relativeBase)).map(item => item._id.substring(relativeBase.length));

    // Read files from directory
    return this._readDir(base, file => this._processFile(file.type, file.path)).map(file => file.path).then(files => // Handle deleted files
      Promise.filter(cacheFiles, path => !files.includes(path)).map(path => this._processFile(File.TYPE_DELETE, path)));
  }).catch(err => {
    if (err.cause && err.cause.code !== 'ENOENT') throw err;
  }).asCallback(callback);
};
github hexojs / hexo / lib / plugins / console / generate.js View on Github external
function firstGenerate() {
    // Show the loading time
    const interval = prettyHrtime(process.hrtime(start));
    log.info('Files loaded in %s', cyan(interval));

    // Reset the timer for later usage
    start = process.hrtime();

    // Check the public folder
    return fs.stat(publicDir).then(stats => {
      if (!stats.isDirectory()) {
        throw new Error('%s is not a directory', magenta(tildify(publicDir)));
      }
    }).catch(err => {
      // Create public folder if not exists
      if (err.cause && err.cause.code === 'ENOENT') {
        return fs.mkdirs(publicDir);
      }

      throw err;
    }).then(() => {
      const task = (fn, path) => () => fn(path);
      const doTask = fn => fn();
      const routeList = route.list();
      const publicFiles = Cache.filter(item => item._id.startsWith('public/')).map(item => item._id.substring(7));
      const tasks = publicFiles.filter(path => !routeList.includes(path))
github hexojs / hexo / test / scripts / box / file.js View on Github external
it('stat()', () => Promise.all([
    fs.stat(file.source),
    file.stat()
  ]).then(stats => {
    stats[0].should.eql(stats[1]);
  }));
github hexojs / hexo / test / scripts / hexo / post.js View on Github external
}).then(post => {
      hexo.config.post_asset_folder = false;
      return fs.stat(path);
    }).then(stats => {
      stats.isDirectory().should.be.true;
github hexojs / hexo / test / scripts / box / box.js View on Github external
    return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
      _id: cacheId,
github hexojs / hexo-cli / lib / console / init.js View on Github external
function removeGitDir(target) {
  const gitDir = pathFn.join(target, '.git');

  return fs.stat(gitDir).catch(err => {
    if (err.cause && err.cause.code === 'ENOENT') return;
    throw err;
  }).then(stats => {
    if (stats) {
      return stats.isDirectory() ? fs.rmdir(gitDir) : fs.unlink(gitDir);
    }
  }).then(() => fs.readdir(target)).map(path => pathFn.join(target, path)).filter(path => fs.stat(path).then(stats => stats.isDirectory())).each(removeGitDir);
}
github zthxxx / hexo-directory-category / lib / processor_post.js View on Github external
function scanAssetDir(post) {
    if (!ctx.config.post_asset_folder) return;

    const assetDir = post.asset_dir;
    const baseDir = ctx.base_dir;
    const baseDirLength = baseDir.length;
    const PostAsset = ctx.model('PostAsset');

    return fs.stat(assetDir).then(stats => {
      if (!stats.isDirectory()) return [];

      return fs.listDir(assetDir);
    }).catch(err => {
      if (err.cause && err.cause.code === 'ENOENT') return [];
      throw err;
    }).filter(item => !common.isTmpFile(item) && !common.isHiddenFile(item)).map(item => {
      const id = pathFn.join(assetDir, item).substring(baseDirLength).replace(/\\/g, '/');
      const asset = PostAsset.findById(id);
      if (asset) return undefined;

      return PostAsset.save({
        _id: id,
        post: post._id,
        slug: item,
        modified: true
github hexojs / hexo / lib / box / index.js View on Github external
    () => stat(src)
  ).then(result => ({