Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 46 additions & 49 deletions js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,60 +249,57 @@ function loadFile (fileName) {

/* Public Methods */

export const Loader = {

/**
* Load all modules as defined in the config.
*/
async loadModules () {
const moduleData = await getModuleData();
const envVars = await getEnvVars();
const customCss = envVars.customCss;

// Load all modules
for (const module of moduleData) {
await loadModule(module);
}
/**
* Load all modules as defined in the config.
*/
export async function loadModules () {
const moduleData = await getModuleData();
const envVars = await getEnvVars();
const customCss = envVars.customCss;

// Load custom.css
// Since this happens after loading the modules,
// it overwrites the default styles.
await loadFile(customCss);
// Load all modules
for (const module of moduleData) {
await loadModule(module);
}

// Start all modules.
await startModules();
},
// Load custom.css
// Since this happens after loading the modules,
// it overwrites the default styles.
await loadFile(customCss);

/**
* Load a file (script or stylesheet).
* Prevent double loading and search for files defined in js/vendor.js.
* @param {string} fileName Path of the file we want to load.
* @param {Module} module The module that calls the loadFile function.
* @returns {Promise} resolved when the file is loaded
*/
loadFileForModule (fileName, module) {
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
Log.log(`File already loaded: ${fileName}`);
return Promise.resolve();
}
// Start all modules.
await startModules();
}

if (fileName.indexOf("http://") === 0 || fileName.indexOf("https://") === 0 || fileName.indexOf("/") !== -1) {
// This is an absolute or relative path.
// Load it and then return.
loadedFiles.push(fileName.toLowerCase());
return loadFile(fileName);
}
/**
* Load a file (script or stylesheet).
* Prevent double loading and search for files defined in js/vendor.js.
* @param {string} fileName Path of the file we want to load.
* @param {Module} module The module that calls the loadFile function.
* @returns {Promise} resolved when the file is loaded
*/
export function loadFileForModule (fileName, module) {
if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
Log.log(`File already loaded: ${fileName}`);
return Promise.resolve();
}

if (vendor[fileName] !== undefined) {
// This file is defined in js/vendor.js.
// Load it from its location.
loadedFiles.push(fileName.toLowerCase());
return loadFile(`${vendor[fileName]}`);
}
if (fileName.indexOf("http://") === 0 || fileName.indexOf("https://") === 0 || fileName.indexOf("/") !== -1) {
// This is an absolute or relative path.
// Load it and then return.
loadedFiles.push(fileName.toLowerCase());
return loadFile(fileName);
}

// File not loaded yet.
// Load it based on the module path.
if (vendor[fileName] !== undefined) {
// This file is defined in js/vendor.js.
// Load it from its location.
loadedFiles.push(fileName.toLowerCase());
return loadFile(module.file(fileName));
return loadFile(`${vendor[fileName]}`);
}
};

// File not loaded yet.
// Load it based on the module path.
loadedFiles.push(fileName.toLowerCase());
return loadFile(module.file(fileName));
}
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global addAnimateCSS, removeAnimateCSS, AnimateCSSIn, AnimateCSSOut, modulePositions, io */

// eslint-disable-next-line import-x/extensions
import { Loader } from "./loader.js";
import { loadModules } from "./loader.js";

let modules = [];

Expand Down Expand Up @@ -573,7 +573,7 @@
Log.setLogLevel(config.logLevel);

await globalThis.Translator.loadCoreTranslations(config.language);
await Loader.loadModules();
await loadModules();

Check failure

Code scanning / CodeQL

Invocation of non-function Error

Callee is not a function: it has type undefined.
Comment thread
KristjanESPERANTO marked this conversation as resolved.
Dismissed
},

/**
Expand Down
4 changes: 2 additions & 2 deletions js/module.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global nunjucks */

// eslint-disable-next-line import-x/extensions
import { Loader } from "./loader.js";
import { loadFileForModule } from "./loader.js";
// eslint-disable-next-line import-x/extensions
import { MMSocket } from "./socketclient.js";

Expand Down Expand Up @@ -282,7 +282,7 @@
const loadNextDependency = async () => {
if (dependencies.length > 0) {
const nextDependency = dependencies[0];
await Loader.loadFileForModule(nextDependency, this);
await loadFileForModule(nextDependency, this);

Check failure

Code scanning / CodeQL

Invocation of non-function Error

Callee is not a function: it has type undefined.
Comment thread
KristjanESPERANTO marked this conversation as resolved.
Dismissed
dependencies = dependencies.slice(1);
await loadNextDependency();
} else {
Expand Down