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

return non-zero status code when type generation is incomplete or validation fails #154

Open
mnbf9rca opened this issue Aug 17, 2023 · 1 comment
Labels
breaking This issue introduces a breaking change that would go into a new Major version enhancement New feature or request
Milestone

Comments

@mnbf9rca
Copy link

Feature description

I have a script which generates all my types based on entries in a config file:

const { execSync } = require('child_process')
const config = require('../ts-to-zod.config.js')

try {
  config.forEach(entry => {
    const command = `npx ts-to-zod --config ${entry.name}`
    console.log(`Running: ${command}`)
    execSync(command, { stdio: 'inherit' })
  })

  console.log('All commands executed successfully.')
  process.exit(0) // Exit with success status code
} catch (error) {
  console.error('An error occurred while executing the commands:', error.message)
  process.exit(1) // Exit with failure status code
}

I have this run before all my tests:

  "scripts": {
    "pretest": "npm run gen:all",
    "gen:all": "node scripts/generate-zod-schemas.js",
    "test": "NODE_ENV=test jest --verbose --runInBand --coverage --detectOpenHandles --forceExit",
    // other scripts
  },

Desired outcome

I would like errors like this one:

 ›   Warning: Some schemas can't be generated due to direct or indirect missing dependencies:
 ›   stopPointSchema
✔ Validating generated types
🎉 Zod schemas generated!

to cause ts-to-zod to return a non-zero status code so that the test execution stops. Instead, i get an empty or incomplete zod schema file.

@schiller-manuel
Copy link
Collaborator

Feel free to create a PR!

@schiller-manuel schiller-manuel added the breaking This issue introduces a breaking change that would go into a new Major version label Feb 28, 2024
@tvillaren tvillaren added the enhancement New feature or request label Aug 13, 2024
@tvillaren tvillaren added the v4 label Aug 26, 2024
@tvillaren tvillaren added this to the 4.0.0 milestone Aug 26, 2024
@tvillaren tvillaren removed the v4 label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This issue introduces a breaking change that would go into a new Major version enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants