Skip to content

Commit

Permalink
feat: Proper exit code when schema generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
gallayl committed Jun 2, 2024
1 parent f86e474 commit 734eeca
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions common/src/bin/create-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,30 @@ export const apiValues: SchemaGenerationSetting[] = [
]

export const exec = async (): Promise<void> => {
for (const schemaValue of [...entityValues, ...apiValues]) {
try {
console.log(`Create schema from ${schemaValue.inputFile} to ${schemaValue.outputFile}`)
const schema = createGenerator({
path: join(process.cwd(), schemaValue.inputFile),
tsconfig: join(process.cwd(), './tsconfig.json'),
skipTypeCheck: true,
expose: 'all',
}).createSchema(schemaValue.type)
await promises.writeFile(join(process.cwd(), schemaValue.outputFile), JSON.stringify(schema, null, 2))
} catch (error) {
console.error(`There was an error generating schema from ${schemaValue.inputFile}`, error)
process.exit(1)
}
}
await Promise.all(
[...entityValues, ...apiValues].map(async (schemaValue) => {
try {
const inputFile = join(process.cwd(), schemaValue.inputFile)
const outputFile = join(process.cwd(), schemaValue.outputFile)

console.log(`Create schema from ${inputFile} to ${outputFile}`)
const schema = createGenerator({
path: inputFile,
tsconfig: join(process.cwd(), './tsconfig.json'),
skipTypeCheck: true,
expose: 'all',
}).createSchema(schemaValue.type)
await promises.writeFile(outputFile, JSON.stringify(schema, null, 2))
console.log(`Schema generated succesfully.`)
} catch (error) {
console.error(`There was an error generating schema from ${schemaValue.inputFile}`, error)
throw error
}
}),
)
}

exec()
exec().catch((error) => {
console.error('Schema generation failed', error)
process.exit(1)
})

0 comments on commit 734eeca

Please sign in to comment.