Skip to content

Commit 74d4fbb

Browse files
committed
Expose tsPath to generate options
1 parent e88c600 commit 74d4fbb

7 files changed

Lines changed: 57 additions & 29 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@povio/openapi-codegen-cli",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "./dist/index.js",
55
"bin": {
66
"openapi-codegen": "./dist/sh.js"

src/commands/generate.command.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class GenerateOptions implements GenerateParams {
1717
@YargOption({ envAlias: "tsNamespaces", type: "boolean" })
1818
tsNamespaces?: boolean;
1919

20+
@YargOption({ envAlias: "tsPath" })
21+
tsPath?: string;
22+
2023
@YargOption({ envAlias: "splitByTags", type: "boolean" })
2124
splitByTags?: boolean;
2225

src/commands/generate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type GenerateParams = {
1919
| "input"
2020
| "output"
2121
| "tsNamespaces"
22+
| "tsPath"
2223
| "splitByTags"
2324
| "defaultTag"
2425
| "removeOperationPrefixEndingWith"

src/generators/const/options.const.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { GenerateType } from "src/generators/types/generate";
22
import { GenerateOptions } from "src/generators/types/options";
3-
import { TEMPLATE_IMPORTS } from "./deps.const";
3+
import { TEMPLATE_DATA_TS_PATH, TEMPLATE_IMPORTS } from "./deps.const";
44
import { ENUM_SUFFIX, SCHEMA_SUFFIX } from "./zod.const";
55

66
export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
@@ -13,6 +13,7 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
1313
excludePathRegex: "",
1414
excludeRedundantZodSchemas: true,
1515
tsNamespaces: true,
16+
tsPath: TEMPLATE_DATA_TS_PATH,
1617
importPath: "ts",
1718
configs: {
1819
[GenerateType.Models]: {
@@ -32,12 +33,8 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
3233
namespaceSuffix: "Acl",
3334
},
3435
},
35-
acl: true,
36-
checkAcl: true,
3736
standalone: false,
3837
baseUrl: "",
39-
abilityContextImportPath: TEMPLATE_IMPORTS.abilityContext,
40-
abilityContextGenericAppAbilities: false,
4138
// Zod options
4239
schemaSuffix: SCHEMA_SUFFIX,
4340
enumSuffix: ENUM_SUFFIX,
@@ -54,4 +51,9 @@ export const DEFAULT_GENERATE_OPTIONS: GenerateOptions = {
5451
axiosRequestConfig: false,
5552
infiniteQueries: false,
5653
mutationEffects: true,
54+
// ACL options
55+
acl: true,
56+
checkAcl: true,
57+
abilityContextImportPath: TEMPLATE_IMPORTS.abilityContext,
58+
abilityContextGenericAppAbilities: false,
5759
};

src/generators/types/options.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ interface QueriesGenerateOptions {
2424
axiosRequestConfig?: boolean;
2525
infiniteQueries?: boolean;
2626
mutationEffects?: boolean;
27+
}
28+
29+
interface ACLOptions {
30+
acl: boolean;
2731
checkAcl?: boolean;
32+
abilityContextImportPath: string;
33+
abilityContextGenericAppAbilities: boolean;
2834
}
2935

3036
interface GenerateConfig {
@@ -41,16 +47,15 @@ interface BaseGenerateOptions {
4147
excludePathRegex: string;
4248
excludeRedundantZodSchemas: boolean;
4349
tsNamespaces: boolean;
50+
tsPath: string;
4451
importPath: "ts" | "relative" | "absolute";
4552
configs: Record<GenerateType, GenerateConfig>;
46-
acl: boolean;
4753
standalone: boolean;
4854
baseUrl: string;
49-
abilityContextImportPath: string;
50-
abilityContextGenericAppAbilities: boolean;
5155
}
5256

5357
export type GenerateOptions = BaseGenerateOptions &
5458
ZodGenerateOptions &
5559
EndpointsGenerateOptions &
56-
QueriesGenerateOptions;
60+
QueriesGenerateOptions &
61+
ACLOptions;

src/generators/utils/generate/generate.imports.utils.test.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,38 @@ import { getImportPath } from "./generate.imports.utils";
33

44
describe("Utils: generate imports", () => {
55
test("getImportPath", () => {
6-
expect(getImportPath({ output: "output", importPath: "ts" })).toEqual("@/data/");
7-
expect(getImportPath({ output: "output", importPath: "relative" })).toEqual("../");
8-
expect(getImportPath({ output: "output", importPath: "absolute" })).toEqual("output/");
9-
expect(getImportPath({ output: "some-folder", importPath: "ts" })).toEqual("@/data/");
10-
expect(getImportPath({ output: "some-folder", importPath: "relative" })).toEqual("../");
11-
expect(getImportPath({ output: "some-folder", importPath: "absolute" })).toEqual("some-folder/");
12-
expect(getImportPath({ output: "src/data", importPath: "ts" })).toEqual("@/data/");
13-
expect(getImportPath({ output: "src/data", importPath: "relative" })).toEqual("../");
14-
expect(getImportPath({ output: "src/data", importPath: "absolute" })).toEqual("src/data/");
15-
expect(getImportPath({ output: "src/data/auto-gen", importPath: "ts" })).toEqual("@/data/auto-gen/");
16-
expect(getImportPath({ output: "src/data/auto-gen", importPath: "relative" })).toEqual("../");
17-
expect(getImportPath({ output: "src/data/auto-gen", importPath: "absolute" })).toEqual("src/data/auto-gen/");
18-
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "ts" })).toEqual("@/data/auto-gen/");
19-
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "relative" })).toEqual("../");
20-
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "absolute" })).toEqual(
6+
expect(getImportPath({ output: "output", importPath: "ts", tsPath: "@/data" })).toEqual("@/data/");
7+
expect(getImportPath({ output: "output", importPath: "ts", tsPath: "@/output" })).toEqual("@/output/");
8+
expect(getImportPath({ output: "output", importPath: "relative", tsPath: "@/data" })).toEqual("../");
9+
expect(getImportPath({ output: "output", importPath: "absolute", tsPath: "@/data" })).toEqual("output/");
10+
expect(getImportPath({ output: "some-folder", importPath: "ts", tsPath: "@/data" })).toEqual("@/data/");
11+
expect(getImportPath({ output: "some-folder", importPath: "ts", tsPath: "@/output" })).toEqual("@/output/");
12+
expect(getImportPath({ output: "some-folder", importPath: "relative", tsPath: "@/data" })).toEqual("../");
13+
expect(getImportPath({ output: "some-folder", importPath: "absolute", tsPath: "@/data" })).toEqual("some-folder/");
14+
expect(getImportPath({ output: "src/data", importPath: "ts", tsPath: "@/data" })).toEqual("@/data/");
15+
expect(getImportPath({ output: "src/data", importPath: "ts", tsPath: "@/output" })).toEqual("@/output/");
16+
expect(getImportPath({ output: "src/data", importPath: "relative", tsPath: "@/data" })).toEqual("../");
17+
expect(getImportPath({ output: "src/data", importPath: "absolute", tsPath: "@/data" })).toEqual("src/data/");
18+
expect(getImportPath({ output: "src/data/auto-gen", importPath: "ts", tsPath: "@/data" })).toEqual(
19+
"@/data/auto-gen/",
20+
);
21+
expect(getImportPath({ output: "src/data/auto-gen", importPath: "ts", tsPath: "@/output" })).toEqual(
22+
"@/output/auto-gen/",
23+
);
24+
expect(getImportPath({ output: "src/data/auto-gen", importPath: "relative", tsPath: "@/data" })).toEqual("../");
25+
expect(getImportPath({ output: "src/data/auto-gen", importPath: "absolute", tsPath: "@/data" })).toEqual(
26+
"src/data/auto-gen/",
27+
);
28+
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "ts", tsPath: "@/data" })).toEqual(
29+
"@/data/auto-gen/",
30+
);
31+
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "ts", tsPath: "@/output" })).toEqual(
32+
"@/output/auto-gen/",
33+
);
34+
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "relative", tsPath: "@/data" })).toEqual(
35+
"../",
36+
);
37+
expect(getImportPath({ output: "frontend/src/data/auto-gen", importPath: "absolute", tsPath: "@/data" })).toEqual(
2138
"frontend/src/data/auto-gen/",
2239
);
2340
});

