0.3.0
Publish npm package / publish (push) Canceled after 0s

This commit is contained in:
2026-10-07 15:30:39 +02:00
parent 452d872954
commit ed5a666ad3
11 changed files with 148 additions and 19 deletions
+25
View File
@@ -131,6 +131,31 @@ render("./output", { web: "not a boolean", header: { show: true, title: "Hi" } }
For safety, tdir refuses to render into the filesystem root, the current working directory, the home directory, or any directory that overlaps the template source. Dynamic file and directory names are also resolved against the output directory and cannot write outside it.
Pass `{ overwrite: false }` to keep existing work safe, e.g. in a scaffolding CLI. tdir then throws `TargetExistsError` instead of clearing a target that exists and is not empty (or is a file); a missing or empty target is rendered as usual:
```ts
import { TargetExistsError } from "@gregorlohaus/tdir"
try {
render("./my-app", context, { overwrite: false })
} catch (error) {
if (error instanceof TargetExistsError) console.error("./my-app already exists")
else throw error
}
```
## Renaming output files
Some files can't be stored in a template under their real name, e.g. npm never publishes `.gitignore` or `.npmrc` files. Store them under another name and map it back with `rename`, which applies to rendered file and directory names:
```ts
render("./output", context, { rename: { _gitignore: ".gitignore", _npmrc: ".npmrc" } })
// templates/_gitignore -> output/.gitignore
// templates/<@if(context.web)>web/_gitignore -> output/web/.gitignore
```
Reverse maps record the renamed output path, so `tdir reverse` writes edits back to `_gitignore`.
## Reverse maps
Pass `{ reverseMap: true }` as the third render argument to write `.tdir-map.json` into the output directory: