bin scripts: Promisify npm.load

This commit is contained in:
Richard Hansen 2021-01-09 02:44:59 -05:00 committed by John McLear
parent 92cd2cc760
commit efdcaae526
7 changed files with 39 additions and 23 deletions

View File

@ -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;
}
});
})();

View File

@ -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;
}
});
})();

View File

@ -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 () => {
}
}));
}
});
})();

View File

@ -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;
}
});
})();

View File

@ -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) => {
});
}
});
});
})();

View File

@ -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.');
});
})();

View File

@ -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`);
});
})();