All files / packages/design-system-2/scripts/buildCss/utils names.ts

100% Statements 10/10
100% Branches 15/15
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54                    13x             13x 236x                 13x                             57x 57x 57x     57x 30x     27x    
/**
 * Shared name substitution for the CSS build.
 *
 * One helper fills the {system} and {theme} placeholders in a path or filename
 * template. deriveFilename builds the output base filename from the same tokens
 * and the variant flags. Callers pass explicit tokens; this file is the only
 * place that concatenates system and theme into a path or filename.
 */
 
/** The theme names this build produces. */
export const THEMES = ['cosmos', 'lightning-blue'];
 
/**
 * Fill the {system} and {theme} placeholders in one template.
 * template: a path or filename that may contain {system} and {theme}.
 * system and theme: the values to substitute.
 */
export const fillName = (template: string, { system, theme = '' }: { system: string; theme?: string }) =>
  template.replaceAll('{system}', system).replaceAll('{theme}', theme);
 
/**
 * Derive the output base filename from the variant flags.
 *
 * A build that is neither production nor theme-layer is a base structure file,
 * for example slds2.base or slds2.scoped.base. Every other variant carries a
 * theme suffix. System and theme concatenation runs through fillName.
 */
export const deriveFilename = ({
  system,
  theme,
  lbc = false,
  themeLayer = false,
  scoped = false,
  production = false,
}: {
  system: string;
  theme: string;
  lbc?: boolean;
  themeLayer?: boolean;
  scoped?: boolean;
  production?: boolean;
}) => {
  const lbcInfix = lbc ? '.lbc' : '';
  const themeLayerInfix = themeLayer ? '.theme-layer' : '';
  const scopedSuffix = scoped ? '.scoped' : '';
 
  // A base structure file has no theme suffix.
  if (!production && !themeLayer) {
    return fillName(`{system}${scopedSuffix}.base`, { system, theme });
  }
 
  return fillName(`{system}${lbcInfix}${themeLayerInfix}${scopedSuffix}.{theme}`, { system, theme });
};