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 } +}