MCPcopy
hub / github.com/MagicMirrorOrg/MagicMirror / loadFileForModule

Function loadFileForModule

js/loader.js:283–307  ·  view source on GitHub ↗

* 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 loade

(fileName, module)

Source from the content-addressed store, hash-verified

281 * @returns {Promise} resolved when the file is loaded
282 */
283 loadFileForModule (fileName, module) {
284 if (loadedFiles.indexOf(fileName.toLowerCase()) !== -1) {
285 Log.log(`File already loaded: ${fileName}`);
286 return Promise.resolve();
287 }
288
289 if (fileName.indexOf("http://") === 0 || fileName.indexOf("https://") === 0 || fileName.indexOf("/") !== -1) {
290 // This is an absolute or relative path.
291 // Load it and then return.
292 loadedFiles.push(fileName.toLowerCase());
293 return loadFile(fileName);
294 }
295
296 if (vendor[fileName] !== undefined) {
297 // This file is defined in js/vendor.js.
298 // Load it from its location.
299 loadedFiles.push(fileName.toLowerCase());
300 return loadFile(`${vendor[fileName]}`);
301 }
302
303 // File not loaded yet.
304 // Load it based on the module path.
305 loadedFiles.push(fileName.toLowerCase());
306 return loadFile(module.file(fileName));
307 }
308};

Callers

nothing calls this directly

Calls 2

loadFileFunction · 0.85
fileMethod · 0.80

Tested by

no test coverage detected