function processMultipleThemeArgs()

in lib/cli/commands.ts [89:126]


function processMultipleThemeArgs(args) {
  const themeArgs = Object.keys(PALETTE_OPTIONS).map(key => Utils.dashToCamel(key));
  let themes = [];

  // Filter out the defined, theme-specific keys from the rest.
  let definedArgs = Object.keys(args)
    .filter(key => args[key] && themeArgs.indexOf(key) !== -1);

  // Find the palette with the most colors to be used as a reference.
  let largestPalette = definedArgs
    .sort((key, prevKey) => args[prevKey].length - args[key].length)[0];

  if (largestPalette) {
    // Goes through the colors and creates new themes by matching them to their index.
    for (let i = 0; i < args[largestPalette].length; i++) {
      let newTheme = {
        dark: !!args.dark
      };

      definedArgs.forEach(palette => {
        let value = args[palette][i];

        if (value) {
          newTheme[palette] = value;
        }
      });

      themes.push(newTheme);
    }
  } else {
    // Add a default theme, that will use the defaults, if no palettes were specified.
    themes.push({
      dark: !!args.dark
    });
  }

  args.themes = themes;
}