-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from retejs/validate-init-parameters
Validate init parameters
- Loading branch information
Showing
2 changed files
with
65 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { App } from 'rete-kit' | ||
|
||
export const targets: { stack: App.AppStack, versions: number[] }[] = [ | ||
{ stack: 'react', versions: [16, 17, 18] }, | ||
{ stack: 'vue', versions: [2, 3] }, | ||
{ stack: 'angular', versions: [12, 13, 14, 15, 16, 17] }, | ||
{ stack: 'svelte', versions: [3, 4] } | ||
] | ||
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 }: (typeof fixtures)[0], next: boolean) { | ||
return [ | ||
stack === 'angular' && new App.Features.Angular(version as 12 | 13 | 14 | 15, next), | ||
stack === 'react' && 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, 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 unknownVersions = stackVersions.filter(v => !targets.find(t => t.stack === stacks[0])?.versions.includes(Number(v))) | ||
|
||
if (unknownVersions.length > 0) { | ||
return { error: `Unknown stack versions: ${unknownVersions.join(', ')}` } | ||
} | ||
} | ||
|
||
return { error: null } | ||
} |