-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from yamadashy/feature/zod
feat: Implement Zod for Robust Configuration Validation
- Loading branch information
Showing
24 changed files
with
410 additions
and
249 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { z } from 'zod'; | ||
|
||
// Output style enum | ||
export const repomixOutputStyleSchema = z.enum(['plain', 'xml', 'markdown']); | ||
export type RepomixOutputStyle = z.infer<typeof repomixOutputStyleSchema>; | ||
|
||
// Default values map | ||
export const defaultFilePathMap: Record<RepomixOutputStyle, string> = { | ||
plain: 'repomix-output.txt', | ||
markdown: 'repomix-output.md', | ||
xml: 'repomix-output.xml', | ||
} as const; | ||
|
||
// Base config schema | ||
export const repomixConfigBaseSchema = z.object({ | ||
output: z | ||
.object({ | ||
filePath: z.string().optional(), | ||
style: repomixOutputStyleSchema.optional(), | ||
headerText: z.string().optional(), | ||
instructionFilePath: z.string().optional(), | ||
removeComments: z.boolean().optional(), | ||
removeEmptyLines: z.boolean().optional(), | ||
topFilesLength: z.number().optional(), | ||
showLineNumbers: z.boolean().optional(), | ||
copyToClipboard: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
include: z.array(z.string()).optional(), | ||
ignore: z | ||
.object({ | ||
useGitignore: z.boolean().optional(), | ||
useDefaultPatterns: z.boolean().optional(), | ||
customPatterns: z.array(z.string()).optional(), | ||
}) | ||
.optional(), | ||
security: z | ||
.object({ | ||
enableSecurityCheck: z.boolean().optional(), | ||
}) | ||
.optional(), | ||
}); | ||
|
||
// Default config schema with default values | ||
export const repomixConfigDefaultSchema = z.object({ | ||
output: z | ||
.object({ | ||
filePath: z.string().default(defaultFilePathMap.plain), | ||
style: repomixOutputStyleSchema.default('plain'), | ||
headerText: z.string().optional(), | ||
instructionFilePath: z.string().optional(), | ||
removeComments: z.boolean().default(false), | ||
removeEmptyLines: z.boolean().default(false), | ||
topFilesLength: z.number().int().min(0).default(5), | ||
showLineNumbers: z.boolean().default(false), | ||
copyToClipboard: z.boolean().default(false), | ||
}) | ||
.default({}), | ||
include: z.array(z.string()).default([]), | ||
ignore: z | ||
.object({ | ||
useGitignore: z.boolean().default(true), | ||
useDefaultPatterns: z.boolean().default(true), | ||
customPatterns: z.array(z.string()).default([]), | ||
}) | ||
.default({}), | ||
security: z | ||
.object({ | ||
enableSecurityCheck: z.boolean().default(true), | ||
}) | ||
.default({}), | ||
}); | ||
|
||
export const repomixConfigFileSchema = repomixConfigBaseSchema; | ||
|
||
export const repomixConfigCliSchema = repomixConfigBaseSchema; | ||
|
||
export const repomixConfigMergedSchema = repomixConfigDefaultSchema | ||
.and(repomixConfigFileSchema) | ||
.and(repomixConfigCliSchema) | ||
.and( | ||
z.object({ | ||
cwd: z.string(), | ||
}), | ||
); | ||
|
||
export type RepomixConfigDefault = z.infer<typeof repomixConfigDefaultSchema>; | ||
export type RepomixConfigFile = z.infer<typeof repomixConfigFileSchema>; | ||
export type RepomixConfigCli = z.infer<typeof repomixConfigCliSchema>; | ||
export type RepomixConfigMerged = z.infer<typeof repomixConfigMergedSchema>; | ||
|
||
export const defaultConfig = repomixConfigDefaultSchema.parse({}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.