File tree Expand file tree Collapse file tree 5 files changed +64
-64
lines changed Expand file tree Collapse file tree 5 files changed +64
-64
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ generateApi({
100100 toJS: false ,
101101 extractRequestParams: false ,
102102 extractRequestBody: false ,
103- prettier: {
103+ prettier: { // By default prettier config is load from your project
104104 printWidth: 120 ,
105105 tabWidth: 2 ,
106106 trailingComma: " all" ,
Original file line number Diff line number Diff line change 5858 "@types/swagger-schema-official" : " 2.0.21" ,
5959 "axios" : " ^0.21.1" ,
6060 "commander" : " ^6.2.1" ,
61+ "cosmiconfig" : " ^7.0.0" ,
6162 "eta" : " ^1.12.1" ,
6263 "js-yaml" : " ^4.0.0" ,
6364 "lodash" : " ^4.17.21" ,
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ const { generateOutputFiles } = require("./output");
2121const formatFileContent = require ( "./formatFileContent" ) ;
2222const { logger } = require ( "./logger" ) ;
2323const { ComponentTypeNameResolver } = require ( "./utils/resolveName" ) ;
24+ const { getPrettierOptions } = require ( "./prettierOptions" ) ;
2425
2526module . exports = {
2627 constants : constants ,
@@ -46,7 +47,7 @@ module.exports = {
4647 defaultResponseType = config . defaultResponseType ,
4748 unwrapResponseData = config . unwrapResponseData ,
4849 singleHttpClient = config . singleHttpClient ,
49- prettier : prettierOptions = constants . PRETTIER_OPTIONS ,
50+ prettier : prettierOptions = getPrettierOptions ( ) ,
5051 hooks : rawHooks ,
5152 extraTemplates,
5253 enumNamesAsValues,
Original file line number Diff line number Diff line change 1+ const { cosmiconfigSync } = require ( "cosmiconfig" ) ;
2+ const constants = require ( "./constants" ) ;
3+
4+ /**
5+ * Get prettier options from user's project or return the default one
6+ * @return {import('prettier').Options } Prettier options
7+ */
8+ function getPrettierOptions ( ) {
9+ const prettier = cosmiconfigSync ( "prettier" ) . search ( ) ;
10+
11+ if ( prettier ) {
12+ return {
13+ ...prettier . config ,
14+ parser : "typescript" ,
15+ } ;
16+ }
17+
18+ return constants . PRETTIER_OPTIONS ;
19+ }
20+
21+ module . exports = {
22+ getPrettierOptions,
23+ } ;
You can’t perform that action at this time.
0 commit comments