Azure / Azure/typespec-azure

[typespec-ts] Add `src-output-dir` option for specifying source code output dir

Open
#4,760 9 comments 0 reactions 1 assignee Claimed by @dgetu View on GitHub
emitter:typescript
Dominant language
TypeScript
Stars
27
Forks
90
Avg merge
1d 22h
Merged PRs (30d)
156

Description

Example usage:

Existing customization behavior should stay the same - the default behavior is to emit to `generated` if the dir already exists, `src` otherwise.

```jsonc
{
"src-output-dir": "src/generated", // defaults to "generated" if the directory exists at emit time, "src" otherwise
"entry-point-root": "src" // defaults to "src-output-dir" if defined, "src" otherwise
}
```

`ls .`

| filename | example filename | kind |
|--------------------------------|----------------------------|-------------|
| `${entry-point-root}/index.ts` | `src/index.ts` | authored |
| `${entry-dir}/models/index.ts` | `src/models/index.ts` | authored |
| `${entry-dir}/api/index.ts` | `src/api/index.ts` | authored |
| `${src-output-dir}/index.ts` | `src/generated/index.ts` | generated |
| `${src-output-dir}/models/...` | `src/generated/models/...` | generated |
| `${src-output-dir}/api/...` | `src/generated/api/...` | generated |

If `entry-point-root` isn't the same as `src-output-dir`, create each missing authored file of the three listed above, and re-export the corresponding generated `index.ts` from it. If an authored file already exists, don't change it, since it's meant to be customized by the SDK author.

`src/index.ts` (only write to this file if it doesn't exist)

```ts
export * from "./generated/index.js";
```

`package.json`, `api-extractor.json`, `tsconfig.json` and `.tshy` config output need to be updated as well.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.