Skip to content

Commit

Permalink
feat: allow formatting to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jansedlon committed Jun 5, 2024
1 parent dd55dad commit cc9fffe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ In addition to the Prisma features, you can also generate Drizzle-specific featu
| relationalQuery | Flag to generate relational query | true | false |
| moduleResolution | Specify the [module resolution](https://www.typescriptlang.org/tsconfig#moduleResolution) that will affect the import style | _*auto_ | nodenext |
| verbose | Flag to enable verbose logging | - | true |
| abortOnFailedFormatting | Flag to throw exception when formatting fails | true | false |
| **dateMode | Change the generated mode for date | "date" ||

_* It will find the closest tsconfig from the current working directory. Note that [extends](https://www.typescriptlang.org/tsconfig#extends) is not supported_
Expand Down
39 changes: 24 additions & 15 deletions packages/generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,30 @@ generatorHandler({
function handleFormatting() {
const generator = getGenerator()
if (generator.config.formatter == null) return
switch (generator.config.formatter) {
case 'prettier':
execSync(`prettier --write ${generator.output.path}`, {
stdio: 'inherit',
})
break
case 'biome':
execSync(`biome format --write ${generator.output.path}`, {
stdio: 'inherit',
})
break
default:
execSync(`${generator.config.formatter} ${generator.output.path}`, {
stdio: 'inherit',
})

try {
switch (generator.config.formatter) {
case 'prettier':
execSync(`prettier --write ${generator.output.path}`, {
stdio: 'inherit',
})
break
case 'biome':
execSync(`biome format --write ${generator.output.path}`, {
stdio: 'inherit',
})
break
default:
execSync(`${generator.config.formatter} ${generator.output.path}`, {
stdio: 'inherit',
})
}
} catch (e) {
if (generator.config.abortOnFailedFormatting) {
throw e
}

logger.log('Failed to format the generated schema')
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/generator/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Config = object({
moduleResolution: optional(ModuleResolution),
verbose: optional(BooleanInStr),
formatter: optional(string()),
abortOnFailedFormatting: withDefault(optional(BooleanInStr), true),
dateMode: optional(DateMode),
})
export type Config = Output<typeof Config>
Expand Down

0 comments on commit cc9fffe

Please sign in to comment.