fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #362 from hey-api/fix/deleting-whole-output-dir

fix: only delete generated files instead of whole output directory

authored by

Jordan Shatford and committed by
GitHub
974dd72b a4b0c22f

+27 -23
+5
.changeset/fuzzy-vans-leave.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: only delete generated files instead of whole output directory
+3 -3
packages/openapi-ts/src/compiler/index.ts
··· 1 - import { writeFileSync } from 'node:fs'; 1 + import { PathLike, writeFileSync } from 'node:fs'; 2 2 3 3 import ts from 'typescript'; 4 4 ··· 15 15 private _headers: Array<string> = []; 16 16 private _imports: Array<ts.Node> = []; 17 17 private _items: Array<ts.Node | string> = []; 18 - private _path: string; 18 + private _path: PathLike; 19 19 20 - public constructor(path: string, header: boolean = true) { 20 + public constructor({ path, header = true }: { path: PathLike; header?: boolean }) { 21 21 this._path = path; 22 22 if (header) { 23 23 const text = 'This file is auto-generated by @hey-api/openapi-ts';
+5 -14
packages/openapi-ts/src/utils/write/client.ts
··· 1 - import { mkdirSync, rmSync } from 'node:fs'; 1 + import { existsSync, mkdirSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 4 import type { OpenApi } from '../../openApi'; ··· 20 20 */ 21 21 export const writeClient = async (openApi: OpenApi, client: Client, templates: Templates): Promise<void> => { 22 22 const config = getConfig(); 23 - await rmSync(config.output, { 24 - force: true, 25 - recursive: true, 26 - }); 27 23 28 24 if (typeof config.exportServices === 'string') { 29 25 const regexp = new RegExp(config.exportServices); ··· 33 29 if (typeof config.exportModels === 'string') { 34 30 const regexp = new RegExp(config.exportModels); 35 31 client.models = client.models.filter(model => regexp.test(model.name)); 32 + } 33 + 34 + if (!existsSync(path.resolve(config.output))) { 35 + mkdirSync(path.resolve(config.output), { recursive: true }); 36 36 } 37 37 38 38 const sections = [ ··· 60 60 61 61 for (const section of sections) { 62 62 const sectionPath = path.resolve(config.output, section.dir); 63 - if (section.dir) { 64 - await rmSync(sectionPath, { 65 - force: true, 66 - recursive: true, 67 - }); 68 - } 69 - await mkdirSync(sectionPath, { 70 - recursive: true, 71 - }); 72 63 await section.fn(openApi, sectionPath, client, templates); 73 64 } 74 65
+9 -1
packages/openapi-ts/src/utils/write/core.ts
··· 1 - import { copyFileSync, existsSync, writeFileSync } from 'node:fs'; 1 + import { copyFileSync, existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; 2 2 import path from 'node:path'; 3 3 4 4 import type { OpenApi } from '../../openApi'; ··· 27 27 server: config.base !== undefined ? config.base : client.server, 28 28 version: client.version, 29 29 }; 30 + 31 + rmSync(path.resolve(outputPath), { 32 + force: true, 33 + recursive: true, 34 + }); 35 + mkdirSync(path.resolve(outputPath), { 36 + recursive: true, 37 + }); 30 38 31 39 if (config.exportCore) { 32 40 await writeFileSync(
+1 -1
packages/openapi-ts/src/utils/write/index.ts
··· 13 13 export const writeClientIndex = async (client: Client, outputPath: string): Promise<void> => { 14 14 const config = getConfig(); 15 15 16 - const fileIndex = new TypeScriptFile(path.resolve(outputPath, 'index.ts')); 16 + const fileIndex = new TypeScriptFile({ path: path.resolve(outputPath, 'index.ts') }); 17 17 18 18 if (config.name) { 19 19 fileIndex.add(compiler.export.named([config.name], `./${config.name}`));
+2 -2
packages/openapi-ts/src/utils/write/models.ts
··· 225 225 export const writeTypesAndEnums = async (openApi: OpenApi, outputPath: string, client: Client): Promise<void> => { 226 226 const config = getConfig(); 227 227 228 - const fileEnums = new TypeScriptFile(path.resolve(outputPath, 'enums.gen.ts')); 229 - const fileModels = new TypeScriptFile(path.resolve(outputPath, 'models.ts')); 228 + const fileEnums = new TypeScriptFile({ path: path.resolve(outputPath, 'enums.gen.ts') }); 229 + const fileModels = new TypeScriptFile({ path: path.resolve(outputPath, 'models.ts') }); 230 230 231 231 for (const model of client.models) { 232 232 processModel(client, model, (node, type) => {
+1 -1
packages/openapi-ts/src/utils/write/schemas.ts
··· 13 13 export const writeSchemas = async (openApi: OpenApi, outputPath: string): Promise<void> => { 14 14 const config = getConfig(); 15 15 16 - const fileSchemas = new TypeScriptFile(path.resolve(outputPath, 'schemas.ts')); 16 + const fileSchemas = new TypeScriptFile({ path: path.resolve(outputPath, 'schemas.ts') }); 17 17 18 18 const addSchema = (name: string, obj: any) => { 19 19 const validName = `$${ensureValidTypeScriptJavaScriptIdentifier(name)}`;
+1 -1
packages/openapi-ts/src/utils/write/services.ts
··· 22 22 ): Promise<void> => { 23 23 const config = getConfig(); 24 24 25 - const fileServices = new TypeScriptFile(path.resolve(outputPath, 'services.ts')); 25 + const fileServices = new TypeScriptFile({ path: path.resolve(outputPath, 'services.ts') }); 26 26 27 27 let imports: string[] = []; 28 28 let results: string[] = [];