Skip to content

Commit a479b2d

Browse files
authored
Merge branch 'acacode:main' into patch-2
2 parents 9fdcd04 + 28bb7fe commit a479b2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1469
-1984
lines changed

.envrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# shellcheck shell=bash
3+
export NODE_VERSIONS="${HOME}/.nvm/versions/node"
4+
export NODE_VERSION_PREFIX="v"
5+
use node
6+
layout node
7+
corepack enable

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- name: Set-up Node.js
1717
uses: actions/setup-node@v4
1818
with:
19-
node-version: 22
2019
check-latest: true
20+
node-version-file: .nvmrc
2121

2222
- run: corepack enable
2323

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
- name: Set-up Node.js
2323
uses: actions/setup-node@v4
2424
with:
25-
node-version: 22
2625
check-latest: true
26+
node-version-file: .nvmrc
2727

2828
- run: corepack enable
2929

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ Options:
3939
--js generate js api module with declaration file (default: false)
4040
--module-name-index <number> determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits) (default: 0)
4141
--module-name-first-tag splits routes based on the first tag (default: false)
42-
--disableStrictSSL disabled strict SSL (default: false)
43-
--disableProxy disabled proxy (default: false)
4442
--axios generate axios http client (default: false)
4543
--unwrap-response-data unwrap the data item from the response (default: false)
4644
--disable-throw-on-error Do not throw an error when response.ok is not true (default: false)
@@ -403,7 +401,7 @@ type PrimitiveTypeStructValue =
403401
| string
404402
| ((
405403
schema: Record<string, any>,
406-
parser: import("./src/schema-parser/schema-parser").SchemaParser,
404+
parser: import("./src/schema-parser/schema-parser").SchemaParser
407405
) => string);
408406

409407
type PrimitiveTypeStruct = Record<
@@ -416,7 +414,7 @@ type PrimitiveTypeStruct = Record<
416414
>;
417415

418416
declare const primitiveTypeConstructs: (
419-
struct: PrimitiveTypeStruct,
417+
struct: PrimitiveTypeStruct
420418
) => Partial<PrimitiveTypeStruct>;
421419

