From 69e796f92af29bbaff7bb93723c4b007eee77ec9 Mon Sep 17 00:00:00 2001 From: Ni55aN Date: Fri, 22 Dec 2023 22:03:46 +0200 Subject: [PATCH 1/2] refactor(init): supported stacks and features --- src/index.ts | 34 +--------------------------------- src/init/index.ts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 src/init/index.ts diff --git a/src/index.ts b/src/index.ts index afeb58e..b667834 100755 --- a/src/index.ts +++ b/src/index.ts @@ -8,44 +8,12 @@ import { join, dirname, resolve } from 'path' 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`) diff --git a/src/init/index.ts b/src/init/index.ts new file mode 100644 index 0000000..c452ba1 --- /dev/null +++ b/src/init/index.ts @@ -0,0 +1,34 @@ +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) + ] +} + From c50dd36e9ba1fb9c3d2ed3fc122ccf109ef954f8 Mon Sep 17 00:00:00 2001 From: Ni55aN Date: Fri, 22 Dec 2023 22:04:18 +0200 Subject: [PATCH 2/2] feat(init): validate stacks and versions --- src/index.ts | 11 +++++++++-- src/init/index.ts | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index b667834..457d901 100755 --- a/src/index.ts +++ b/src/index.ts @@ -27,16 +27,23 @@ program 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) diff --git a/src/init/index.ts b/src/init/index.ts index c452ba1..d1277fb 100644 --- a/src/init/index.ts +++ b/src/init/index.ts @@ -32,3 +32,24 @@ export function getFeatures({ stack, version }: (typeof fixtures)[0], next: bool ] } +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 } +}