All files / src/commands/init index.ts

100% Statements 26/26
95.83% Branches 23/24
100% Functions 9/9
100% Lines 22/22

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 55 56 57 58 59 60 61 62 63 641x   1x               6x   1x 23x   23x           1x 46x                             1x 7x   4x 1x     3x 1x     2x 2x 2x 3x   3x     2x 1x       1x    
import { App } from 'rete-kit'
 
export const targets: { stack: App.AppStack, versions: number[] }[] = [
  { stack: 'react', versions: [16, 17, 18] },
  { stack: 'react-vite', versions: [16, 17, 18, 19] },
  { stack: 'vue', versions: [2, 3] },
  { stack: 'angular', versions: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21] },
  { stack: 'svelte', versions: [3, 4, 5] },
  { stack: 'lit-vite', versions: [3] }
]
export const stackNames = targets.map(t => t.stack)
 
export const fixtures = targets
  .map(({ stack, versions }) => versions.map(version => ({ stack, version, folder: `${stack}${version}` as const })))
  .flat()
  .map(({ stack, version, folder }) => ({
    stack,
    version,
    folder
  }))
 
export function getFeatures({ stack, version }: Pick<(typeof fixtures)[0], 'stack' | 'version'>, next: boolean) {
  return [
    stack === 'angular' && new App.Features.Angular(version as 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21, next),
    ['react', 'react-vite'].includes(stack) && new App.Features.React(version, stack, next),
    stack === 'vue' && new App.Features.Vue(version as 2 | 3, next),
    stack === 'svelte' && new App.Features.Svelte(version as 3 | 4 | 5, next),
    stack === 'lit-vite' && new App.Features.Lit(version as 3, next),
    new App.Features.ZoomAt(),
    new App.Features.OrderNodes(),
    new App.Features.Dataflow(next),
    new App.Features.Selectable(),
    new App.Features.Minimap(next),
    new App.Features.Reroute(next)
  ]
}
 
export function validate(stacks: string[], stackVersions: string[] | null): { error: string | null } {
  const unknownStacks = stacks.filter(name => !stackNames.includes(name as App.AppStack))
 
  if (unknownStacks.length > 0) {
    return { error: `Unknown stack names: ${unknownStacks.join(', ')}` }
  }
 
  if (stacks.length > 1 && stackVersions && stackVersions.length > 0) {
    return { error: `You can't specify versions for multiple stacks` }
  }
 
  if (stacks.length === 1 && stackVersions && stackVersions.length > 0) {
    const [stack] = stacks
    const unknownVersions = stackVersions.filter(v => {
      const target = targets.find(t => t.stack === stack)
 
      return !target?.versions.includes(Number(v))
    })
 
    if (unknownVersions.length > 0) {
      return { error: `Unknown stack versions: ${unknownVersions.join(', ')}` }
    }
  }
 
  return { error: null }
}