How to use the hexo-fs.existsSync 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 poacher2k / hexo-featured-image / index.js View on Github external
hexo.extend.filter.register('before_exit', function() {
	// to work smoothly with hexo_generator_json_content
	var jsonContentCfg = hexo.config.hasOwnProperty('jsonContent')
		? hexo.config.jsonContent
		: {
				meta: true,
		  };
	var postsCfg = jsonContentCfg.hasOwnProperty('posts')
		? jsonContentCfg.posts
		: {};

	if (postsCfg.featured_image && fs.existsSync(contentJsonPath)) {
		var postsObject = {};
		var posts = hexo.locals.get('posts');
		posts.forEach(function(post) {
			postsObject[post.path] = post;
		});
		var content = JSON.parse(fs.readFileSync(contentJsonPath));
		var contentPosts = content.posts;
		if (!contentPosts) return;
		content.posts = contentPosts.map(function(post) {
			var fullPost = postsObject[post.path];
			if (fullPost && fullPost.featured_image) {
				post.featured_image = fullPost.featured_image;
				if (postsCfg.thumbnail && fullPost.thumbnail) {
					post.thumbnail = fullPost.thumbnail;
				}
			}
github Tencent / feflow / lib / internal / clean / clean.js View on Github external
module.exports = function (args) {
  const { log, baseDir, pluginDir, logDir } = this;
  const packagePath = pathFn.join(baseDir, 'package.json');
  const packageLockPath = pathFn.join(baseDir, 'package-lock.json');

  // Remove plugin dir
  if (fs.existsSync(pluginDir) && fs.lstatSync(pluginDir).isDirectory()) {
    deleteFolderRecursive(pluginDir);
  }

  // Remove log dir
  if (fs.existsSync(logDir) && fs.lstatSync(logDir).isDirectory()) {
    deleteFolderRecursive(logDir);
  }

  // Remove package-lock.json
  fs.unlinkSync(packageLockPath);

  // Rewrite package.json
  fs.writeFileSync(packagePath, JSON.stringify({
    'name': 'feflow-home',
    'version': '0.0.0',
    'private': true
github EYHN / hexo-helper-live2d / index.js View on Github external
* Use custom
     */
    return scriptFrom;

  }

}

if (config.enable) {

  _.unset(config, 'enable');
  if (_.hasIn(config, 'model.use')) {

    let modelJsonUrl = null;
    let tryPath = path.resolve(hexo.base_dir, './live2d_models/', config.model.use);
    if (fs.existsSync(tryPath)) { // eslint-disable-line no-sync

      /*
       * Is in live2d_models(2)
       * LoadModelFrom
       */
      const {
        modelGenerators,
        'modelJsonUrl': pkgModelJsonUrl,
      } = loadModelFrom(tryPath, `${config.pluginRootPath}${config.pluginModelPath}`);
      modelJsonUrl = `${blogRoot}${pkgModelJsonUrl}`;
      generators.push(...modelGenerators);
      if (config.log) {

        print.log(`Loaded model from live2d_models folder(2), '${url.parse(modelJsonUrl).pathname}' from '${tryPath}'`);

      }
github Tencent / feflow / lib / internal / clean / clean.js View on Github external
module.exports = function (args) {
  const { log, baseDir, pluginDir, logDir } = this;
  const packagePath = pathFn.join(baseDir, 'package.json');
  const packageLockPath = pathFn.join(baseDir, 'package-lock.json');

  // Remove plugin dir
  if (fs.existsSync(pluginDir) && fs.lstatSync(pluginDir).isDirectory()) {
    deleteFolderRecursive(pluginDir);
  }

  // Remove log dir
  if (fs.existsSync(logDir) && fs.lstatSync(logDir).isDirectory()) {
    deleteFolderRecursive(logDir);
  }

  // Remove package-lock.json
  fs.unlinkSync(packageLockPath);

  // Rewrite package.json
  fs.writeFileSync(packagePath, JSON.stringify({
    'name': 'feflow-home',
    'version': '0.0.0',
    'private': true
  }, null, 4));

  log.info('Feflow 重新重新初始化完成');
};
github OpenGeoscience / geojs / website / themes / agency / scripts / helper.js View on Github external
hexo.extend.helper.register('fileExists', function(path) {
    return fs.existsSync(path);
});
github Tencent / feflow / lib / internal / create / create.js View on Github external
run(generator, subgenerator) {
    const ctx = this.ctx;
    const pluginDir = ctx.pluginDir;
    let path = pathFn.join(pluginDir, generator, `${subgenerator}/index.js`);
    if (!fs.existsSync(path)) {
      path = pathFn.join(pluginDir, generator, 'generators', `${subgenerator}/index.js`);
    }
    yeomanEnv.register(require.resolve(path), generator);
    yeomanEnv.run(generator, this.args, err => {});
  }
github Tencent / feflow / lib / internal / clean / clean.js View on Github external
const deleteFolderRecursive = function (path) {
  if (fs.existsSync(path)) {
    fs.readdirSync(path).forEach(function (file) {
      const curPath = path + '/' + file;
      if (fs.lstatSync(curPath).isDirectory()) {
        deleteFolderRecursive(curPath);
      } else {
        fs.unlinkSync(curPath);
      }
    });
    fs.rmdirSync(path);
  }
};
github tea3 / hexo-generator-amp / lib / cache.js View on Github external
module.exports.getCacheHash = function(hexoConfig){
  var result = null;
  if( existsOption(hexoConfig) && fs.existsSync(getCachePath(hexoConfig)) ){
    if(!read_cacheData){
      read_cacheData = fs.readFileSync( getCachePath(hexoConfig) );
      read_cacheData = JSON.parse(read_cacheData);
    }
    
    if(!read_cacheData.hash){
      return "";
    }else{
      return read_cacheData.hash;
    }
  }else{
    return "";
  }
};
github mythsman / hexo-douban / index.js View on Github external
self.load().then(function () {
    if(!fs.existsSync(publicDir)){
      fs.mkdirSync(publicDir);
    }
    if(!fs.existsSync(path.join(publicDir,'assets'))){
      fs.mkdirSync(path.join(publicDir,'assets'));
    }
    self.route.get(doubanLoadingPath)._data().then(function (stream) {
      stream.pipe(fs.createWriteStream(path.join(publicDir, doubanLoadingPath)));
    });
    names.forEach(name => {
      var id = name + "/index.html";
      self.route.get(id) && self.route.get(id)._data().then(function (contents) {
        fs.writeFile(path.join(publicDir, id), contents);
        log.info("Generated: %s", id);
      });
    });
  });