422420
generateApi({

index.ts

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as path from "node:path";
2+
import * as url from "node:url";
23
import { defineCommand, runMain } from "citty";
34
import { consola } from "consola";
45
import packageJson from "./package.json" with { type: "json" };
@@ -53,6 +54,9 @@ const generateTemplatesCommand = defineCommand({
5354
},
5455
},
5556
run: async ({ args }) => {
57+
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
58+
if (args.silent) consola.level = 0;
59+
5660
await generateTemplates({
5761
cleanOutput: args["clean-output"],
5862
httpClientType: args["http-client"],
@@ -175,27 +179,17 @@ const generateCommand = defineCommand({
175179
type: "string",
176180
description:
177181
"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",
178-
default: codeGenBaseConfig.moduleNameIndex,
182+
default: codeGenBaseConfig.moduleNameIndex.toString(),
179183
},
180184
"module-name-first-tag": {
181185
type: "boolean",
182186
description: "splits routes based on the first tag",
183187
default: codeGenBaseConfig.moduleNameFirstTag,
184188
},
185-
disableStrictSSL: {
186-
type: "boolean",
187-
description: "disabled strict SSL",
188-
default: codeGenBaseConfig.disableStrictSSL,
189-
},
190-
disableProxy: {
191-
type: "boolean",
192-
description: "disabled proxy",
193-
default: codeGenBaseConfig.disableProxy,
194-
},
195189
axios: {
196190
type: "boolean",
197191
description: "generate axios http client",
198-
default: codeGenBaseConfig.httpClientType === HTTP_CLIENT.AXIOS,
192+
default: false,
199193
},
200194
"unwrap-response-data": {
201195
type: "boolean",
@@ -223,12 +217,12 @@ const generateCommand = defineCommand({
223217
default: codeGenBaseConfig.defaultResponseType,
224218
},
225219
"type-prefix": {
226-
type: "boolean",
220+
type: "string",
227221
description: "data contract name prefix",
228222
default: codeGenBaseConfig.typePrefix,
229223
},
230224
"type-suffix": {
231-
type: "boolean",
225+
type: "string",
232226
description: "data contract name suffix",
233227
default: codeGenBaseConfig.typeSuffix,
234228
},
@@ -277,27 +271,29 @@ const generateCommand = defineCommand({
277271
"custom-config": {
278272
type: "string",
279273
description: "custom config: primitiveTypeConstructs, hooks, ... ",
280-
default: "",
281274
},
282275
},
283276
run: async ({ args }) => {
284-
let customConfig = null;
285-
let customConfigPath: string | undefined;
277+
if (args.debug) consola.level = Number.MAX_SAFE_INTEGER;
278+
if (args.silent) consola.level = 0;
279+
280+
let customConfig;
286281

287282
if (args["custom-config"]) {
288283
try {
289-
customConfigPath = path.resolve(process.cwd(), args["custom-config"]);
284+
const customConfigPath = url
285+
.pathToFileURL(path.resolve(process.cwd(), args["custom-config"]))
286+
.toString();
290287
customConfig = await import(customConfigPath);
291288
customConfig = customConfig.default || customConfig;
289+
if (customConfig) {
290+
consola.info(`Found custom config at: ${customConfigPath}`);
291+
}
292292
} catch (error) {
293293
consola.error("Error loading custom config:", error);
294294
}
295295
}
296296

297-
if (customConfig) {
298-
consola.info(`Found custom config at: ${customConfigPath}`);
299-
}
300-
301297
await generateApi({
302298
addReadonly: args["add-readonly"],
303299
anotherArrayType: args["another-array-type"],
@@ -306,8 +302,6 @@ const generateCommand = defineCommand({
306302
debug: args.debug,
307303
defaultResponseAsSuccess: args["default-as-success"],
308304
defaultResponseType: args["default-response"],
309-
disableProxy: args.disableProxy,
310-
disableStrictSSL: args.disableStrictSSL,
311305
disableThrowOnError: args["disable-throw-on-error"],
312306
enumNamesAsValues: args["enum-names-as-values"],
313307
extractEnums: args["extract-enums"],
@@ -325,11 +319,11 @@ const generateCommand = defineCommand({
325319
args["http-client"] || args.axios
326320
? HTTP_CLIENT.AXIOS
327321
: HTTP_CLIENT.FETCH,
328-
input: path.resolve(process.cwd(), args.path),
322+
input: path.resolve(process.cwd(), args.path as string),
329323
modular: args.modular,
330324
moduleNameFirstTag: args["module-name-first-tag"],
331325
moduleNameIndex: +args["module-name-index"] || 0,
332-
output: path.resolve(process.cwd(), args.output || "."),
326+
output: path.resolve(process.cwd(), (args.output as string) || "."),
333327
patch: args.patch,
334328
silent: args.silent,
335329
singleHttpClient: args["single-http-client"],

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,26 @@
5353
"eta": "^2.2.0",
5454
"js-yaml": "^4.1.0",
5555
"lodash": "^4.17.21",
56-
"nanoid": "^3.3.7",
57-
"prettier": "~3.3.3",
56+
"nanoid": "^5.0.9",
57+
"prettier": "~3.4.1",
5858
"swagger-schema-official": "2.0.0-bab6bed",
5959
"swagger2openapi": "^7.0.8",
60-
"typescript": "~5.6.2"
60+
"typescript": "~5.7.2"
6161
},
6262
"devDependencies": {
63-
"@biomejs/biome": "1.9.2",
63+
"@biomejs/biome": "1.9.4",
6464
"@tsconfig/node18": "18.2.4",
6565
"@tsconfig/strictest": "2.0.5",
6666
"@types/js-yaml": "4.0.9",
67-
"@types/lodash": "4.17.7",
68-
"@types/node": "22.5.5",
67+
"@types/lodash": "4.17.13",
68+
"@types/node": "22.10.1",
6969
"@types/swagger2openapi": "7.0.4",
70-
"axios": "1.7.7",
71-
"tsup": "8.3.0",
72-
"vitest": "2.1.1"
70+
"axios": "1.7.8",
71+
"openapi-types": "12.1.3",
72+
"tsup": "8.3.5",
73+
"vitest": "2.1.6"
7374
},
74-
"packageManager": "[email protected].0",
75+
"packageManager": "[email protected].1",
7576
"engines": {
7677
"node": ">=18.0.0"
7778
},

src/code-formatter.js renamed to src/code-formatter.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import * as prettier from "prettier";
22
import * as typescript from "typescript";
3+
import type { CodeGenConfig } from "./configuration.js";
34

4-
class CodeFormatter {
5-
/**
6-
* @type {CodeGenConfig}
7-
*/
8-
config;
5+
export class CodeFormatter {
6+
config: CodeGenConfig;
97

10-
constructor({ config }) {
8+
constructor(config: CodeGenConfig) {
119
this.config = config;
1210
}
1311

14-
removeUnusedImports = (content) => {
12+
removeUnusedImports = (content: string) => {
1513
const tempFileName = "file.ts";
1614

1715
const host = new TsLanguageServiceHost(tempFileName, content);
@@ -20,6 +18,7 @@ class CodeFormatter {
2018
const fileTextChanges = languageService.organizeImports(
2119
{ type: "file", fileName: tempFileName },
2220
{ newLineCharacter: typescript.sys.newLine },
21+
undefined,
2322
)[0];
2423

2524
if (fileTextChanges?.textChanges.length) {
@@ -35,11 +34,7 @@ class CodeFormatter {
3534
return content;
3635
};
3736

38-
/**
39-
* @param content
40-
* @returns {Promise<string>}
41-
*/
42-
prettierFormat = async (content) => {
37+
prettierFormat = async (content: string) => {
4338
const formatted = await prettier.format(
4439
content,
4540
this.config.prettierOptions,
@@ -48,7 +43,7 @@ class CodeFormatter {
4843
};
4944

5045
formatCode = async (
51-
code,
46+
code: string,
5247
{ removeUnusedImports = true, prettierFormat = true } = {},
5348
) => {
5449
if (removeUnusedImports) {
@@ -62,22 +57,24 @@ class CodeFormatter {
6257
}
6358

6459
class TsLanguageServiceHost {
65-
constructor(fileName, content) {
60+
fileName: string;
61+
content: string;
62+
compilerOptions: typescript.CompilerOptions;
63+
64+
constructor(fileName: string, content: string) {
65+
this.fileName = fileName;
66+
this.content = content;
6667
const tsconfig = typescript.findConfigFile(
6768
fileName,
6869
typescript.sys.fileExists,
6970
);
70-
71-
Object.assign(this, {
72-
fileName,
73-
content,
74-
compilerOptions: tsconfig
75-
? typescript.convertCompilerOptionsFromJson(
76-
typescript.readConfigFile(tsconfig, typescript.sys.readFile).config
77-
.compilerOptions,
78-
).options
79-
: typescript.getDefaultCompilerOptions(),
80-
});
71+
this.compilerOptions = tsconfig
72+
? typescript.convertCompilerOptionsFromJson(
73+
typescript.readConfigFile(tsconfig, typescript.sys.readFile).config
74+
.compilerOptions,
75+
"",
76+
).options
77+
: typescript.getDefaultCompilerOptions();
8178
}
8279

8380
getNewLine() {
@@ -101,16 +98,14 @@ class TsLanguageServiceHost {
10198
getScriptSnapshot() {
10299
return typescript.ScriptSnapshot.fromString(this.content);
103100
}
104-
readFile(fileName, encoding) {
101+
readFile(fileName: string, encoding: string) {
105102
if (fileName === this.fileName) {
106103
return this.content;
107104
}
108105

109106
return typescript.sys.readFile(fileName, encoding);
110107
}
111-
fileExists(path) {
108+
fileExists(path: string) {
112109
return typescript.sys.fileExists(path);
113110
}
114111
}
115-
116-
export { CodeFormatter };

0 commit comments

Comments
 (0)