Skip to content

Commit

Permalink
Convert exportimport files to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
bubonicfred committed Jun 18, 2024
1 parent c094627 commit bd42340
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
12 changes: 6 additions & 6 deletions imports/server/exportimport/expImpFilesAttachments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpFilesAttachments {
static get FILENAME_POSTFIX() {
Expand All @@ -14,7 +14,7 @@ class ExpImpFilesAttachments {
.then((doc) => {
if (doc) {
const attFile = msID + ExpImpFilesAttachments.FILENAME_POSTFIX;
fs.writeFileSync(attFile, EJSON.stringify(doc, null, 2));
writeFileSync(attFile, stringify(doc, null, 2));
console.log(
`Saved: ${attFile} with ${doc.length} file attachments`,
);
Expand All @@ -37,8 +37,8 @@ class ExpImpFilesAttachments {
const attachmentFile = msID + ExpImpFilesAttachments.FILENAME_POSTFIX;
let AllAttachmentsDoc = undefined;
try {
AllAttachmentsDoc = EJSON.parse(
fs.readFileSync(attachmentFile, "utf8"),
AllAttachmentsDoc = parse(
readFileSync(attachmentFile, "utf8"),
);
if (!AllAttachmentsDoc) {
return reject(`Could not read attachment file ${attachmentFile}`);
Expand Down Expand Up @@ -94,4 +94,4 @@ class ExpImpFilesAttachments {
}
}

module.exports = ExpImpFilesAttachments;
export default ExpImpFilesAttachments;
10 changes: 5 additions & 5 deletions imports/server/exportimport/expImpFilesDocuments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpFilesDocuments {
static get FILENAME_POSTFIX() {
Expand All @@ -14,7 +14,7 @@ class ExpImpFilesDocuments {
.then((doc) => {
if (doc) {
const protFile = msID + ExpImpFilesDocuments.FILENAME_POSTFIX;
fs.writeFileSync(protFile, EJSON.stringify(doc, null, 2));
writeFileSync(protFile, stringify(doc, null, 2));
console.log(
`Saved: ${protFile} with ${doc.length} protocol documents`,
);
Expand Down Expand Up @@ -42,7 +42,7 @@ class ExpImpFilesDocuments {
const protFile = msID + ExpImpFilesDocuments.FILENAME_POSTFIX;
let AllProtocolsDoc = undefined;
try {
AllProtocolsDoc = EJSON.parse(fs.readFileSync(protFile, "utf8"));
AllProtocolsDoc = parse(readFileSync(protFile, "utf8"));
if (!AllProtocolsDoc) {
return reject(`Could not read documents file ${protFile}`);
}
Expand Down Expand Up @@ -97,4 +97,4 @@ class ExpImpFilesDocuments {
}
}

module.exports = ExpImpFilesDocuments;
export default ExpImpFilesDocuments;
10 changes: 5 additions & 5 deletions imports/server/exportimport/expImpMeetingseries.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpMeetingSeries {
static get FILENAME_POSTFIX() {
Expand All @@ -14,7 +14,7 @@ class ExpImpMeetingSeries {
.then((doc) => {
if (doc) {
const msFile = msID + ExpImpMeetingSeries.FILENAME_POSTFIX;
fs.writeFileSync(msFile, EJSON.stringify(doc, null, 2));
writeFileSync(msFile, stringify(doc, null, 2));
console.log(`Saved: ${msFile}`);
doc.visibleFor?.map((userID) => {
userIDs[userID] = 1;
Expand Down Expand Up @@ -43,7 +43,7 @@ class ExpImpMeetingSeries {
const msFile = msID + ExpImpMeetingSeries.FILENAME_POSTFIX;
let msDoc = undefined;
try {
msDoc = EJSON.parse(fs.readFileSync(msFile, "utf8"));
msDoc = parse(readFileSync(msFile, "utf8"));
if (!msDoc) {
return reject(`Could not read meeting series file ${msFile}`);
}
Expand Down Expand Up @@ -75,4 +75,4 @@ class ExpImpMeetingSeries {
}
}

module.exports = ExpImpMeetingSeries;
export default ExpImpMeetingSeries;
14 changes: 7 additions & 7 deletions imports/server/exportimport/expImpMinutes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const EJSON = require("bson");
const ExpImpTopics = require("./expImpTopics");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";
import { patchUsers as _patchUsers } from "./expImpTopics";

class ExpImpMinutes {
static get FILENAME_POSTFIX() {
Expand All @@ -25,7 +25,7 @@ class ExpImpMinutes {
.then((allMinutesDoc) => {
if (allMinutesDoc) {
const minFile = msID + ExpImpMinutes.FILENAME_POSTFIX;
fs.writeFileSync(minFile, EJSON.stringify(allMinutesDoc, null, 2));
writeFileSync(minFile, stringify(allMinutesDoc, null, 2));
console.log(
`Saved: ${minFile} with ${allMinutesDoc.length} minutes`,
);
Expand Down Expand Up @@ -72,7 +72,7 @@ class ExpImpMinutes {
const minFile = msID + ExpImpMinutes.FILENAME_POSTFIX;
let minDoc = undefined;
try {
minDoc = EJSON.parse(fs.readFileSync(minFile, "utf8"));
minDoc = parse(readFileSync(minFile, "utf8"));
if (!minDoc) {
return reject(new Error(`Could not read minutes file ${minFile}`));
}
Expand Down Expand Up @@ -137,12 +137,12 @@ class ExpImpMinutes {

// iterate topics
for (let t = 0; element.topics && t < element.topics.length; t++) {
element.topics[t] = ExpImpTopics.patchUsers(element.topics[t], usrMap);
element.topics[t] = _patchUsers(element.topics[t], usrMap);
}
}

return { minIDs, minDoc };
}
}

module.exports = ExpImpMinutes;
export default ExpImpMinutes;
10 changes: 5 additions & 5 deletions imports/server/exportimport/expImpSchema.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpSchema {
static get MADE_FOR_SCHEMA() {
Expand Down Expand Up @@ -34,7 +34,7 @@ class ExpImpSchema {
);
}
const schemaFile = msID + ExpImpSchema.FILENAME_POSTFIX;
fs.writeFileSync(schemaFile, EJSON.stringify(doc, null, 2));
writeFileSync(schemaFile, stringify(doc, null, 2));
console.log(`Saved: ${schemaFile}`);
resolve(db);
return;
Expand All @@ -57,7 +57,7 @@ class ExpImpSchema {
const schemaFile = msID + ExpImpSchema.FILENAME_POSTFIX;
let exportedSchema = undefined;
try {
exportedSchema = EJSON.parse(fs.readFileSync(schemaFile, "utf8"));
exportedSchema = parse(readFileSync(schemaFile, "utf8"));
if (!exportedSchema) {
return reject(`Could not read schema file ${schemaFile}`);
}
Expand Down Expand Up @@ -107,4 +107,4 @@ class ExpImpSchema {
}
}

module.exports = ExpImpSchema;
export default ExpImpSchema;
10 changes: 5 additions & 5 deletions imports/server/exportimport/expImpTopics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpTopics {
static get FILENAME_POSTFIX() {
Expand All @@ -14,7 +14,7 @@ class ExpImpTopics {
.then((doc) => {
if (doc) {
const topFile = msID + ExpImpTopics.FILENAME_POSTFIX;
fs.writeFileSync(topFile, EJSON.stringify(doc, null, 2));
writeFileSync(topFile, stringify(doc, null, 2));
console.log(`Saved: ${topFile} with ${doc.length} topics`);
resolve({ db, userIDs });
return;
Expand All @@ -29,7 +29,7 @@ class ExpImpTopics {
const topFile = msID + ExpImpTopics.FILENAME_POSTFIX;
let AllTopicsDoc = undefined;
try {
AllTopicsDoc = EJSON.parse(fs.readFileSync(topFile, "utf8"));
AllTopicsDoc = parse(readFileSync(topFile, "utf8"));
if (!AllTopicsDoc) {
return reject(`Could not read topic file ${topFile}`);
}
Expand Down Expand Up @@ -97,4 +97,4 @@ class ExpImpTopics {
}
}

module.exports = ExpImpTopics;
export default ExpImpTopics;
14 changes: 7 additions & 7 deletions imports/server/exportimport/expImpUsers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const EJSON = require("bson");
import { writeFileSync, readFileSync } from "fs";
import { stringify, parse } from "bson";

class ExpImpUsers {
static get FILENAME_POSTFIX() {
Expand Down Expand Up @@ -36,7 +36,7 @@ class ExpImpUsers {
userIDsFromDB[usr._id] = 1;
});
const usrFile = msID + ExpImpUsers.FILENAME_POSTFIX;
fs.writeFileSync(usrFile, EJSON.stringify(allUsersDoc, null, 2));
writeFileSync(usrFile, stringify(allUsersDoc, null, 2));
console.log(`Saved: ${usrFile} with ${allUsersDoc.length} users`);

// Save mapping file old => new user ID
Expand All @@ -55,7 +55,7 @@ class ExpImpUsers {
}
});
const mapFile = msID + ExpImpUsers.MAPNAME_POSTFIX;
fs.writeFileSync(mapFile, JSON.stringify(userIDsOuputMap, null, 2));
writeFileSync(mapFile, JSON.stringify(userIDsOuputMap, null, 2));
console.log(`Saved: ${mapFile}`);
console.log(
" *** IMPORTANT!!! EDIT USER MAP FILE BEFORE IMPORT!!!",
Expand All @@ -74,7 +74,7 @@ class ExpImpUsers {
const mapFile = msID + ExpImpUsers.MAPNAME_POSTFIX;
let usrMap = undefined;
try {
usrMap = JSON.parse(fs.readFileSync(mapFile, "utf8"));
usrMap = JSON.parse(readFileSync(mapFile, "utf8"));
if (!usrMap) {
return reject(`Could not read user map file ${mapFile}`);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ class ExpImpUsers {
const usrFile = msID + ExpImpUsers.FILENAME_POSTFIX;
let allUsersDoc = undefined;
try {
allUsersDoc = EJSON.parse(fs.readFileSync(usrFile, "utf8"));
allUsersDoc = parse(readFileSync(usrFile, "utf8"));
if (!allUsersDoc) {
return reject(`Could not read user file ${usrFile}`);
}
Expand Down Expand Up @@ -205,4 +205,4 @@ class ExpImpUsers {
}
}

module.exports = ExpImpUsers;
export default ExpImpUsers;

0 comments on commit bd42340

Please sign in to comment.