Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable no-console */
const base64Img = require('base64-img');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const iconsSrcDir = path.join(__dirname, 'src', 'icons');
const iconsLibDir = path.join(__dirname, 'lib', 'icons');
mkdirp.sync(iconsLibDir);
fs.readdir(path.join(__dirname, 'src', 'icons'), (err, files) => {
if (err) {
console.error(err);
process.exit(1);
}
for (const file of files) {
base64Img.base64(path.join(iconsSrcDir, file), (err, data) => {
if (err) {
console.error(err);
process.exit(1);
}
fs.writeFile(
path.join(iconsLibDir, file + '.js'),
`module.exports='${data}'`,
err => {
if (err) {
console.error(err);
return new Promise((res, rej) => {
fs.readdir(path, function(err, files){
//err错误 , files 文件名列表包含文件夹与文件
if(err){
console.log('error:\n' + err);
rej(-1)
return;
}
files.forEach(function(file){
fs.stat(path + '/' + file, function(err, stat){
if(err){console.log(err); return;}
if(stat.isDirectory()){
// 如果是文件夹遍历
explorer(path + '/' + file);
}else{
// 读出所有的文件
exec(cmd, { timeout: _pdf2htmlEXTimeout }, (err, stdout, stderr) => {
if (err) {
log().error({ err, cmd, stdout, stderr }, 'Could not convert page to html');
return callback({ code: 500, msg: 'Could not convert page to html' });
}
// Converting was succesful, get a list of files we generated
fs.readdir(pagesDir, (err, files) => {
if (err) {
log().error(
{ err, contentId: ctx.contentId },
'Could not read the %s directory to list the files',
pagesDir
);
return callback({ code: 500, msg: 'Could not read the directory' });
}
// Only return the page HTML files, ie: page.i.html
const htmlFiles = _.filter(files, file => {
return file.split('.')[0] === 'page' && file.split('.').pop() === 'html';
});
// Add each HTML to the list of previews that should be stored.
_.each(htmlFiles, htmlFile => {
fs.stat(filename, function (err, s) {
if (!err && s.isDirectory()) {
fs.readdir(filename, function(err, files) {
if (err) {
console.error('Error generating docs for files', filename, err);
return cb(err);
}
files.forEach(function(file) {
if (file.match(/\.js$/)) {
oneFile(filename, file, cb), touched++;
}
});
if(!touched) {
cb();
}
});
} else {
cb();
}
nThen((w) => {
Fs.readdir(ctx.workdir, w((err, ret) => {
if (err) { throw err; }
files = ret.filter((f) => /^paylog_[0-9]+_[a-f0-9]+.bin$/.test(f));
}));
}).nThen((w) => {
if (!files.length) { return; }
return (new Promise((fulfill, reject) => {
fs.readdir(pathname, (err, files) => {
if (err)
reject(err);
else
fulfill(files);
});
}));
}
function(cb) {
fs.readdir(path, cb);
},
return new Promise(function(resolve, reject) {
fs.readdir(path, function(err, files) {
err ? reject(err) : resolve(files)
})
})
}
function readdir(err) {
if (err)
return cb(err);
fs.readdir(path, function (err, ls) {
if (err)
return cb (err);
list = ls;
shift();
});
}