From 88862f0246db33bcd86711cf11b4679de40d22be Mon Sep 17 00:00:00 2001 From: SamTV12345 <40429738+samtv12345@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:23:10 +0200 Subject: [PATCH] Fixed bin scripts. --- bin/checkAllPads.ts | 1 + bin/createUserSession.ts | 2 ++ bin/deleteAllGroupSessions.ts | 1 + bin/deletePad.ts | 1 + bin/extractPadData.ts | 1 + bin/importSqlFile.ts | 7 +++++-- bin/migrateDirtyDBtoRealDB.ts | 7 ++++--- bin/plugins/checkPlugin.ts | 2 +- bin/plugins/stalePlugins.ts | 2 ++ bin/rebuildPad.ts | 3 +++ bin/repairPad.ts | 1 + 11 files changed, 22 insertions(+), 6 deletions(-) diff --git a/bin/checkAllPads.ts b/bin/checkAllPads.ts index a967413d1..305afabab 100644 --- a/bin/checkAllPads.ts +++ b/bin/checkAllPads.ts @@ -25,4 +25,5 @@ if (process.argv.length !== 2) throw new Error('Use: node bin/checkAllPads.js'); console.log(`Pad ${padId}: OK`); })); console.log('Finished.'); + process.exit(0) })(); diff --git a/bin/createUserSession.ts b/bin/createUserSession.ts index 1dbab0d69..165cf287a 100644 --- a/bin/createUserSession.ts +++ b/bin/createUserSession.ts @@ -14,6 +14,7 @@ import path from "node:path"; import querystring from "node:querystring"; import axios from 'axios' +import process from "node:process"; process.on('unhandledRejection', (err) => { throw err; }); @@ -53,4 +54,5 @@ const settings = require('ep_etherpad-lite/node/utils/Settings'); if (res.data.code === 1) throw new Error(`Error creating session: ${JSON.stringify(res.data)}`); console.log('Session made: ====> create a cookie named sessionID and set the value to', res.data.data.sessionID); + process.exit(0) })(); diff --git a/bin/deleteAllGroupSessions.ts b/bin/deleteAllGroupSessions.ts index 23d21c594..6064757ec 100644 --- a/bin/deleteAllGroupSessions.ts +++ b/bin/deleteAllGroupSessions.ts @@ -49,4 +49,5 @@ const settings = require('ep_etherpad-lite/tests/container/loadSettings').loadSe } } console.log(`Deleted ${deleteCount} sessions`); + process.exit(0) })(); diff --git a/bin/deletePad.ts b/bin/deletePad.ts index 20037bb33..2f6009158 100644 --- a/bin/deletePad.ts +++ b/bin/deletePad.ts @@ -38,4 +38,5 @@ const apikey = fs.readFileSync(filePath, {encoding: 'utf-8'}); const deleteAttempt = await axios.post(uri); if (deleteAttempt.data.code === 1) throw new Error(`Error deleting pad ${deleteAttempt.data}`); console.log('Deleted pad', deleteAttempt.data); + process.exit(0) })(); diff --git a/bin/extractPadData.ts b/bin/extractPadData.ts index 3c10a3acc..466b31b89 100644 --- a/bin/extractPadData.ts +++ b/bin/extractPadData.ts @@ -60,4 +60,5 @@ const padId = process.argv[2]; } console.log('finished'); + process.exit(0) })(); diff --git a/bin/importSqlFile.ts b/bin/importSqlFile.ts index 23ad9b7d1..7660fa407 100644 --- a/bin/importSqlFile.ts +++ b/bin/importSqlFile.ts @@ -6,7 +6,8 @@ import util from "node:util"; const fs = require('fs'); import log4js from 'log4js'; import readline from 'readline'; -import ueberDB from "ueberdb2"; +import {Database} from "ueberdb2"; +import process from "node:process"; const settings = require('ep_etherpad-lite/node/utils/Settings'); process.on('unhandledRejection', (err) => { throw err; }); @@ -56,7 +57,7 @@ const unescape = (val: string) => { writeInterval: 100, json: false, // data is already json encoded }; - const db = new ueberDB.Database( // eslint-disable-line new-cap + const db = new Database( // eslint-disable-line new-cap settings.dbType, settings.dbSettings, dbWrapperSettings, @@ -96,6 +97,8 @@ const unescape = (val: string) => { 'depended on dbms this may take some time..\n'); const closeDB = util.promisify(db.close.bind(db)); + // @ts-ignore await closeDB(null); log(`finished, imported ${keyNo} keys.`); + process.exit(0) })(); diff --git a/bin/migrateDirtyDBtoRealDB.ts b/bin/migrateDirtyDBtoRealDB.ts index 144f6e88c..3cd32a85a 100644 --- a/bin/migrateDirtyDBtoRealDB.ts +++ b/bin/migrateDirtyDBtoRealDB.ts @@ -1,7 +1,7 @@ 'use strict'; import process from 'node:process'; -import ueberDB from "ueberdb2"; +import {Database} from "ueberdb2"; import log4js from 'log4js'; import util from 'util'; const settings = require('ep_etherpad-lite/node/utils/Settings'); @@ -23,7 +23,7 @@ process.on('unhandledRejection', (err) => { throw err; }); cache: '0', // The cache slows things down when you're mostly writing. writeInterval: 0, // Write directly to the database, don't buffer }; - const db = new ueberDB.Database( // eslint-disable-line new-cap + const db = new Database( // eslint-disable-line new-cap settings.dbType, settings.dbSettings, dbWrapperSettings, @@ -31,7 +31,7 @@ process.on('unhandledRejection', (err) => { throw err; }); await db.init(); console.log('Waiting for dirtyDB to parse its file.'); - const dirty = await new ueberDB.Database('dirty',`${__dirname}/../var/dirty.db`); + const dirty = new Database('dirty', `${__dirname}/../var/dirty.db`); await dirty.init(); const keys = await dirty.findKeys('*', '') @@ -57,4 +57,5 @@ process.on('unhandledRejection', (err) => { throw err; }); await db.close(null); await dirty.close(null); console.log('Finished.'); + process.exit(0) })(); diff --git a/bin/plugins/checkPlugin.ts b/bin/plugins/checkPlugin.ts index cdd78d791..e2ca59d5e 100644 --- a/bin/plugins/checkPlugin.ts +++ b/bin/plugins/checkPlugin.ts @@ -474,6 +474,6 @@ log4js.configure({ logger.info('No changes.'); } } - logger.info('Finished'); + process.exit(0) })(); diff --git a/bin/plugins/stalePlugins.ts b/bin/plugins/stalePlugins.ts index ce2b876ed..563bf51d1 100644 --- a/bin/plugins/stalePlugins.ts +++ b/bin/plugins/stalePlugins.ts @@ -3,6 +3,7 @@ // Returns a list of stale plugins and their authors email import axios from 'axios' +import process from "node:process"; const currentTime = new Date(); (async () => { @@ -19,4 +20,5 @@ const currentTime = new Date(); console.log(`${name}, ${res.data[plugin].data.maintainers[0].email}`); } } + process.exit(0) })(); diff --git a/bin/rebuildPad.ts b/bin/rebuildPad.ts index 0d77940c0..8bb63ed84 100644 --- a/bin/rebuildPad.ts +++ b/bin/rebuildPad.ts @@ -7,6 +7,8 @@ // As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an // unhandled rejection into an uncaught exception, which does cause Node.js to exit. +import process from "node:process"; + process.on('unhandledRejection', (err) => { throw err; }); if (process.argv.length !== 4 && process.argv.length !== 5) { @@ -82,4 +84,5 @@ const newPadId = process.argv[4] || `${padId}-rebuilt`; await db.shutdown(); console.info('finished'); + process.exit(0) })(); diff --git a/bin/repairPad.ts b/bin/repairPad.ts index 848b7205f..f59cf347e 100644 --- a/bin/repairPad.ts +++ b/bin/repairPad.ts @@ -57,4 +57,5 @@ let valueCount = 0; } console.info(`Finished: Replaced ${valueCount} values in the database`); + process.exit(0) })();