Skip to content

Commit 761cb85

Browse files
committed
Add option to set import extension
1 parent 14d1aa9 commit 761cb85

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ async function main() {
2525
'schema': { type: 'string', short: 's' },
2626
'connection-source': { type: 'string', short: 'c' },
2727
'output-dir': { type: 'string', short: 'o' },
28+
'output-import-ext': { type: 'string' },
2829
'remove-extraneous': { type: 'string' },
2930
'export-table-instances': { type: 'boolean' },
3031
'export-row-types': { type: 'boolean' },
@@ -47,6 +48,11 @@ async function main() {
4748
connectionSourcePath: argv["connection-source"],
4849
outputDirPath: argv["output-dir"],
4950
removeExtraneous: argv["remove-extraneous"] ?? "never",
51+
output: {
52+
import: {
53+
extension: argv["output-import-ext"],
54+
}
55+
},
5056
export: {
5157
tableInstances: argv['export-table-instances'],
5258
tableClasses: argv['export-table-classes'],

src/generator-options.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ export const TypeWrapperSchema = z.object({
297297
wrapper: ImportedItemSchema
298298
});
299299

300+
export const OutputImportOptionsSchema = z.object({
301+
extension: z.string().nullish(),
302+
});
303+
304+
export const OutputOptionsSchema = z.object({
305+
import: OutputImportOptionsSchema.nullish(),
306+
});
307+
300308
export const GeneratorOptsSchema = z.object({
301309
/** Simulate the generation and print the outcome without actually modifying any files */
302310
dryRun: z.boolean().nullish(),
@@ -341,6 +349,11 @@ export const GeneratorOptsSchema = z.object({
341349
*/
342350
tables: TableInclusionSchema.nullish(),
343351

352+
/**
353+
* Shared options that affect all generated output
354+
*/
355+
output: OutputOptionsSchema.nullish(),
356+
344357
/**
345358
* Customize what all entities are exported from generated file
346359
*

src/generator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export class Generator {
180180
comment: this.formatComment([table.comment]),
181181
idPrefix,
182182
},
183+
output: this.opts.output,
183184
imports: [
184185
...utilImports,
185186
...adapterImports,

src/template.ts.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* This file has been auto-generated from database schema using ts-sql-codegen.
66
* Any changes will be overwritten.
77
*/
8-
import { {{table.kind}} } from "ts-sql-query/{{table.kind}}";
9-
import type { DBConnection } from "{{dbConnectionSource}}";
8+
import { {{table.kind}} } from "ts-sql-query/{{table.kind}}{{output.import.extension}}";
9+
import type { DBConnection } from "{{dbConnectionSource}}{{output.import.extension}}";
1010
{{#if importExtraTypes}}
1111
import {
1212
{{#if rowTypes.insertable}}
@@ -29,13 +29,13 @@ import {
2929
{{#if valuesTypes.selected}}
3030
SelectedValues,
3131
{{/if}}
32-
} from "ts-sql-query/extras/types";
32+
} from "ts-sql-query/extras/types{{output.import.extension}}";
3333
{{/if}}
3434
{{#each imports}}
3535
{{#if isDefault}}
3636
{{#each imported}}
3737
{{#dedent-by 4 "level"}}
38-
import {{.}} from "{{../importPath}}";
38+
import {{.}} from "{{../importPath}}{{output.import.extension}}";
3939
{{/dedent-by}}
4040
{{/each}}
4141
{{else}}
@@ -46,7 +46,7 @@ import {
4646
{{.}},
4747
{{/each}}
4848
{{/dedent-by}}
49-
} from "{{importPath}}";
49+
} from "{{importPath}}{{output.import.extension}}";
5050
{{/dedent-by}}
5151
{{/if}}
5252
{{/each}}

0 commit comments

Comments
 (0)