From a5331a68acbcca62d114f980e511f57ecb190e46 Mon Sep 17 00:00:00 2001 From: Golmote Date: Tue, 20 Mar 2018 20:57:34 +0100 Subject: [PATCH] Add a loadLanguages() function for easy component loading on NodeJS (#1359) --- components/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 components/index.js diff --git a/components/index.js b/components/index.js new file mode 100644 index 0000000000..80a70c2a79 --- /dev/null +++ b/components/index.js @@ -0,0 +1,24 @@ +var components = require('../components.js'); + +function loadLanguages(arr) { + // If no argument is passed, load all components + if (!arr) { + arr = Object.keys(components.languages).filter(function (lang) { + return lang !== 'meta'; + }); + } + + if (!Array.isArray(arr)) { + arr = [arr]; + } + arr.forEach(function(language) { + // Load dependencies first + if (components.languages[language] && components.languages[language].require) { + loadLanguages(components.languages[language].require); + } + + require('./prism-' + language); + }); +} + +module.exports = loadLanguages; \ No newline at end of file