Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};
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))
it('stat()', () => Promise.all([
fs.stat(file.source),
file.stat()
]).then(stats => {
stats[0].should.eql(stats[1]);
}));
}).then(post => {
hexo.config.post_asset_folder = false;
return fs.stat(path);
}).then(stats => {
stats.isDirectory().should.be.true;
return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({
_id: cacheId,
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);
}
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
() => stat(src)
).then(result => ({