diff --git a/cdbscreens.js b/cdbscreens.js index e7133bc..6340aae 100644 --- a/cdbscreens.js +++ b/cdbscreens.js @@ -1,6 +1,6 @@ 'use strict'; -const fs = require('fs'); +const fsx = require('fs-extra'); const crypto = require('crypto'); const config = require('./config'); const mylog = require('./mylog'); @@ -8,18 +8,15 @@ const cdbfetch = require('./cdbfetch'); async function cdbscreens() { let screens = config.screenshots; - const loading = []; - screens = screens + screens = await Promise.all(screens .map(x => (typeof x === 'string' || x instanceof String) ? { name: x } : x) - .map(x => { + .map(async x => { if(x.data) x.data = Buffer.from(x.data); else - loading.push(new Promise((r, j) => fs.readFile(x.name, - (e, d) => e ? j(e) : r(x.data = d)))); + x.data = await fsx.readFile(x.name); return x; - }); - await Promise.all(loading); + })); screens.forEach(x => x.hash = crypto.createHash('sha256') .update(x.data) .digest('base64') diff --git a/gitlua.js b/gitlua.js index 5428287..f9e88ef 100644 --- a/gitlua.js +++ b/gitlua.js @@ -1,13 +1,10 @@ 'use strict'; -const fs = require('fs'); -const util = require('util'); +const fsx = require('fs-extra'); const config = require('./config'); const mylog = require('./mylog'); const spawn = require('./spawn'); -const readFile = util.promisify(fs.readFile); - function luaser(obj) { if(Array.isArray(obj)) return `{${obj.map(luaser).join(',')}}`; @@ -30,7 +27,7 @@ function luaser(obj) { module.exports = async cwd => { const luahook = `config = ${luaser(config)}\n\n` + - (await readFile('luahook.lua')) + (await fsx.readFile('luahook.lua')) .toString(); mylog('loading lua metadata...'); diff --git a/index.js b/index.js index a3eeec2..e3783e5 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,7 @@ process.on('unhandledRejection', e => { throw e; }); -const fs = require('fs'); -const util = require('util'); +const fsx = require('fs-extra'); const path = require('path'); const config = require('./config'); const gitmirror = require('./gitmirror'); @@ -13,13 +12,12 @@ const cdbedit = require('./cdbedit'); const cdbrelease = require('./cdbrelease'); const cdbscreens = require('./cdbscreens'); -const readFile = util.promisify(fs.readFile); -const loadJsonConfig = async (fn, key, req) => { +const loadJsonConfig = async (fn, key) => { try { - const conf = await readFile(fn); + const conf = await fsx.readFile(fn); config.set(key, JSON.parse(conf.toString())); } catch (e) { - if(req) throw e; + if(e.code !== 'ENOENT') throw e; console.warn(e.message || e); } }; @@ -39,8 +37,7 @@ function missingConfig(...opts) { await gitexport(true, async full => { if(config.cdbjson) await loadJsonConfig( - path.join(full, config.cdbjsonpath), - 'gitjson', true); + path.join(full, config.cdbjsonpath), 'gitjson'); if(config.cdblua) await gitlua(full); });