Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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);
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));
});
});
});
}).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 => {
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);
});
}
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.');
});
});
}
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.');
});
});
}
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);
});
}
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);
});
}
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;
});
});
}
], function(scriptDir){
return scriptDir ? fs.exists(scriptDir) : false;
}).map(function(scriptDir){
var scriptPath = '';