mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-01 21:30:30 +01:00
refactor: remove util.promisify calls
This commit is contained in:
@@ -4,9 +4,6 @@ require('colors');
|
||||
const path = require('path');
|
||||
const winston = require('winston');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
const fsAccessAsync = util.promisify(fs.access);
|
||||
|
||||
const db = require('../database');
|
||||
const events = require('../events');
|
||||
@@ -100,7 +97,7 @@ async function resetSettings() {
|
||||
|
||||
async function resetTheme(themeId) {
|
||||
try {
|
||||
await fsAccessAsync(path.join(dirname, 'node_modules', themeId, 'package.json'));
|
||||
await fs.promises.access(path.join(dirname, 'node_modules', themeId, 'package.json'));
|
||||
} catch (err) {
|
||||
winston.warn('[reset] Theme `%s` is not installed on this forum', themeId);
|
||||
throw new Error('theme-not-found');
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const file = require('../../file');
|
||||
|
||||
@@ -17,7 +15,7 @@ themesController.get = async function (req, res, next) {
|
||||
|
||||
let themeConfig;
|
||||
try {
|
||||
themeConfig = await readFileAsync(themeConfigPath, 'utf8');
|
||||
themeConfig = await fs.promises.readFile(themeConfigPath, 'utf8');
|
||||
themeConfig = JSON.parse(themeConfig);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
|
||||
@@ -4,9 +4,6 @@ const path = require('path');
|
||||
const nconf = require('nconf');
|
||||
const mime = require('mime');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readdirAsync = util.promisify(fs.readdir);
|
||||
const statAsync = util.promisify(fs.stat);
|
||||
|
||||
const meta = require('../../meta');
|
||||
const posts = require('../../posts');
|
||||
@@ -27,7 +24,7 @@ uploadsController.get = async function (req, res, next) {
|
||||
const itemsPerPage = 20;
|
||||
const page = parseInt(req.query.page, 10) || 1;
|
||||
try {
|
||||
let files = await readdirAsync(currentFolder);
|
||||
let files = await fs.promises.readdir(currentFolder);
|
||||
files = files.filter(filename => filename !== '.gitignore');
|
||||
const itemCount = files.length;
|
||||
var start = Math.max(0, (page - 1) * itemsPerPage);
|
||||
@@ -91,10 +88,10 @@ async function filesToData(currentDir, files) {
|
||||
}
|
||||
|
||||
async function getFileData(currentDir, file) {
|
||||
const stat = await statAsync(path.join(currentDir, file));
|
||||
const stat = await fs.promises.stat(path.join(currentDir, file));
|
||||
let filesInDir = [];
|
||||
if (stat.isDirectory()) {
|
||||
filesInDir = await readdirAsync(path.join(currentDir, file));
|
||||
filesInDir = await fs.promises.readdir(path.join(currentDir, file));
|
||||
}
|
||||
const url = nconf.get('upload_url') + currentDir.replace(nconf.get('upload_path'), '') + '/' + file;
|
||||
return {
|
||||
|
||||
@@ -9,10 +9,6 @@ const htmlToText = require('html-to-text');
|
||||
const url = require('url');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
|
||||
const _ = require('lodash');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
@@ -47,7 +43,7 @@ Emailer.getTemplates = async function (config) {
|
||||
|
||||
const templates = await Promise.all(emails.map(async (email) => {
|
||||
const path = email.replace(emailsPath, '').substr(1).replace('.tpl', '');
|
||||
const original = await readFileAsync(email, 'utf8');
|
||||
const original = await fs.promises.readFile(email, 'utf8');
|
||||
|
||||
return {
|
||||
path: path,
|
||||
@@ -316,7 +312,7 @@ async function buildCustomTemplates(config) {
|
||||
const compiled = await Benchpress.precompile(source, {
|
||||
minify: global.env !== 'development',
|
||||
});
|
||||
await writeFileAsync(template.fullpath.replace(/\.tpl$/, '.js'), compiled);
|
||||
await fs.promises.writeFile(template.fullpath.replace(/\.tpl$/, '.js'), compiled);
|
||||
}));
|
||||
|
||||
Benchpress.flush();
|
||||
|
||||
27
src/file.js
27
src/file.js
@@ -7,15 +7,6 @@ const winston = require('winston');
|
||||
const mkdirp = require('mkdirp');
|
||||
const mime = require('mime');
|
||||
const graceful = require('graceful-fs');
|
||||
const util = require('util');
|
||||
|
||||
const readdirAsync = util.promisify(fs.readdir);
|
||||
const copyFileAsync = util.promisify(fs.copyFile);
|
||||
const writeFleAsync = util.promisify(fs.writeFile);
|
||||
const statAsync = util.promisify(fs.stat);
|
||||
const unlinkAsync = util.promisify(fs.unlink);
|
||||
const linkAsync = util.promisify(fs.link);
|
||||
const symlinkAsync = util.promisify(fs.symlink);
|
||||
|
||||
const utils = require('./utils');
|
||||
|
||||
@@ -36,7 +27,7 @@ file.saveFileToLocal = async function (filename, folder, tempPath) {
|
||||
|
||||
winston.verbose('Saving file ' + filename + ' to : ' + uploadPath);
|
||||
await mkdirp(path.dirname(uploadPath));
|
||||
await copyFileAsync(tempPath, uploadPath);
|
||||
await fs.promises.copyFile(tempPath, uploadPath);
|
||||
return {
|
||||
url: '/assets/uploads/' + (folder ? folder + '/' : '') + filename,
|
||||
path: uploadPath,
|
||||
@@ -47,7 +38,7 @@ file.base64ToLocal = async function (imageData, uploadPath) {
|
||||
const buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
||||
uploadPath = path.join(nconf.get('upload_path'), uploadPath);
|
||||
|
||||
await writeFleAsync(uploadPath, buffer, {
|
||||
await fs.promises.writeFile(uploadPath, buffer, {
|
||||
encoding: 'base64',
|
||||
});
|
||||
return uploadPath;
|
||||
@@ -86,7 +77,7 @@ file.allowedExtensions = function () {
|
||||
|
||||
file.exists = async function (path) {
|
||||
try {
|
||||
await statAsync(path);
|
||||
await fs.promises.stat(path);
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
return false;
|
||||
@@ -114,7 +105,7 @@ file.delete = async function (path) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await unlinkAsync(path);
|
||||
await fs.promises.unlink(path);
|
||||
} catch (err) {
|
||||
winston.warn(err);
|
||||
}
|
||||
@@ -126,9 +117,9 @@ file.link = async function link(filePath, destPath, relative) {
|
||||
}
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
await linkAsync(filePath, destPath);
|
||||
await fs.promises.link(filePath, destPath);
|
||||
} else {
|
||||
await symlinkAsync(filePath, destPath, 'file');
|
||||
await fs.promises.symlink(filePath, destPath, 'file');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -138,7 +129,7 @@ file.linkDirs = async function linkDirs(sourceDir, destDir, relative) {
|
||||
}
|
||||
|
||||
const type = (process.platform === 'win32') ? 'junction' : 'dir';
|
||||
await symlinkAsync(sourceDir, destDir, type);
|
||||
await fs.promises.symlink(sourceDir, destDir, type);
|
||||
};
|
||||
|
||||
file.typeToExtension = function (type) {
|
||||
@@ -151,10 +142,10 @@ file.typeToExtension = function (type) {
|
||||
|
||||
// Adapted from http://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search
|
||||
file.walk = async function (dir) {
|
||||
const subdirs = await readdirAsync(dir);
|
||||
const subdirs = await fs.promises.readdir(dir);
|
||||
const files = await Promise.all(subdirs.map(async (subdir) => {
|
||||
const res = path.resolve(dir, subdir);
|
||||
return (await statAsync(res)).isDirectory() ? file.walk(res) : res;
|
||||
return (await fs.promises.stat(res)).isDirectory() ? file.walk(res) : res;
|
||||
}));
|
||||
return files.reduce((a, f) => a.concat(f), []);
|
||||
};
|
||||
|
||||
11
src/image.js
11
src/image.js
@@ -5,9 +5,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
const winston = require('winston');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
|
||||
const file = require('./file');
|
||||
const plugins = require('./plugins');
|
||||
@@ -46,7 +43,7 @@ image.resizeImage = async function (data) {
|
||||
});
|
||||
} else {
|
||||
const sharp = requireSharp();
|
||||
const buffer = await readFileAsync(data.path);
|
||||
const buffer = await fs.promises.readFile(data.path);
|
||||
const sharpImage = sharp(buffer, {
|
||||
failOnError: true,
|
||||
});
|
||||
@@ -93,7 +90,7 @@ image.stripEXIF = async function (path) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const buffer = await readFileAsync(path);
|
||||
const buffer = await fs.promises.readFile(path);
|
||||
const sharp = requireSharp();
|
||||
await sharp(buffer, { failOnError: true }).rotate().toFile(path);
|
||||
} catch (err) {
|
||||
@@ -111,7 +108,7 @@ image.checkDimensions = async function (path) {
|
||||
};
|
||||
|
||||
image.convertImageToBase64 = async function (path) {
|
||||
return await readFileAsync(path, 'base64');
|
||||
return await fs.promises.readFile(path, 'base64');
|
||||
};
|
||||
|
||||
image.mimeFromBase64 = function (imageData) {
|
||||
@@ -132,7 +129,7 @@ image.writeImageDataToTempFile = async function (imageData) {
|
||||
|
||||
const buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
||||
|
||||
await writeFileAsync(filepath, buffer, { encoding: 'base64' });
|
||||
await fs.promises.writeFile(filepath, buffer, { encoding: 'base64' });
|
||||
return filepath;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const Languages = module.exports;
|
||||
const languagesPath = path.join(__dirname, '../build/public/language');
|
||||
|
||||
@@ -13,7 +10,7 @@ const files = fs.readdirSync(path.join(__dirname, '../public/vendor/jquery/timea
|
||||
Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f => f.split('.')[2]);
|
||||
|
||||
Languages.get = async function (language, namespace) {
|
||||
const data = await readFileAsync(path.join(languagesPath, language, namespace + '.json'), 'utf8');
|
||||
const data = await fs.promises.readFile(path.join(languagesPath, language, namespace + '.json'), 'utf8');
|
||||
return JSON.parse(data) || {};
|
||||
};
|
||||
|
||||
@@ -23,7 +20,7 @@ Languages.listCodes = async function () {
|
||||
return codeCache;
|
||||
}
|
||||
try {
|
||||
const file = await readFileAsync(path.join(languagesPath, 'metadata.json'), 'utf8');
|
||||
const file = await fs.promises.readFile(path.join(languagesPath, 'metadata.json'), 'utf8');
|
||||
const parsed = JSON.parse(file);
|
||||
|
||||
codeCache = parsed.languages;
|
||||
@@ -47,7 +44,7 @@ Languages.list = async function () {
|
||||
let languages = await Promise.all(codes.map(async function (folder) {
|
||||
try {
|
||||
const configPath = path.join(languagesPath, folder, 'language.json');
|
||||
const file = await readFileAsync(configPath, 'utf8');
|
||||
const file = await fs.promises.readFile(configPath, 'utf8');
|
||||
const lang = JSON.parse(file);
|
||||
return lang;
|
||||
} catch (err) {
|
||||
|
||||
@@ -4,9 +4,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const mkdirp = require('mkdirp');
|
||||
const winston = require('winston');
|
||||
const util = require('util');
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const filePath = path.join(__dirname, '../../build/cache-buster');
|
||||
|
||||
@@ -19,7 +16,7 @@ function generate() {
|
||||
|
||||
exports.write = async function write() {
|
||||
await mkdirp(path.dirname(filePath));
|
||||
await writeFileAsync(filePath, generate());
|
||||
await fs.promises.writeFile(filePath, generate());
|
||||
};
|
||||
|
||||
exports.read = async function read() {
|
||||
@@ -27,7 +24,7 @@ exports.read = async function read() {
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
const buster = await readFileAsync(filePath, 'utf8');
|
||||
const buster = await fs.promises.readFile(filePath, 'utf8');
|
||||
if (!buster || buster.length !== 11) {
|
||||
winston.warn('[cache-buster] cache buster string invalid: expected /[a-z0-9]{11}/, got `' + buster + '`');
|
||||
return generate();
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const semver = require('semver');
|
||||
const winston = require('winston');
|
||||
@@ -34,7 +32,7 @@ const pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/;
|
||||
|
||||
Dependencies.checkModule = async function (moduleName) {
|
||||
try {
|
||||
let pkgData = await readFileAsync(path.join(__dirname, '../../node_modules/', moduleName, 'package.json'), 'utf8');
|
||||
let pkgData = await fs.promises.readFile(path.join(__dirname, '../../node_modules/', moduleName, 'package.json'), 'utf8');
|
||||
pkgData = Dependencies.parseModuleData(moduleName, pkgData);
|
||||
|
||||
const satisfies = Dependencies.doesSatisfy(pkgData, pkg.dependencies[moduleName]);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const nconf = require('nconf');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
@@ -7,11 +8,7 @@ const util = require('util');
|
||||
let mkdirp = require('mkdirp');
|
||||
mkdirp = mkdirp.hasOwnProperty('native') ? mkdirp : util.promisify(mkdirp);
|
||||
const rimraf = require('rimraf');
|
||||
const _ = require('lodash');
|
||||
|
||||
const rimrafAsync = util.promisify(rimraf);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const file = require('../file');
|
||||
const Plugins = require('../plugins');
|
||||
@@ -55,7 +52,7 @@ async function getTranslationMetadata() {
|
||||
languages: languages,
|
||||
namespaces: namespaces,
|
||||
};
|
||||
await writeFileAsync(path.join(buildLanguagesPath, 'metadata.json'), JSON.stringify(result));
|
||||
await fs.promises.writeFile(path.join(buildLanguagesPath, 'metadata.json'), JSON.stringify(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -64,7 +61,7 @@ async function writeLanguageFile(language, namespace, translations) {
|
||||
const filePath = path.join(buildLanguagesPath, language, namespace + '.json');
|
||||
|
||||
await mkdirp(path.dirname(filePath));
|
||||
await writeFileAsync(filePath, JSON.stringify(translations, null, dev ? 2 : 0));
|
||||
await fs.promises.writeFile(filePath, JSON.stringify(translations, null, dev ? 2 : 0));
|
||||
}
|
||||
|
||||
// for each language and namespace combination,
|
||||
@@ -124,7 +121,7 @@ async function addPlugin(translations, pluginData, lang, namespace) {
|
||||
|
||||
async function assignFileToTranslations(translations, path) {
|
||||
try {
|
||||
const fileData = await readFileAsync(path, 'utf8');
|
||||
const fileData = await fs.promises.readFile(path, 'utf8');
|
||||
Object.assign(translations, JSON.parse(fileData));
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
|
||||
@@ -2,17 +2,14 @@
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const truncateAsync = util.promisify(fs.truncate);
|
||||
const Logs = module.exports;
|
||||
|
||||
Logs.path = path.resolve(__dirname, '../../logs/output.log');
|
||||
|
||||
Logs.get = async function () {
|
||||
return await readFileAsync(Logs.path, 'utf-8');
|
||||
return await fs.promises.readFile(Logs.path, 'utf-8');
|
||||
};
|
||||
|
||||
Logs.clear = async function () {
|
||||
return await truncateAsync(Logs.path, 0);
|
||||
return await fs.promises.truncate(Logs.path, 0);
|
||||
};
|
||||
|
||||
@@ -4,13 +4,11 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
|
||||
const rimraf = require('rimraf');
|
||||
let mkdirp = require('mkdirp');
|
||||
mkdirp = mkdirp.hasOwnProperty('native') ? mkdirp : util.promisify(mkdirp);
|
||||
|
||||
const readdirAsync = util.promisify(fs.readdir);
|
||||
const rimraf = require('rimraf');
|
||||
const rimrafAsync = util.promisify(rimraf);
|
||||
const writeFileAsync = util.promisify(fs.writeFile);
|
||||
|
||||
const file = require('../file');
|
||||
const plugins = require('../plugins');
|
||||
@@ -25,7 +23,7 @@ const Sounds = module.exports;
|
||||
Sounds.addUploads = async function addUploads() {
|
||||
let files = [];
|
||||
try {
|
||||
files = await readdirAsync(uploadsPath);
|
||||
files = await fs.promises.readdir(uploadsPath);
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err;
|
||||
@@ -72,7 +70,7 @@ Sounds.build = async function build() {
|
||||
await rimrafAsync(soundsPath);
|
||||
await mkdirp(soundsPath);
|
||||
|
||||
await writeFileAsync(path.join(soundsPath, 'fileMap.json'), JSON.stringify(map));
|
||||
await fs.promises.writeFile(path.join(soundsPath, 'fileMap.json'), JSON.stringify(map));
|
||||
|
||||
await Promise.all(plugins.soundpacks.map(pack => file.linkDirs(pack.dir, path.join(soundsPath, pack.id), false)));
|
||||
};
|
||||
|
||||
@@ -7,8 +7,6 @@ const rimraf = require('rimraf');
|
||||
const winston = require('winston');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const fsReadFile = util.promisify(fs.readFile);
|
||||
const fsWriteFile = util.promisify(fs.writeFile);
|
||||
|
||||
const nconf = require('nconf');
|
||||
const _ = require('lodash');
|
||||
@@ -33,7 +31,7 @@ async function processImports(paths, templatePath, source) {
|
||||
|
||||
var partial = matches[1];
|
||||
if (paths[partial] && templatePath !== partial) {
|
||||
const partialSource = await fsReadFile(paths[partial], 'utf8');
|
||||
const partialSource = await fs.promises.readFile(paths[partial], 'utf8');
|
||||
source = source.replace(regex, partialSource);
|
||||
return await processImports(paths, templatePath, source);
|
||||
}
|
||||
@@ -117,7 +115,7 @@ async function compileTemplate(filename, source) {
|
||||
const compiled = await Benchpress.precompile(source, {
|
||||
minify: process.env.NODE_ENV !== 'development',
|
||||
});
|
||||
return await fsWriteFile(path.join(viewsPath, filename.replace(/\.tpl$/, '.js')), compiled);
|
||||
return await fs.promises.writeFile(path.join(viewsPath, filename.replace(/\.tpl$/, '.js')), compiled);
|
||||
}
|
||||
Templates.compileTemplate = compileTemplate;
|
||||
|
||||
@@ -133,14 +131,14 @@ async function compile() {
|
||||
|
||||
await Promise.all(Object.keys(files).map(async (name) => {
|
||||
const filePath = files[name];
|
||||
let imported = await fsReadFile(filePath, 'utf8');
|
||||
let imported = await fs.promises.readFile(filePath, 'utf8');
|
||||
imported = await processImports(files, name, imported);
|
||||
|
||||
await mkdirp(path.join(viewsPath, path.dirname(name)));
|
||||
|
||||
await fsWriteFile(path.join(viewsPath, name), imported);
|
||||
await fs.promises.writeFile(path.join(viewsPath, name), imported);
|
||||
const compiled = await Benchpress.precompile(imported, { minify: process.env.NODE_ENV !== 'development' });
|
||||
await fsWriteFile(path.join(viewsPath, name.replace(/\.tpl$/, '.js')), compiled);
|
||||
await fs.promises.writeFile(path.join(viewsPath, name.replace(/\.tpl$/, '.js')), compiled);
|
||||
}));
|
||||
|
||||
winston.verbose('[meta/templates] Successfully compiled templates.');
|
||||
|
||||
@@ -4,13 +4,7 @@ const path = require('path');
|
||||
const nconf = require('nconf');
|
||||
const winston = require('winston');
|
||||
const _ = require('lodash');
|
||||
|
||||
const util = require('util');
|
||||
const fs = require('fs');
|
||||
const fsReaddir = util.promisify(fs.readdir);
|
||||
const fsStat = util.promisify(fs.stat);
|
||||
const fsReadfile = util.promisify(fs.readFile);
|
||||
|
||||
|
||||
const file = require('../file');
|
||||
const db = require('../database');
|
||||
@@ -33,7 +27,7 @@ Themes.get = async () => {
|
||||
themes = await Promise.all(themes.map(async (theme) => {
|
||||
const config = path.join(themePath, theme, 'theme.json');
|
||||
try {
|
||||
const file = await fsReadfile(config, 'utf8');
|
||||
const file = await fs.promises.readFile(config, 'utf8');
|
||||
const configObj = JSON.parse(file);
|
||||
|
||||
// Minor adjustments for API output
|
||||
@@ -59,12 +53,12 @@ Themes.get = async () => {
|
||||
};
|
||||
|
||||
async function getThemes(themePath) {
|
||||
let dirs = await fsReaddir(themePath);
|
||||
let dirs = await fs.promises.readdir(themePath);
|
||||
dirs = dirs.filter(dir => themeNamePattern.test(dir) || dir.startsWith('@'));
|
||||
return await Promise.all(dirs.map(async (dir) => {
|
||||
try {
|
||||
const dirpath = path.join(themePath, dir);
|
||||
const stat = await fsStat(dirpath);
|
||||
const stat = await fs.promises.stat(dirpath);
|
||||
if (!stat.isDirectory()) {
|
||||
return false;
|
||||
}
|
||||
@@ -95,7 +89,7 @@ Themes.set = async (data) => {
|
||||
throw new Error('[[error:invalid-theme-id]]');
|
||||
}
|
||||
|
||||
let config = await fsReadfile(pathToThemeJson, 'utf8');
|
||||
let config = await fs.promises.readFile(pathToThemeJson, 'utf8');
|
||||
config = JSON.parse(config);
|
||||
|
||||
await db.sortedSetRemove('plugins:active', current);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const path = require('path');
|
||||
const winston = require('winston');
|
||||
|
||||
@@ -12,9 +11,6 @@ const Data = module.exports;
|
||||
|
||||
const basePath = path.join(__dirname, '../../');
|
||||
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
const statAsync = util.promisify(fs.stat);
|
||||
|
||||
Data.getPluginPaths = async function () {
|
||||
let plugins = await db.getSortedSetRange('plugins:active', 0, -1);
|
||||
plugins = plugins.filter(plugin => plugin && typeof plugin === 'string')
|
||||
@@ -26,8 +22,8 @@ Data.getPluginPaths = async function () {
|
||||
|
||||
Data.loadPluginInfo = async function (pluginPath) {
|
||||
const [packageJson, pluginJson] = await Promise.all([
|
||||
readFileAsync(path.join(pluginPath, 'package.json'), 'utf8'),
|
||||
readFileAsync(path.join(pluginPath, 'plugin.json'), 'utf8'),
|
||||
fs.promises.readFile(path.join(pluginPath, 'package.json'), 'utf8'),
|
||||
fs.promises.readFile(path.join(pluginPath, 'plugin.json'), 'utf8'),
|
||||
]);
|
||||
|
||||
let pluginData;
|
||||
@@ -96,7 +92,7 @@ Data.getStaticDirectories = async function (pluginData) {
|
||||
|
||||
const dirPath = path.join(pluginData.path, pluginData.staticDirs[route]);
|
||||
try {
|
||||
const stats = await statAsync(dirPath);
|
||||
const stats = await fs.promises.stat(dirPath);
|
||||
if (!stats.isDirectory()) {
|
||||
winston.warn('[plugins/' + pluginData.id + '] Mapped path \'' +
|
||||
route + ' => ' + dirPath + '\' is not a directory.');
|
||||
|
||||
@@ -11,8 +11,6 @@ const util = require('util');
|
||||
const user = require('../user');
|
||||
const posts = require('../posts');
|
||||
|
||||
const readdirAsync = util.promisify(fs.readdir);
|
||||
|
||||
var app;
|
||||
var middleware;
|
||||
|
||||
@@ -253,7 +251,7 @@ Plugins.normalise = async function (apiReturn) {
|
||||
Plugins.nodeModulesPath = path.join(__dirname, '../../node_modules');
|
||||
|
||||
Plugins.showInstalled = async function () {
|
||||
const dirs = await readdirAsync(Plugins.nodeModulesPath);
|
||||
const dirs = await fs.promises.readdir(Plugins.nodeModulesPath);
|
||||
|
||||
let pluginPaths = await findNodeBBModules(dirs);
|
||||
pluginPaths = pluginPaths.map(dir => path.join(Plugins.nodeModulesPath, dir));
|
||||
|
||||
@@ -12,8 +12,6 @@ const db = require('../database');
|
||||
const meta = require('../meta');
|
||||
const pubsub = require('../pubsub');
|
||||
|
||||
const statAsync = util.promisify(fs.stat);
|
||||
|
||||
const supportedPackageManagerList = require('../cli/package-install').supportedPackageManager; // load config from src/cli/package-install.js
|
||||
const packageManager = supportedPackageManagerList.indexOf(nconf.get('package_manager')) >= 0 ? nconf.get('package_manager') : 'npm';
|
||||
let packageManagerExecutable = packageManager;
|
||||
@@ -121,7 +119,7 @@ module.exports = function (Plugins) {
|
||||
Plugins.isInstalled = async function (id) {
|
||||
const pluginDir = path.join(__dirname, '../../node_modules', id);
|
||||
try {
|
||||
const stats = await statAsync(pluginDir);
|
||||
const stats = await fs.promises.stat(pluginDir);
|
||||
return stats.isDirectory();
|
||||
} catch (err) {
|
||||
return false;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const util = require('util');
|
||||
const readFileAsync = util.promisify(fs.readFile);
|
||||
|
||||
const path = require('path');
|
||||
const nconf = require('nconf');
|
||||
@@ -68,7 +66,7 @@ async function renderAdminTemplate() {
|
||||
}
|
||||
|
||||
async function getSource() {
|
||||
return await readFileAsync(path.resolve(nconf.get('views_dir'), 'admin/partials/widget-settings.tpl'), 'utf8');
|
||||
return await fs.promises.readFile(path.resolve(nconf.get('views_dir'), 'admin/partials/widget-settings.tpl'), 'utf8');
|
||||
}
|
||||
|
||||
function buildTemplatesFromAreas(areas) {
|
||||
|
||||
Reference in New Issue
Block a user