Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate init parameters #2

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 10 additions & 35 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { createCommand } from 'commander'

Check warning on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Run autofix to sort these imports!
import execa from 'execa'
import chalk from 'chalk'
import fs from 'fs'
Expand All @@ -8,44 +8,12 @@
import { App } from 'rete-kit'
import { appsCachePath, projects } from './consts'
import { log } from './ui'
import { fixtures, getFeatures, stackNames, validate } from './init'

const program = createCommand()

program.version(require('../package.json').version)

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] }
]
const stackNames = targets.map(t => t.stack)

const fixtures = targets
.map(({ stack, versions }) => versions.map(version => ({ stack, version, folder: `${stack}${version}` as const })))
.flat()
.map(({ stack, version, folder }) => ({
stack,
version,
folder
}))

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)
]
}


program
.command('init')
.description(`Initialize testing tool`)
Expand All @@ -53,22 +21,29 @@
.option('-n --next')
.option('-s --stack <stack>', `Stacks to test, comma-separated (${stackNames.join(',')})`)
.option('-sv --stack-versions <stack-version>', `Versions to test, comma-separated`)
.action(async (options: { depsAlias: string, stack?: string, stackVersions?: string, next?: boolean }) => {

Check warning on line 24 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Async arrow function has too many statements (20). Maximum allowed is 12
if (!process.version.startsWith('v16')) console.info(chalk.yellow('---\nWe recommend using Node.js 16 to avoid any potential issues\n---'))

Check warning on line 25 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 143. Maximum allowed is 120

const next = options.next || false
const cwd = process.cwd()
const depsAlias = options.depsAlias ? resolve(cwd, options.depsAlias) : undefined
const stacks = options.stack ? options.stack.split(',') : null
const stacks = options.stack ? options.stack.split(',') : stackNames
const stackVersions = options.stackVersions ? options.stackVersions.split(',') : null

const { error } = validate(stacks, stackVersions)

if (error) {
log('fail', 'FAIL')(chalk.red(error))
process.exit(1)
}

await fs.promises.mkdir(join(cwd, appsCachePath), { recursive: true })

for (const fixture of fixtures) {
const features = getFeatures(fixture, next)
const { folder, stack, version } = fixture

if (stacks && !stacks.includes(stack)) continue
if (!stacks.includes(stack)) continue
if (stackVersions && !stackVersions.includes(String(version))) continue

log('success')('Start creating', chalk.yellow(stack, `v${version}`), 'application in ', folder)
Expand All @@ -94,7 +69,7 @@
.option('-s --stack <stack>', `Stacks to test, comma-separated (${stackNames.join(',')})`)
.option('-sv --stack-versions <stack-version>', `Versions to test, comma-separated`)
.option('-p --project <project>', `Project (${projects.map(p => p.name)})`)
.action(async (options: { updateSnapshots?: boolean, stack?: string, stackVersions?: string, project?: string, grep?: string }) => {

Check warning on line 72 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 134. Maximum allowed is 120

Check warning on line 72 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Async arrow function has too many statements (14). Maximum allowed is 12
const stacks = options.stack ? options.stack.split(',') : null
const stackVersions = options.stackVersions ? options.stackVersions.split(',') : null

Expand Down
55 changes: 55 additions & 0 deletions src/init/index.ts
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)))

Check warning on line 47 in src/init/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 126. Maximum allowed is 120

if (unknownVersions.length > 0) {
return { error: `Unknown stack versions: ${unknownVersions.join(', ')}` }
}
}

return { error: null }
}
Loading