Skip to content

Commit

Permalink
refactor: Convert more files to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
bubonicfred committed Jun 18, 2024
1 parent b0d4342 commit c094627
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 35 deletions.
6 changes: 3 additions & 3 deletions client/helpers/confirmationDialog.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _ } from "lodash";
import { assignIn } from "lodash";
import { Blaze } from "meteor/blaze";
import { Template } from "meteor/templating";
import { i18n } from "meteor/universe:i18n";
Expand All @@ -7,7 +7,7 @@ const DIALOG_TEMPLATE = Template.confirmationDialog;

export class ConfirmationDialog {
constructor(options, callbacks = {}) {
this.options = _.assignIn(
this.options = assignIn(
{
title: i18n.__("Dialog.ConfirmDelete.title"),
content: i18n.__("Dialog.ConfirmDelete.body"),
Expand All @@ -19,7 +19,7 @@ export class ConfirmationDialog {
},
options,
); // overwrite above defaults with given options
this.callback = _.assignIn(
this.callback = assignIn(
{
onSuccess() {},
},
Expand Down
4 changes: 2 additions & 2 deletions client/templates/topic/topicEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { configureSelect2Responsibles } from "/imports/client/ResponsibleSearch"
import { MeetingSeries } from "/imports/meetingseries";
import { Minutes } from "/imports/minutes";
import { Topic } from "/imports/topic";
import { _ } from "lodash";
import { assignIn } from "lodash";
import { $ } from "meteor/jquery";
import { Meteor } from "meteor/meteor";
import { Session } from "meteor/session";
Expand Down Expand Up @@ -66,7 +66,7 @@ Template.topicEdit.events({
const editTopic = getEditTopic();
const topicDoc = {};
if (editTopic) {
_.extend(topicDoc, editTopic._topicDoc);
assignIn(topicDoc, editTopic._topicDoc);
}

let labels = tmpl.$("#id_item_selLabels").val();
Expand Down
4 changes: 2 additions & 2 deletions client/templates/topic/topicInfoItemEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Minutes } from "/imports/minutes";
import { Priority } from "/imports/priority";
import { Topic } from "/imports/topic";
import { User, userSettings } from "/imports/user";
import { _ } from "lodash";
import { assignIn } from "lodash";
import { Meteor } from "meteor/meteor";
import { ReactiveDict } from "meteor/reactive-dict";
import { ReactiveVar } from "meteor/reactive-var";
Expand Down Expand Up @@ -214,7 +214,7 @@ Template.topicInfoItemEdit.events({

const doc = {};
if (editItem) {
_.assignIn(doc, editItem._infoItemDoc);
assignIn(doc, editItem._infoItemDoc);
}

doc.subject = newSubject;
Expand Down
4 changes: 2 additions & 2 deletions imports/attachment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _ } from "lodash";
import { assignIn } from "lodash";

import { AttachmentsCollection } from "./collections/attachments_private";
import { Minutes } from "./minutes";
Expand Down Expand Up @@ -42,7 +42,7 @@ export class Attachment {

static uploadFile(uploadFilename, minutesObj, callbacks = {}) {
const doNothing = () => {};
callbacks = _.assignIn(
callbacks = assignIn(
{
onStart: doNothing,
onEnd: doNothing,
Expand Down
10 changes: 5 additions & 5 deletions imports/ldap/import.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
let getLDAPUsers = require("./getLDAPUsers"),
saveUsers = require("./saveUsers");
import getLDAPUsers from "./getLDAPUsers";
import saveUsers from "./saveUsers";

const report = (bulkResult) => {
let inserted = bulkResult.nUpserted,
updated = bulkResult.nModified;
const inserted = bulkResult.nUpserted;
const updated = bulkResult.nModified;

console.log(
`Successfully inserted ${inserted} users and updated ${updated} users.`,
Expand Down Expand Up @@ -55,4 +55,4 @@ const importUsers = (ldapSettings, mongoUrl) =>
.then(resetSelfSigned)
.catch(handleRejection);

module.exports = importUsers;
export default importUsers;
11 changes: 6 additions & 5 deletions imports/ldap/saveUsers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { MongoClient as mongo } from "mongodb";
import { parse } from "mongo-uri";
import transformUser from "./transformUser";

import { map, forEach } from "lodash";
import { Random } from "../../tests/performance/fixtures/lib/random";
import { generateId } from "../../tests/performance/fixtures/lib/random";

const _transformUsers = (settings, users) =>
map(users, (user) => transformUser(settings, user));
Expand Down Expand Up @@ -41,7 +42,7 @@ const _insertUsers = (client, mongoUri, users) => {
.upsert()
.updateOne({
$setOnInsert: {
_id: Random.generateId(),
_id: generateId(),
// by setting this only on insert we won't log out everyone
// everytime we sync the users
services: {
Expand All @@ -68,9 +69,9 @@ const _insertUsers = (client, mongoUri, users) => {
};

const _closeMongo = (data) => {
let force = false,
client = data.client,
result = data.bulkResult;
const force = false;
const client = data.client;
const result = data.bulkResult;

return new Promise((resolve) => {
client.close(force);
Expand Down
16 changes: 12 additions & 4 deletions imports/ldap/transformUser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { pick, without } from "lodash";
import { pick } from "lodash";

/**
* Filters an array and returns a new array without the specified values.
*
* @param {Array} arr - The array to filter.
* @param {...*} args - The values to exclude from the filtered array.
* @returns {Array} - A new array with the values excluded.
*/
const without = (arr, ...args) => arr.filter(item => !args.includes(item))
export default (ldapSettings, userData) => {
ldapSettings.propertyMap = ldapSettings.propertyMap || {};
const usernameAttribute =
ldapSettings.searchDn || ldapSettings.propertyMap.username || "cn",
longnameAttribute = ldapSettings.propertyMap.longname,
mailAttribute = ldapSettings.propertyMap.email || "mail";
ldapSettings.searchDn || ldapSettings.propertyMap.username || "cn";
const longnameAttribute = ldapSettings.propertyMap.longname;
const mailAttribute = ldapSettings.propertyMap.email || "mail";

// userData.mail may be a string with one mail address or an array.
// Nevertheless we are only interested in the first mail address here - if
Expand Down
24 changes: 12 additions & 12 deletions programs/generateLicenseList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const crawler = require("npm-license-crawler"),
http = require("http"),
https = require("https"),
fs = require("fs");
import { dumpLicenses } from "npm-license-crawler";
import { get as _get } from "http";
import { get as __get } from "https";
import { createWriteStream } from "fs";

const meteorPackages = {
meteor: {
Expand Down Expand Up @@ -107,9 +107,9 @@ const meteorPackages = {

function get(url, callback) {
if (url.startsWith("https")) {
https.get(url, callback);
__get(url, callback);
} else {
http.get(url, callback);
_get(url, callback);
}
}

Expand Down Expand Up @@ -169,11 +169,11 @@ function streamCollector(streams, index, outStream) {
outStream.write(`\n\n${licenseSeparator}\n\n`);
streamCollector(streams, index + 1, outStream);
});
} else {
console.log(`NO LICENSE TEXT FOUND FOR ${project}`);
outStream.write(`\n\n${licenseSeparator}\n\n`);
streamCollector(streams, index + 1, outStream);
return;
}
console.log(`NO LICENSE TEXT FOUND FOR ${project}`);
outStream.write(`\n\n${licenseSeparator}\n\n`);
streamCollector(streams, index + 1, outStream);
})
.catch(console.error);
}
Expand All @@ -185,13 +185,13 @@ function getSortedKeys(obj) {
return keys.sort((a, b) => obj[b] - obj[a]);
}

crawler.dumpLicenses({ start: ["."] }, (error, res) => {
dumpLicenses({ start: ["."] }, (error, res) => {
if (error) {
console.error("Error:", error);
return;
}

const output = fs.createWriteStream("LicensesOfDependencies.txt");
const output = createWriteStream("LicensesOfDependencies.txt");
const streams = Object.keys(res).map((project) =>
downloadToStream(project, res[project].licenseUrl, res[project].licenses),
);
Expand Down

0 comments on commit c094627

Please sign in to comment.