-
-
Notifications
You must be signed in to change notification settings - Fork 219
Close #1700: accept file arguments in typia generate CLI #1702
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,19 +11,28 @@ export namespace TypiaProgrammer { | |||||||||||||||||||||||||||||||||||||||||||||
| input: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| output: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| project: string; | ||||||||||||||||||||||||||||||||||||||||||||||
| files?: string[]; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| export const build = async ( | ||||||||||||||||||||||||||||||||||||||||||||||
| location: TypiaProgrammer.ILocation, | ||||||||||||||||||||||||||||||||||||||||||||||
| ): Promise<void> => { | ||||||||||||||||||||||||||||||||||||||||||||||
| location.input = path.resolve(location.input); | ||||||||||||||||||||||||||||||||||||||||||||||
| const hasFiles = location.files && location.files.length > 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Resolve paths | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!hasFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||
| location.input = path.resolve(location.input); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| location.output = path.resolve(location.output); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if ((await is_directory(location.input)) === false) | ||||||||||||||||||||||||||||||||||||||||||||||
| throw new URIError( | ||||||||||||||||||||||||||||||||||||||||||||||
| "Error on TypiaGenerator.generate(): input path is not a directory.", | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| else if (fs.existsSync(location.output) === false) | ||||||||||||||||||||||||||||||||||||||||||||||
| // Validate directories | ||||||||||||||||||||||||||||||||||||||||||||||
| if (!hasFiles) { | ||||||||||||||||||||||||||||||||||||||||||||||
| if ((await is_directory(location.input)) === false) | ||||||||||||||||||||||||||||||||||||||||||||||
| throw new URIError( | ||||||||||||||||||||||||||||||||||||||||||||||
| "Error on TypiaGenerator.generate(): input path is not a directory.", | ||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| if (fs.existsSync(location.output) === false) | ||||||||||||||||||||||||||||||||||||||||||||||
| await fs.promises.mkdir(location.output, { recursive: true }); | ||||||||||||||||||||||||||||||||||||||||||||||
| else if ((await is_directory(location.output)) === false) { | ||||||||||||||||||||||||||||||||||||||||||||||
| const parent: string = path.join(location.output, ".."); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -34,6 +43,11 @@ export namespace TypiaProgrammer { | |||||||||||||||||||||||||||||||||||||||||||||
| await fs.promises.mkdir(location.output); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Resolve file paths | ||||||||||||||||||||||||||||||||||||||||||||||
| const resolvedFiles = hasFiles | ||||||||||||||||||||||||||||||||||||||||||||||
| ? location.files!.map((f) => path.resolve(f)) | ||||||||||||||||||||||||||||||||||||||||||||||
| : []; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Validate provided files (when using explicit file list) | |
| if (hasFiles) { | |
| for (const file of resolvedFiles) { | |
| try { | |
| const stat = await fs.promises.stat(file); | |
| if (stat.isFile() === false) { | |
| throw new URIError( | |
| "Error on TypiaGenerator.generate(): input file path is not a file: " + | |
| file, | |
| ); | |
| } | |
| await fs.promises.access(file, fs.constants.R_OK); | |
| } catch { | |
| throw new URIError( | |
| "Error on TypiaGenerator.generate(): input file does not exist or is not readable: " + | |
| file, | |
| ); | |
| } | |
| } | |
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Skip import transformation when processing individual files" but doesn't explain why this is necessary. The ImportTransformer appears to rewrite import paths from the input directory structure to the output directory structure. Skipping this for individual files may cause import paths to break if the generated files have different relative paths. This needs clarification or a more robust solution.
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using file arguments mode, the output path can collide if multiple input files have the same basename. For example, src/users/user.typia.ts and src/orders/user.typia.ts would both write to output/user.typia.ts, with the second overwriting the first. Consider adding validation to detect duplicate basenames or implement a conflict resolution strategy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new file arguments feature in the CLI lacks automated test coverage. While the repository has comprehensive testing for transformation features, there are no tests for CLI functionality like the ArgumentParser or TypiaGenerateWizard. Consider adding integration tests that verify file argument parsing, validation, and correct handling of both directory and file modes.