fbredius/storybook

View on GitHub
lib/theming/src/ensure.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { logger } from '@storybook/client-logger';

import { deletedDiff } from 'deep-object-diff';
import dedent from 'ts-dedent';

import light from './themes/light';
import { Theme, ThemeVars } from './types';
import { convert } from './convert';

export const ensure = (input: ThemeVars): Theme => {
  if (!input) {
    return convert(light);
  }
  const missing = deletedDiff(light, input);
  if (Object.keys(missing).length) {
    logger.warn(
      dedent`
          Your theme is missing properties, you should update your theme!

          theme-data missing:
        `,
      missing
    );
  }

  return convert(input);
};