Skip to content

Commit 097d0a1

Browse files
committed
feat: disable writing a log file via a --no-log-file flag
1 parent 93dad69 commit 097d0a1

File tree

4 files changed

+68
-55
lines changed

4 files changed

+68
-55
lines changed

packages/openapi-ts/bin/index.cjs

+5
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',

packages/openapi-ts/src/index.ts

+2-1
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+
const writeLogFile = config ? config.logFile : resolvedConfig?.logFile;
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' && writeLogFile) {
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/initConfigs.ts

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ export const initConfigs = async (
269269
dryRun = false,
270270
experimentalParser = true,
271271
exportCore = true,
272+
logFile = true,
272273
name,
273274
request,
274275
useOptions = true,
@@ -311,6 +312,7 @@ export const initConfigs = async (
311312
experimentalParser,
312313
exportCore: false,
313314
input,
315+
logFile,
314316
logs,
315317
name,
316318
output,

packages/openapi-ts/src/types/config.d.ts

+59-54
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ export interface UserConfig {
135135
| (string & {})
136136
| Record<string, unknown>
137137
| Input;
138+
/**
139+
* @deprecated
140+
*
141+
* Opt in to the experimental parser?
142+
*
143+
* @default true
144+
*/
145+
experimentalParser?: boolean;
146+
147+
/**
148+
* @deprecated
149+
*
150+
* Generate core client classes?
151+
*
152+
* @default true
153+
*/
154+
exportCore?: boolean;
138155
/**
139156
* The relative location of the logs folder
140157
*
@@ -175,6 +192,48 @@ export interface UserConfig {
175192
*/
176193
path?: string;
177194
};
195+
/**
196+
* Whether or not error logs should be written to a file or not
197+
* */
198+
logFile: boolean;
199+
/**
200+
* Regenerate the client when the input file changes? You can alternatively
201+
* pass a numeric value for the interval in ms.
202+
*
203+
* @default false
204+
*/
205+
watch?:
206+
| boolean
207+
| number
208+
| {
209+
/**
210+
* Regenerate the client when the input file changes?
211+
*
212+
* @default false
213+
*/
214+
enabled?: boolean;
215+
/**
216+
* How often should we attempt to detect the input file change? (in ms)
217+
*
218+
* @default 1000
219+
*/
220+
interval?: number;
221+
/**
222+
* How long will we wait before the request times out?
223+
*
224+
* @default 60_000
225+
*/
226+
timeout?: number;
227+
};
228+
/**
229+
* @deprecated
230+
*
231+
* Custom client class name. Please note this option is deprecated and
232+
* will be removed in favor of clients.
233+
*
234+
* @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name
235+
*/
236+
name?: string;
178237
/**
179238
* The relative location of the output folder
180239
*/
@@ -230,67 +289,13 @@ export interface UserConfig {
230289
* @default ['@hey-api/typescript', '@hey-api/sdk']
231290
*/
232291
plugins?: ReadonlyArray<UserPlugins['name'] | UserPlugins>;
233-
/**
234-
* Regenerate the client when the input file changes? You can alternatively
235-
* pass a numeric value for the interval in ms.
236-
*
237-
* @default false
238-
*/
239-
watch?:
240-
| boolean
241-
| number
242-
| {
243-
/**
244-
* Regenerate the client when the input file changes?
245-
*
246-
* @default false
247-
*/
248-
enabled?: boolean;
249-
/**
250-
* How often should we attempt to detect the input file change? (in ms)
251-
*
252-
* @default 1000
253-
*/
254-
interval?: number;
255-
/**
256-
* How long will we wait before the request times out?
257-
*
258-
* @default 60_000
259-
*/
260-
timeout?: number;
261-
};
262292
/**
263293
* @deprecated
264294
*
265295
* Manually set base in OpenAPI config instead of inferring from server value
266296
*/
267297
// eslint-disable-next-line typescript-sort-keys/interface
268298
base?: string;
269-
/**
270-
* @deprecated
271-
*
272-
* Opt in to the experimental parser?
273-
*
274-
* @default true
275-
*/
276-
experimentalParser?: boolean;
277-
/**
278-
* @deprecated
279-
*
280-
* Generate core client classes?
281-
*
282-
* @default true
283-
*/
284-
exportCore?: boolean;
285-
/**
286-
* @deprecated
287-
*
288-
* Custom client class name. Please note this option is deprecated and
289-
* will be removed in favor of clients.
290-
*
291-
* @link https://heyapi.dev/openapi-ts/migrating.html#deprecated-name
292-
*/
293-
name?: string;
294299
/**
295300
* @deprecated
296301
*

0 commit comments

Comments
 (0)