src/generators/utils/generate/generate.imports.utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TEMPLATE_DATA_FILE_PATH, TEMPLATE_DATA_TS_PATH } from "src/generators/const/deps.const";
1+
import { TEMPLATE_DATA_FILE_PATH } from "src/generators/const/deps.const";
22
import { SchemaResolver } from "src/generators/core/SchemaResolver.class";
33
import { Endpoint } from "src/generators/types/endpoint";
44
import { GenerateType, Import } from "src/generators/types/generate";
@@ -110,14 +110,14 @@ export function getEntityImports({
110110
return Array.from(imports.values());
111111
}
112112

113-
export function getImportPath(options: Pick<GenerateOptions, "output" | "importPath">) {
114-
let importPath = TEMPLATE_DATA_TS_PATH;
113+
export function getImportPath(options: Pick<GenerateOptions, "output" | "importPath" | "tsPath">) {
114+
let importPath = options.tsPath;
115115
if (options.importPath === "relative") {
116116
importPath = "../";
117117
} else if (options.importPath === "absolute") {
118118
importPath = options.output;
119119
} else if (new RegExp(`${TEMPLATE_DATA_FILE_PATH}`, "g").test(options.output)) {
120-
importPath = options.output.replace(new RegExp(`.*${TEMPLATE_DATA_FILE_PATH}`, "g"), TEMPLATE_DATA_TS_PATH);
120+
importPath = options.output.replace(new RegExp(`.*${TEMPLATE_DATA_FILE_PATH}`, "g"), options.tsPath);
121121
}
122122
return `${importPath}/`.replace(/\/\//g, "/");
123123
}

0 commit comments

Comments
 (0)