Skip to content
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

Added dir_base template parameter for emitTemplate #515

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ Config file format (`config.json`):

By default, PgTyped saves generated files in the same folder as the source files it parses.
This behavior can be customized using the `emitTemplate` config parameter.
In that template, four parameters are available for interpolation: `root`, `dir`, `base`, `name` and `ext`.
In that template, following parameters are available for interpolation: `root`, `dir`, `dir_base`, `base`, `name` and `ext`.
For example, when parsing source/query file `/home/user/dir/file.sql`, these parameters are assigned the following values:

```
┌─────────────────────┬────────────┐
│ dir │ base │
├──────┬ ├──────┬─────┤
│ root │ │ name │ ext │
" / home/user/dir / file .sql "
└──────┴──────────────┴──────┴─────┘
┌───────────────────────────┬────────────┐
│ dir │ base │
├──────┬─────────┬──────────├──────┬─────┤
│ root │ │ dir_base │ name │ ext │
" / home/user/ dir / file .sql "
└──────┴────────────────────┴──────┴─────┘
(All spaces in the "" line should be ignored. They are purely for formatting.)
```

Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ let connected = false;
const connection = new AsyncQueue();
const config: ParsedConfig = worker.workerData;

interface extendedParsedPath extends path.ParsedPath {
dir_base: string,
}

export default async function processFile({
fileName,
transform,
Expand All @@ -26,7 +30,9 @@ export default async function processFile({
await startup(config.db, connection);
connected = true;
}
const ppath = path.parse(fileName);
const ppath = path.parse(fileName) as extendedParsedPath;
ppath.dir_base = path.basename(ppath.dir);

let decsFileName;
if (transform.emitTemplate) {
decsFileName = nun.renderString(transform.emitTemplate, ppath);
Expand Down