Skip to content

Commit

Permalink
feat(init): validate stacks and versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Dec 22, 2023
1 parent 69e796f commit c50dd36
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions src/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

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

0 comments on commit c50dd36

Please sign in to comment.