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.

feat(generate): warn about missing dependencies used in generated client

authored by

Jordan Shatford and committed by
Jordan Shatford
18ffe36f f83279c2

+23 -1
+23 -1
src/index.ts
··· 18 18 // TODO: add support for `openapi-ts.config.ts` 19 19 const configFiles = ['openapi-ts.config.js', 'openapi-ts.config.cjs', 'openapi-ts.config.mjs']; 20 20 21 + // Mapping of all dependencies used in each client. These should be installed in the generated client package 22 + const clientDependencies: Record<Config['client'], string[]> = { 23 + angular: ['@angular/common', '@angular/core', 'rxjs'], 24 + axios: ['axios'], 25 + fetch: [], 26 + node: ['node-fetch'], 27 + xhr: [], 28 + }; 29 + 21 30 const processOutput = (config: Config, dependencies: Dependencies) => { 22 31 if (config.format) { 23 32 if (dependencies.prettier) { ··· 35 44 }; 36 45 37 46 const inferClient = (dependencies: Dependencies): Config['client'] => { 38 - if (dependencies['@angular/cli']) { 47 + if (Object.keys(dependencies).some(d => d.startsWith('@angular'))) { 39 48 return 'angular'; 40 49 } 41 50 if (dependencies.axios) { 42 51 return 'axios'; 43 52 } 53 + if (dependencies['node-fetch']) { 54 + return 'node'; 55 + } 44 56 return 'fetch'; 45 57 }; 46 58 ··· 56 68 return console.log('✨ Creating Node.js client'); 57 69 case 'xhr': 58 70 return console.log('✨ Creating XHR client'); 71 + } 72 + }; 73 + 74 + const logMissingDependenciesWarning = (client: Config['client'], dependencies: Dependencies) => { 75 + const missing = clientDependencies[client].filter(d => dependencies[d] === undefined); 76 + if (missing.length > 0) { 77 + console.log('⚠️ Dependencies used in generated client are missing: ' + missing.join(' ')); 59 78 } 60 79 }; 61 80 ··· 179 198 } 180 199 181 200 console.log('✨ Done! Your client is located in:', config.output); 201 + 202 + logMissingDependenciesWarning(config.client, dependencies); 203 + 182 204 return client; 183 205 } 184 206