Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
quickCreate(generator, subgenerator) {
const {
pluginDir,
log,
} = this.ctx;
// 如果已经设置 默认脚手架
const dirPath = pathFn.join(pluginDir, generator, 'generators');
const files = fs.readdirSync(dirPath);
let selectedSub = '';
files.forEach((filename) => {
if (filename == subgenerator) {
selectedSub = subgenerator;
}
});
if (selectedSub) {
this.run(generator, subgenerator);
} else {
log.warn(
`当前默认父级脚手架为 ${generator} ${subgenerator} 不是其子级脚手架`
);
}
}
async list(generators, subgenerator) {
updateAny(model, id, {source: body.filename}, function (err, post) {
if (err) {
return res.send(400, err);
}
hexo.log.d(`renamed ${model.toLowerCase()} to ${body.filename}`)
// remove old folder if empty
if (model === 'Page' && fs.existsSync(oldPath)) {
if (fs.readdirSync(oldPath).length === 0) {
fs.rmdirSync(oldPath)
hexo.log.d('removed old page\'s empty directory')
}
}
res.done(addIsDraft(post))
}, hexo)
}
quickStart(subgenerator, generator) {
const {
pluginDir,
log
} = this.ctx;
const dirPath = pathFn.join(pluginDir, generator, 'generators');
if (fs.existsSync(dirPath)) {
const files = fs.readdirSync(dirPath);
let selectedSub = '';
files.forEach((filename) => {
if (filename == subgenerator) {
selectedSub = subgenerator;
}
});
if (selectedSub) {
this.run(generator, subgenerator);
} else {
log.error(
'请确认输入了正确的子脚手架'
);
}
} else {
log.error(
'请确认输入了正确的脚手架'
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);
}
};
function initConsole(args) {
args = Object.assign({ install: true, clone: true }, args);
const baseDir = this.base_dir;
const target = args._[0] ? pathFn.resolve(baseDir, String(args._[0])) : baseDir;
const { log } = this;
if (fs.existsSync(target) && fs.readdirSync(target).length !== 0) {
log.fatal(`${chalk.magenta(tildify(target))} not empty, please run \`hexo init\` on an empty folder and then copy your files into it`);
return Promise.reject(new Error('target not empty'));
}
log.info('Cloning hexo-starter', GIT_REPO_URL);
let promise;
if (args.clone) {
promise = spawn('git', ['clone', '--recursive', GIT_REPO_URL, target], {
stdio: 'inherit'
});
} else {
promise = copyAsset(target);
}
generators.forEach((generator) => {
if (generator.name) {
list.push({
type: 'separator',
line: `${chalk.green(generator.name)}`
});
const dirPath = pathFn.join(pluginDir, generator.name, 'generators');
const files = fs.readdirSync(dirPath);
files.shift();
files.forEach(file => {
list.push({
name: `${file}`,
value: `${file + ';' + generator.name}`
});
});
}
});
const answer = await inquirer.prompt([{
module.exports = function listFiles (dirPath) {
const lsDir = fs.readdirSync(dirPath);
const filesArr = [];
for (const fileName of lsDir) {
const pathName = path.join(dirPath, fileName);
if (fs.statSync(pathName).isDirectory()) {
filesArr.push(...listFiles(pathName));
} else {
filesArr.push(pathName);
}
}
return filesArr;