From efdcaae5269450ef49fdd6efb6fce9cc5fee2a6f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 9 Jan 2021 02:44:59 -0500 Subject: [PATCH] bin scripts: Promisify npm.load --- bin/checkAllPads.js | 11 +++++++---- bin/checkPad.js | 11 +++++++---- bin/checkPadDeltas.js | 8 +++++--- bin/extractPadData.js | 8 ++++---- bin/importSqlFile.js | 9 ++++++--- bin/migrateDirtyDBtoRealDB.js | 7 +++++-- bin/repairPad.js | 8 +++++--- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/bin/checkAllPads.js b/bin/checkAllPads.js index 063da96a5..3e2ea8407 100644 --- a/bin/checkAllPads.js +++ b/bin/checkAllPads.js @@ -7,11 +7,14 @@ // unhandled rejection into an uncaught exception, which does cause Node.js to exit. process.on('unhandledRejection', (err) => { throw err; }); +const npm = require('ep_etherpad-lite/node_modules/npm'); +const util = require('util'); + if (process.argv.length !== 2) throw new Error('Use: node bin/checkAllPads.js'); -// load and initialize NPM -const npm = require('ep_etherpad-lite/node_modules/npm'); -npm.load({}, async () => { +(async () => { + await util.promisify(npm.load)({}); + try { // initialize the database require('ep_etherpad-lite/node/utils/Settings'); @@ -92,4 +95,4 @@ npm.load({}, async () => { console.trace(err); throw err; } -}); +})(); diff --git a/bin/checkPad.js b/bin/checkPad.js index 42e5946c1..56464648b 100644 --- a/bin/checkPad.js +++ b/bin/checkPad.js @@ -7,15 +7,18 @@ // unhandled rejection into an uncaught exception, which does cause Node.js to exit. process.on('unhandledRejection', (err) => { throw err; }); +const npm = require('ep_etherpad-lite/node_modules/npm'); +const util = require('util'); + if (process.argv.length !== 3) throw new Error('Use: node bin/checkPad.js $PADID'); // get the padID const padId = process.argv[2]; let checkRevisionCount = 0; -// load and initialize NPM; -const npm = require('ep_etherpad-lite/node_modules/npm'); -npm.load({}, async () => { +(async () => { + await util.promisify(npm.load)({}); + try { // initialize database require('ep_etherpad-lite/node/utils/Settings'); @@ -86,4 +89,4 @@ npm.load({}, async () => { console.trace(err); throw err; } -}); +})(); diff --git a/bin/checkPadDeltas.js b/bin/checkPadDeltas.js index 19d4ba4db..45ee27d72 100644 --- a/bin/checkPadDeltas.js +++ b/bin/checkPadDeltas.js @@ -12,12 +12,14 @@ if (process.argv.length !== 3) throw new Error('Use: node bin/checkPadDeltas.js // get the padID const padId = process.argv[2]; -// load and initialize NPM; const expect = require('../tests/frontend/lib/expect'); const diff = require('ep_etherpad-lite/node_modules/diff'); const npm = require('ep_etherpad-lite/node_modules/npm'); +const util = require('util'); + +(async () => { + await util.promisify(npm.load)({}); -npm.load({}, async () => { // initialize database require('ep_etherpad-lite/node/utils/Settings'); const db = require('ep_etherpad-lite/node/db/DB'); @@ -102,4 +104,4 @@ npm.load({}, async () => { } })); } -}); +})(); diff --git a/bin/extractPadData.js b/bin/extractPadData.js index 3b182a571..58fe50a42 100644 --- a/bin/extractPadData.js +++ b/bin/extractPadData.js @@ -16,9 +16,10 @@ if (process.argv.length !== 3) throw new Error('Use: node extractPadData.js $PAD const padId = process.argv[2]; const npm = require('ep_etherpad-lite/node_modules/npm'); +const util = require('util'); -npm.load({}, async (err) => { - if (err) throw err; +(async () => { + await util.promisify(npm.load)({}); try { // initialize database @@ -29,7 +30,6 @@ npm.load({}, async (err) => { // load extra modules const dirtyDB = require('ep_etherpad-lite/node_modules/dirty'); const padManager = require('ep_etherpad-lite/node/db/PadManager'); - const util = require('util'); // initialize output database const dirty = dirtyDB(`${padId}.db`); @@ -71,4 +71,4 @@ npm.load({}, async (err) => { console.error(err); throw err; } -}); +})(); diff --git a/bin/importSqlFile.js b/bin/importSqlFile.js index 35fe4f323..b02e9e10c 100644 --- a/bin/importSqlFile.js +++ b/bin/importSqlFile.js @@ -4,6 +4,9 @@ // unhandled rejection into an uncaught exception, which does cause Node.js to exit. process.on('unhandledRejection', (err) => { throw err; }); +const npm = require('ep_etherpad-lite/node_modules/npm'); +const util = require('util'); + const startTime = Date.now(); const log = (str) => { @@ -43,10 +46,10 @@ const unescape = (val) => { return val; }; +(async () => { + await util.promisify(npm.load)({}); -require('ep_etherpad-lite/node_modules/npm').load({}, (er, npm) => { const fs = require('fs'); - const ueberDB = require('ep_etherpad-lite/node_modules/ueberdb2'); const settings = require('ep_etherpad-lite/node/utils/Settings'); const log4js = require('ep_etherpad-lite/node_modules/log4js'); @@ -106,4 +109,4 @@ require('ep_etherpad-lite/node_modules/npm').load({}, (er, npm) => { }); } }); -}); +})(); diff --git a/bin/migrateDirtyDBtoRealDB.js b/bin/migrateDirtyDBtoRealDB.js index 48760b8ba..c79d9b747 100644 --- a/bin/migrateDirtyDBtoRealDB.js +++ b/bin/migrateDirtyDBtoRealDB.js @@ -4,9 +4,12 @@ // unhandled rejection into an uncaught exception, which does cause Node.js to exit. process.on('unhandledRejection', (err) => { throw err; }); +const npm = require('ep_etherpad-lite/node_modules/npm'); const util = require('util'); -require('ep_etherpad-lite/node_modules/npm').load({}, async (er, npm) => { +(async () => { + await util.promisify(npm.load)({}); + process.chdir(`${npm.root}/..`); // This script requires that you have modified your settings.json file @@ -56,4 +59,4 @@ require('ep_etherpad-lite/node_modules/npm').load({}, async (er, npm) => { await util.promisify(db.close.bind(db))(); console.log('Finished.'); -}); +})(); diff --git a/bin/repairPad.js b/bin/repairPad.js index e083f30b9..ff2da9776 100644 --- a/bin/repairPad.js +++ b/bin/repairPad.js @@ -18,8 +18,10 @@ const padId = process.argv[2]; let valueCount = 0; const npm = require('ep_etherpad-lite/node_modules/npm'); -npm.load({}, async (err) => { - if (err) throw err; +const util = require('util'); + +(async () => { + await util.promisify(npm.load)({}); // intialize database require('ep_etherpad-lite/node/utils/Settings'); @@ -56,4 +58,4 @@ npm.load({}, async (err) => { } console.info(`Finished: Replaced ${valueCount} values in the database`); -}); +})();