import { ComponentCompilerMeta } from '@stencil/core/internal' ; import { sortBy } from './array' ; import { dashToPascalCase } from './string' ; export const ignoreChecks = ( ) => [ '/* eslint-disable */' , '/* tslint:disable */' , '// @ts-nocheck' ] . join ( '\n' ) ; export const fileName = ( c ) => dashToPascalCase ( c . tagName ) . slice ( 2 ) ; export const buildImports = ( components , ext = '' , isDefaultExport = true ) => components . map ( c => `import ${ isDefaultExport ? `${ fileName ( c ) }Proxy` : `{ ${ fileName ( c ) } as ${ fileName ( c ) }Proxy }` } from './${ fileName ( c ) }${ ext }';` ) . join ( '\n' ) ; export const buildExports = ( components ) => components . map ( c => `export const ${ fileName ( c ) } = /*#__PURE__*/${ fileName ( c ) }Proxy;` ) . join ( '\n' ) ; export const sortComponents = ( cmps ) => sortBy < ComponentCompilerMeta > ( cmps , ( cmp ) => cmp . tagName ) ; export const jsxEventName = ( eventName ) => `on${ eventName . charAt ( 0 ) . toUpperCase ( ) + eventName . slice ( 1 ) }` ; export const safeDefaultValue = ( value ? ) => { try { eval ( value ?? '' ) ; return true ; } catch ( e ) { return false ; } } ; export const findAllDependencies = ( cmpMeta , components ) => { const getDirectDeps = ( tagName ) => components . find ( cmp => cmp . tagName === tagName ) ?. dependencies ?? [ ] ; const getDepTree = ( tagName , imports = new Set ( ) ) => { imports . add ( tagName ) ; const deps = getDirectDeps ( tagName ) ?? [ ] ; deps . forEach ( dep => { getDepTree ( dep , imports ) ; } ) ; return Array . from ( imports ) ; } ; return getDepTree ( cmpMeta . tagName ) . map ( tagName => ( { tagName , className : dashToPascalCase ( tagName ) , } ) ) ; } ; export const importAllDepdencies = ( cmpMeta , components ) => { const deps = findAllDependencies ( cmpMeta , components ) ; return `
import { 
  ${ [ ... deps . map ( i => i . className ) ] . join ( ',\n  ' ) } 
} from '@vime/core';

import { define } from '../lib';
  ` ; } ; export const defineAllDependencies = ( cmpMeta , components ) => { const deps = findAllDependencies ( cmpMeta , components ) ; return `
${ deps . map ( cmp => `define('${ cmp . tagName }', ${ cmp . className });` ) . join ( '\n' ) }
  ` ; } ;