fix(generator): support explicit directory option and use in packagejson/README templates#8897
Conversation
…json/README templates
There was a problem hiding this comment.
Code Review
This pull request introduces a new directory option to allow specifying a custom monorepo directory for the generated TypeScript package, updating the generator logic, schema, and templates (CJS and ESM package.json and README files) to use this directory if provided. The reviewer suggests renaming this option and its associated properties to package-dir / packageDir across all files to avoid confusion with the output directory and to maintain consistency with existing options like package-name.
| .alias('directory', 'package_dir') | ||
| .describe('directory', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)') |
There was a problem hiding this comment.
Using --directory as a CLI option name is highly generic and can easily be confused with the output directory where the generated code is written. To avoid confusion and maintain consistency with --package-name, it is recommended to name this option --package-dir.
| .alias('directory', 'package_dir') | |
| .describe('directory', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)') | |
| .alias('package-dir', 'package_dir') | |
| .describe('package-dir', 'Monorepo directory of the package (e.g. packages/google-cloud-workflows)') |
| const bundleConfig = argv.bundleConfig as string | undefined; | ||
| const serviceYaml = argv.serviceYaml as string | undefined; | ||
| const packageName = argv.packageName as string | undefined; | ||
| const directory = argv.directory as string | undefined; |
| if (directory) { | ||
| protocCommand.push(`--typescript_gapic_opt="directory=${directory}"`); | ||
| } |
There was a problem hiding this comment.
| paramMap: OptionsMap; | ||
| // This field is for users passing proper publish package name like @google-cloud/text-to-speech. | ||
| publishName?: string; | ||
| directory?: string; |
|
|
||
| private readPublishPackageName() { | ||
| this.publishName = this.paramMap['package-name']; | ||
| this.directory = this.paramMap['directory']; |
| }, | ||
| "license": "Apache-2.0", | ||
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/{{ api.naming.namePath }}", | ||
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}", |
There was a problem hiding this comment.
Use api.packageDir instead of api.directory to match the renamed property.
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}", | |
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}", |
| "repository": { | ||
| "type": "git", | ||
| "directory": "packages/{{ api.naming.namePath }}", | ||
| "directory": "{{ api.directory or ('packages/' + api.naming.namePath) }}", |
| }, | ||
| "license": "Apache-2.0", | ||
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/packages/{{ api.naming.namePath }}", | ||
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}", |
There was a problem hiding this comment.
Use api.packageDir instead of api.directory to match the renamed property.
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.directory or ('packages/' + api.naming.namePath) }}", | |
| "homepage": "https://github.com/googleapis/google-cloud-node/tree/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}", |
| [homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/samples | ||
| [homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/CHANGELOG.md | ||
| [homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }} |
There was a problem hiding this comment.
Use api.packageDir instead of api.directory to match the renamed property.
[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}
| [homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/samples | ||
| [homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }}/CHANGELOG.md | ||
| [homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.directory or ('packages/' + api.naming.namePath) }} |
There was a problem hiding this comment.
Use api.packageDir instead of api.directory to match the renamed property.
[homepage_samples]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/samples
[homepage_changelog]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}/CHANGELOG.md
[homepage]: https://github.com/googleapis/google-cloud-node/blob/main/{{ api.packageDir or ('packages/' + api.naming.namePath) }}
No description provided.