Skip to content

Commit 069bb0d

Browse files
authored
Merge pull request #1877 from Matsuuu/main
feat: disable writing a log file via a --no-log-file flag
2 parents c557e04 + 158d1e1 commit 069bb0d

File tree

15 files changed

+39
-1
lines changed

15 files changed

+39
-1
lines changed

.changeset/dull-pianos-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
feat: ability to disable writing a log file via a `--no-log-file` flag or `logs.file` = `false`

packages/openapi-ts/bin/index.cjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ const params = program
3434
'DEPRECATED. Manually set base in OpenAPI config instead of inferring from server value',
3535
)
3636
.option('-s, --silent', 'Set log level to silent')
37+
.option(
38+
'--no-log-file',
39+
'Disable writing a log file. Works like --silent but without supressing console output',
40+
)
3741
.option(
3842
'-w, --watch [value]',
3943
'Regenerate the client when the input file changes?',
@@ -83,6 +87,7 @@ async function start() {
8387

8488
userConfig = processParams(params, [
8589
'dryRun',
90+
'logFile',
8691
'experimentalParser',
8792
'exportCore',
8893
'useOptions',
@@ -113,6 +118,8 @@ async function start() {
113118
userConfig.logs.level = 'silent';
114119
}
115120

121+
userConfig.logs.file = userConfig.logFile;
122+
116123
if (typeof params.watch === 'string') {
117124
userConfig.watch = Number.parseInt(params.watch, 10);
118125
}

packages/openapi-ts/src/generate/__tests__/class.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('generateLegacyClientClass', () => {
2020
path: '',
2121
},
2222
logs: {
23+
file: true,
2324
level: 'info',
2425
path: process.cwd(),
2526
},

packages/openapi-ts/src/generate/__tests__/core.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('generateLegacyCore', () => {
3535
path: '',
3636
},
3737
logs: {
38+
file: true,
3839
level: 'info',
3940
path: process.cwd(),
4041
},
@@ -127,6 +128,7 @@ describe('generateLegacyCore', () => {
127128
path: '',
128129
},
129130
logs: {
131+
file: true,
130132
level: 'info',
131133
path: process.cwd(),
132134
},
@@ -202,6 +204,7 @@ describe('generateLegacyCore', () => {
202204
path: '',
203205
},
204206
logs: {
207+
file: true,
205208
level: 'info',
206209
path: process.cwd(),
207210
},

packages/openapi-ts/src/generate/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('generateIndexFile', () => {
2020
path: '',
2121
},
2222
logs: {
23+
file: true,
2324
level: 'info',
2425
path: process.cwd(),
2526
},

packages/openapi-ts/src/generate/__tests__/output.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('generateLegacyOutput', () => {
2121
path: '',
2222
},
2323
logs: {
24+
file: true,
2425
level: 'info',
2526
path: process.cwd(),
2627
},

packages/openapi-ts/src/getLogs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Config, UserConfig } from './types/config';
22

33
export const getLogs = (userConfig: UserConfig | undefined): Config['logs'] => {
44
let logs: Config['logs'] = {
5+
file: true,
56
level: 'info',
67
path: process.cwd(),
78
};

packages/openapi-ts/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ export const createClient = async (
6767
} catch (error) {
6868
const config = configs[0] as Config | undefined;
6969
const dryRun = config ? config.dryRun : resolvedConfig?.dryRun;
70+
7071
// TODO: add setting for log output
7172
if (!dryRun) {
7273
const logs = config?.logs ?? getLogs(resolvedConfig);
73-
if (logs.level !== 'silent') {
74+
if (logs.level !== 'silent' && logs.file) {
7475
const logName = `openapi-ts-error-${Date.now()}.log`;
7576
const logsDir = path.resolve(process.cwd(), logs.path ?? '');
7677
ensureDirSync(logsDir);

packages/openapi-ts/src/openApi/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vi.mock('../3.1.x', () => ({
1818
vi.mock('../../utils/config', () => {
1919
const config: Partial<Config> = {
2020
logs: {
21+
file: false,
2122
level: 'silent',
2223
path: '',
2324
},

packages/openapi-ts/src/plugins/@hey-api/schemas/__tests__/schemas.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('generateLegacySchemas', () => {
2121
path: '',
2222
},
2323
logs: {
24+
file: true,
2425
level: 'info',
2526
path: process.cwd(),
2627
},
@@ -109,6 +110,7 @@ describe('generateLegacySchemas', () => {
109110
path: '',
110111
},
111112
logs: {
113+
file: true,
112114
level: 'info',
113115
path: process.cwd(),
114116
},

0 commit comments

Comments
 (0)