swagger-typescript-api 10.0.0 → 10.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +284 -260
- package/index.d.ts +7 -1
- package/index.js +115 -115
- package/package.json +116 -113
- package/src/apiConfig.js +30 -30
- package/src/common.js +28 -28
- package/src/components.js +3 -5
- package/src/config.js +4 -0
- package/src/constants.js +7 -0
- package/src/filePrefix.js +14 -14
- package/src/files.js +6 -6
- package/src/formatFileContent.js +13 -6
- package/src/index.js +271 -270
- package/src/logger.js +59 -59
- package/src/modelNames.js +78 -78
- package/src/modelTypes.js +31 -30
- package/src/output.js +165 -166
- package/src/prettierOptions.js +23 -23
- package/src/render/utils/fmtToJSDocLine.js +10 -10
- package/src/render/utils/index.js +31 -23
- package/src/render/utils/templateRequire.js +17 -17
- package/src/routeNames.js +46 -46
- package/src/routes.js +4 -1
- package/src/schema.js +87 -64
- package/src/swagger.js +4 -1
- package/src/templates.js +155 -132
- package/src/translators/JavaScript.js +60 -60
- package/src/typeFormatters.js +121 -75
- package/src/utils/id.js +9 -9
- package/src/utils/random.js +14 -14
- package/src/utils/resolveName.js +97 -97
- package/templates/README.md +17 -13
- package/templates/base/README.md +7 -7
- package/templates/base/data-contract-jsdoc.ejs +32 -0
- package/templates/base/data-contracts.ejs +28 -0
- package/templates/base/enum-data-contract.ejs +15 -0
- package/templates/base/{http-client.eta → http-client.ejs} +2 -2
- package/templates/base/http-clients/{axios-http-client.eta → axios-http-client.ejs} +133 -145
- package/templates/base/http-clients/{fetch-http-client.eta → fetch-http-client.ejs} +222 -222
- package/templates/base/interface-data-contract.ejs +10 -0
- package/templates/base/object-field-jsdoc.ejs +28 -0
- package/templates/base/{route-docs.eta → route-docs.ejs} +31 -31
- package/templates/base/{route-name.eta → route-name.ejs} +42 -42
- package/templates/base/{route-type.eta → route-type.ejs} +21 -21
- package/templates/base/type-data-contract.ejs +15 -0
- package/templates/default/README.md +6 -6
- package/templates/default/{api.eta → api.ejs} +65 -65
- package/templates/default/{procedure-call.eta → procedure-call.ejs} +98 -98
- package/templates/default/{route-types.eta → route-types.ejs} +28 -28
- package/templates/modular/README.md +6 -6
- package/templates/modular/{api.eta → api.ejs} +28 -28
- package/templates/modular/{procedure-call.eta → procedure-call.ejs} +98 -98
- package/templates/modular/{route-types.eta → route-types.ejs} +18 -18
- package/CHANGELOG.md +0 -866
- package/templates/base/data-contracts.eta +0 -45
package/src/index.js
CHANGED
|
@@ -1,270 +1,271 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// Copyright (c) 2019-present acacode
|
|
4
|
-
// Node module: swagger-typescript-api
|
|
5
|
-
// This file is licensed under the MIT License.
|
|
6
|
-
// License text available at https://opensource.org/licenses/MIT
|
|
7
|
-
// Repository https://github.com/acacode/swagger-typescript-api
|
|
8
|
-
|
|
9
|
-
const _ = require("lodash");
|
|
10
|
-
const { parseSchemas } = require("./schema");
|
|
11
|
-
const { parseRoutes, groupRoutes } = require("./routes");
|
|
12
|
-
const { createApiConfig } = require("./apiConfig");
|
|
13
|
-
const { prepareModelType } = require("./modelTypes");
|
|
14
|
-
const { getSwaggerObject, fixSwaggerScheme, convertSwaggerObject } = require("./swagger");
|
|
15
|
-
const { createComponentsMap, filterComponentsMap } = require("./components");
|
|
16
|
-
const { createFile, pathIsExist, pathIsDir, createDir, cleanDir } = require("./files");
|
|
17
|
-
const { addToConfig, config } = require("./config");
|
|
18
|
-
const { getTemplates, getTemplatePaths, renderTemplate, getTemplate } = require("./templates");
|
|
19
|
-
const constants = require("./constants");
|
|
20
|
-
const { generateOutputFiles } = require("./output");
|
|
21
|
-
const formatFileContent = require("./formatFileContent");
|
|
22
|
-
const { logger } = require("./logger");
|
|
23
|
-
const { ComponentTypeNameResolver } = require("./utils/resolveName");
|
|
24
|
-
const { getPrettierOptions } = require("./prettierOptions");
|
|
25
|
-
|
|
26
|
-
module.exports = {
|
|
27
|
-
constants: constants,
|
|
28
|
-
generateApi: ({
|
|
29
|
-
input,
|
|
30
|
-
output,
|
|
31
|
-
url,
|
|
32
|
-
spec,
|
|
33
|
-
name: fileName,
|
|
34
|
-
toJS: translateToJavaScript = config.toJS,
|
|
35
|
-
modular,
|
|
36
|
-
templates,
|
|
37
|
-
generateResponses = config.generateResponses,
|
|
38
|
-
defaultResponseAsSuccess = config.defaultResponseAsSuccess,
|
|
39
|
-
generateRouteTypes = config.generateRouteTypes,
|
|
40
|
-
generateClient = config.generateClient,
|
|
41
|
-
httpClientType = config.httpClientType,
|
|
42
|
-
generateUnionEnums = config.generateUnionEnums,
|
|
43
|
-
addReadonly = config.addReadonly,
|
|
44
|
-
moduleNameIndex = config.moduleNameIndex,
|
|
45
|
-
moduleNameFirstTag = config.moduleNameFirstTag,
|
|
46
|
-
extractRequestParams = config.extractRequestParams,
|
|
47
|
-
extractRequestBody = config.extractRequestBody,
|
|
48
|
-
extractResponseBody = config.extractResponseBody,
|
|
49
|
-
extractResponseError = config.extractResponseError,
|
|
50
|
-
defaultResponseType = config.defaultResponseType,
|
|
51
|
-
unwrapResponseData = config.unwrapResponseData,
|
|
52
|
-
disableThrowOnError = config.disableThrowOnError,
|
|
53
|
-
sortTypes = config.sortTypes,
|
|
54
|
-
singleHttpClient = config.singleHttpClient,
|
|
55
|
-
prettier: prettierOptions = getPrettierOptions(),
|
|
56
|
-
hooks: rawHooks,
|
|
57
|
-
extraTemplates,
|
|
58
|
-
enumNamesAsValues,
|
|
59
|
-
disableStrictSSL = config.disableStrictSSL,
|
|
60
|
-
disableProxy = config.disableProxy,
|
|
61
|
-
cleanOutput,
|
|
62
|
-
silent = config.silent,
|
|
63
|
-
typePrefix = config.typePrefix,
|
|
64
|
-
typeSuffix = config.typeSuffix,
|
|
65
|
-
patch = config.patch,
|
|
66
|
-
authorizationToken,
|
|
67
|
-
apiClassName = config.apiClassName,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
...require("./
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Copyright (c) 2019-present acacode
|
|
4
|
+
// Node module: swagger-typescript-api
|
|
5
|
+
// This file is licensed under the MIT License.
|
|
6
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
7
|
+
// Repository https://github.com/acacode/swagger-typescript-api
|
|
8
|
+
|
|
9
|
+
const _ = require("lodash");
|
|
10
|
+
const { parseSchemas } = require("./schema");
|
|
11
|
+
const { parseRoutes, groupRoutes } = require("./routes");
|
|
12
|
+
const { createApiConfig } = require("./apiConfig");
|
|
13
|
+
const { prepareModelType } = require("./modelTypes");
|
|
14
|
+
const { getSwaggerObject, fixSwaggerScheme, convertSwaggerObject } = require("./swagger");
|
|
15
|
+
const { createComponentsMap, filterComponentsMap } = require("./components");
|
|
16
|
+
const { createFile, pathIsExist, pathIsDir, createDir, cleanDir } = require("./files");
|
|
17
|
+
const { addToConfig, config } = require("./config");
|
|
18
|
+
const { getTemplates, getTemplatePaths, renderTemplate, getTemplate } = require("./templates");
|
|
19
|
+
const constants = require("./constants");
|
|
20
|
+
const { generateOutputFiles } = require("./output");
|
|
21
|
+
const formatFileContent = require("./formatFileContent");
|
|
22
|
+
const { logger } = require("./logger");
|
|
23
|
+
const { ComponentTypeNameResolver } = require("./utils/resolveName");
|
|
24
|
+
const { getPrettierOptions } = require("./prettierOptions");
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
constants: constants,
|
|
28
|
+
generateApi: ({
|
|
29
|
+
input,
|
|
30
|
+
output,
|
|
31
|
+
url,
|
|
32
|
+
spec,
|
|
33
|
+
name: fileName,
|
|
34
|
+
toJS: translateToJavaScript = config.toJS,
|
|
35
|
+
modular,
|
|
36
|
+
templates,
|
|
37
|
+
generateResponses = config.generateResponses,
|
|
38
|
+
defaultResponseAsSuccess = config.defaultResponseAsSuccess,
|
|
39
|
+
generateRouteTypes = config.generateRouteTypes,
|
|
40
|
+
generateClient = config.generateClient,
|
|
41
|
+
httpClientType = config.httpClientType,
|
|
42
|
+
generateUnionEnums = config.generateUnionEnums,
|
|
43
|
+
addReadonly = config.addReadonly,
|
|
44
|
+
moduleNameIndex = config.moduleNameIndex,
|
|
45
|
+
moduleNameFirstTag = config.moduleNameFirstTag,
|
|
46
|
+
extractRequestParams = config.extractRequestParams,
|
|
47
|
+
extractRequestBody = config.extractRequestBody,
|
|
48
|
+
extractResponseBody = config.extractResponseBody,
|
|
49
|
+
extractResponseError = config.extractResponseError,
|
|
50
|
+
defaultResponseType = config.defaultResponseType,
|
|
51
|
+
unwrapResponseData = config.unwrapResponseData,
|
|
52
|
+
disableThrowOnError = config.disableThrowOnError,
|
|
53
|
+
sortTypes = config.sortTypes,
|
|
54
|
+
singleHttpClient = config.singleHttpClient,
|
|
55
|
+
prettier: prettierOptions = getPrettierOptions(),
|
|
56
|
+
hooks: rawHooks,
|
|
57
|
+
extraTemplates,
|
|
58
|
+
enumNamesAsValues,
|
|
59
|
+
disableStrictSSL = config.disableStrictSSL,
|
|
60
|
+
disableProxy = config.disableProxy,
|
|
61
|
+
cleanOutput,
|
|
62
|
+
silent = config.silent,
|
|
63
|
+
typePrefix = config.typePrefix,
|
|
64
|
+
typeSuffix = config.typeSuffix,
|
|
65
|
+
patch = config.patch,
|
|
66
|
+
authorizationToken,
|
|
67
|
+
apiClassName = config.apiClassName,
|
|
68
|
+
debug = config.debug,
|
|
69
|
+
}) =>
|
|
70
|
+
new Promise((resolve, reject) => {
|
|
71
|
+
addToConfig({
|
|
72
|
+
defaultResponseAsSuccess,
|
|
73
|
+
generateRouteTypes,
|
|
74
|
+
generateClient,
|
|
75
|
+
httpClientType,
|
|
76
|
+
generateResponses,
|
|
77
|
+
templates,
|
|
78
|
+
generateUnionEnums,
|
|
79
|
+
addReadonly,
|
|
80
|
+
moduleNameIndex,
|
|
81
|
+
moduleNameFirstTag,
|
|
82
|
+
prettierOptions,
|
|
83
|
+
modular,
|
|
84
|
+
extractRequestParams,
|
|
85
|
+
extractRequestBody,
|
|
86
|
+
extractResponseBody,
|
|
87
|
+
extractResponseError,
|
|
88
|
+
hooks: _.merge(config.hooks, rawHooks || {}),
|
|
89
|
+
enumNamesAsValues,
|
|
90
|
+
disableStrictSSL,
|
|
91
|
+
disableProxy,
|
|
92
|
+
cleanOutput,
|
|
93
|
+
defaultResponseType,
|
|
94
|
+
unwrapResponseData,
|
|
95
|
+
disableThrowOnError,
|
|
96
|
+
sortTypes,
|
|
97
|
+
singleHttpClient,
|
|
98
|
+
constants,
|
|
99
|
+
silent,
|
|
100
|
+
toJS: translateToJavaScript,
|
|
101
|
+
typePrefix,
|
|
102
|
+
typeSuffix,
|
|
103
|
+
patch,
|
|
104
|
+
apiClassName,
|
|
105
|
+
debug,
|
|
106
|
+
});
|
|
107
|
+
(spec
|
|
108
|
+
? convertSwaggerObject(spec, { patch })
|
|
109
|
+
: getSwaggerObject(input, url, disableStrictSSL, disableProxy, authorizationToken, { patch })
|
|
110
|
+
)
|
|
111
|
+
.then(({ usageSchema, originalSchema }) => {
|
|
112
|
+
const templatePaths = getTemplatePaths(config);
|
|
113
|
+
|
|
114
|
+
addToConfig({ templatePaths });
|
|
115
|
+
|
|
116
|
+
const templatesToRender = getTemplates(config);
|
|
117
|
+
|
|
118
|
+
logger.event("start generating your typescript api");
|
|
119
|
+
|
|
120
|
+
fixSwaggerScheme(usageSchema, originalSchema);
|
|
121
|
+
|
|
122
|
+
addToConfig({
|
|
123
|
+
swaggerSchema: usageSchema,
|
|
124
|
+
originalSchema,
|
|
125
|
+
templatesToRender,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const { components } = usageSchema;
|
|
129
|
+
|
|
130
|
+
addToConfig(config.hooks.onInit(config) || config);
|
|
131
|
+
|
|
132
|
+
const componentsMap = createComponentsMap(components);
|
|
133
|
+
|
|
134
|
+
const componentSchemasNames = filterComponentsMap(componentsMap, "schemas").map((c) => c.typeName);
|
|
135
|
+
|
|
136
|
+
addToConfig({
|
|
137
|
+
componentTypeNameResolver: new ComponentTypeNameResolver(componentSchemasNames),
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const parsedSchemas = parseSchemas(components);
|
|
141
|
+
|
|
142
|
+
config.routeNameDuplicatesMap.clear();
|
|
143
|
+
|
|
144
|
+
const routes = parseRoutes({
|
|
145
|
+
usageSchema,
|
|
146
|
+
parsedSchemas,
|
|
147
|
+
moduleNameIndex,
|
|
148
|
+
moduleNameFirstTag,
|
|
149
|
+
extractRequestParams,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const hasSecurityRoutes = routes.some((route) => route.security);
|
|
153
|
+
const hasQueryRoutes = routes.some((route) => route.hasQuery);
|
|
154
|
+
const hasFormDataRoutes = routes.some((route) => route.hasFormDataParams);
|
|
155
|
+
|
|
156
|
+
const usageComponentSchemas = filterComponentsMap(componentsMap, "schemas");
|
|
157
|
+
const sortByProperty = (propertyName) => (o1, o2) => {
|
|
158
|
+
if (o1[propertyName] > o2[propertyName]) {
|
|
159
|
+
return 1;
|
|
160
|
+
}
|
|
161
|
+
if (o1[propertyName] < o2[propertyName]) {
|
|
162
|
+
return -1;
|
|
163
|
+
}
|
|
164
|
+
return 0;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const sortSchemas = (schemas) => {
|
|
168
|
+
if (config.sortTypes) {
|
|
169
|
+
return schemas.sort(sortByProperty("typeName")).map((schema) => {
|
|
170
|
+
if (schema.rawTypeData?.properties) {
|
|
171
|
+
return {
|
|
172
|
+
...schema,
|
|
173
|
+
rawTypeData: {
|
|
174
|
+
...schema.rawTypeData,
|
|
175
|
+
$parsed: schema.rawTypeData["$parsed"] && {
|
|
176
|
+
...schema.rawTypeData["$parsed"],
|
|
177
|
+
content: Array.isArray(schema.rawTypeData["$parsed"].content)
|
|
178
|
+
? schema.rawTypeData["$parsed"].content.sort(sortByProperty("name"))
|
|
179
|
+
: schema.rawTypeData["$parsed"].content,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return schema;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return schemas;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const rawConfiguration = {
|
|
191
|
+
apiConfig: createApiConfig(usageSchema),
|
|
192
|
+
config,
|
|
193
|
+
modelTypes: _.map(sortSchemas(usageComponentSchemas), prepareModelType),
|
|
194
|
+
rawModelTypes: usageComponentSchemas,
|
|
195
|
+
hasFormDataRoutes,
|
|
196
|
+
hasSecurityRoutes,
|
|
197
|
+
hasQueryRoutes,
|
|
198
|
+
generateResponses,
|
|
199
|
+
routes: groupRoutes(routes),
|
|
200
|
+
extraTemplates,
|
|
201
|
+
fileName,
|
|
202
|
+
translateToJavaScript,
|
|
203
|
+
utils: {
|
|
204
|
+
...require("./render/utils"),
|
|
205
|
+
...require("./common"),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const configuration = config.hooks.onPrepareConfig(rawConfiguration) || rawConfiguration;
|
|
210
|
+
|
|
211
|
+
if (pathIsExist(output)) {
|
|
212
|
+
if (cleanOutput) {
|
|
213
|
+
cleanDir(output);
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
createDir(output);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const files = generateOutputFiles({
|
|
220
|
+
modular,
|
|
221
|
+
templatesToRender,
|
|
222
|
+
configuration,
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const isDirPath = pathIsDir(output);
|
|
226
|
+
|
|
227
|
+
const generatedFiles = files.map((file) => {
|
|
228
|
+
if (!isDirPath) return file;
|
|
229
|
+
|
|
230
|
+
if (translateToJavaScript) {
|
|
231
|
+
createFile({
|
|
232
|
+
path: output,
|
|
233
|
+
fileName: file.name,
|
|
234
|
+
content: file.content,
|
|
235
|
+
withPrefix: true,
|
|
236
|
+
});
|
|
237
|
+
createFile({
|
|
238
|
+
path: output,
|
|
239
|
+
fileName: file.declaration.name,
|
|
240
|
+
content: file.declaration.content,
|
|
241
|
+
withPrefix: true,
|
|
242
|
+
});
|
|
243
|
+
logger.success(`javascript api file`, file.name, `created in ${output}`);
|
|
244
|
+
} else {
|
|
245
|
+
createFile({
|
|
246
|
+
path: output,
|
|
247
|
+
fileName: file.name,
|
|
248
|
+
content: file.content,
|
|
249
|
+
withPrefix: true,
|
|
250
|
+
});
|
|
251
|
+
logger.success(`typescript api file`, file.name, `created in ${output}`);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return file;
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
resolve({
|
|
258
|
+
files: generatedFiles,
|
|
259
|
+
configuration,
|
|
260
|
+
getTemplate,
|
|
261
|
+
renderTemplate,
|
|
262
|
+
createFile,
|
|
263
|
+
formatTSContent: formatFileContent,
|
|
264
|
+
});
|
|
265
|
+
})
|
|
266
|
+
.catch((e) => {
|
|
267
|
+
reject(e);
|
|
268
|
+
throw new Error("Swagger schema parse error!\r\n " + e);
|
|
269
|
+
});
|
|
270
|
+
}),
|
|
271
|
+
};
|
package/src/logger.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
const { config } = require("./config");
|
|
3
|
-
const { emojify, emoji } = require("node-emoji");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {{ type: "warn" | "log" | "error", emojiName: keyof emoji, messages: unknown[] }} payload
|
|
8
|
-
* @returns {void}
|
|
9
|
-
*/
|
|
10
|
-
const createLogMessage = ({ type, emojiName, messages }) => {
|
|
11
|
-
if (config.silent) return;
|
|
12
|
-
|
|
13
|
-
const emoji = emojify(emojiName);
|
|
14
|
-
|
|
15
|
-
console[type](
|
|
16
|
-
emoji,
|
|
17
|
-
" ",
|
|
18
|
-
..._.map(messages, (message) =>
|
|
19
|
-
_.startsWith(message, "\n") ? `\n${emoji} ${message.replace(/\n/, "")}` : message,
|
|
20
|
-
),
|
|
21
|
-
);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const logger = {
|
|
25
|
-
log: (...messages) =>
|
|
26
|
-
createLogMessage({
|
|
27
|
-
type: "log",
|
|
28
|
-
emojiName: ":sparkles:",
|
|
29
|
-
messages,
|
|
30
|
-
}),
|
|
31
|
-
event: (...messages) =>
|
|
32
|
-
createLogMessage({
|
|
33
|
-
type: "log",
|
|
34
|
-
emojiName: ":comet: ",
|
|
35
|
-
messages,
|
|
36
|
-
}),
|
|
37
|
-
success: (...messages) =>
|
|
38
|
-
createLogMessage({
|
|
39
|
-
type: "log",
|
|
40
|
-
emojiName: ":white_check_mark:",
|
|
41
|
-
messages,
|
|
42
|
-
}),
|
|
43
|
-
warn: (...messages) =>
|
|
44
|
-
createLogMessage({
|
|
45
|
-
type: "warn",
|
|
46
|
-
emojiName: ":warning: ",
|
|
47
|
-
messages,
|
|
48
|
-
}),
|
|
49
|
-
error: (...messages) =>
|
|
50
|
-
createLogMessage({
|
|
51
|
-
type: "error",
|
|
52
|
-
emojiName: ":exclamation:",
|
|
53
|
-
messages,
|
|
54
|
-
}),
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
module.exports = {
|
|
58
|
-
logger,
|
|
59
|
-
};
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
const { config } = require("./config");
|
|
3
|
+
const { emojify, emoji } = require("node-emoji");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {{ type: "warn" | "log" | "error", emojiName: keyof emoji, messages: unknown[] }} payload
|
|
8
|
+
* @returns {void}
|
|
9
|
+
*/
|
|
10
|
+
const createLogMessage = ({ type, emojiName, messages }) => {
|
|
11
|
+
if (config.silent) return;
|
|
12
|
+
|
|
13
|
+
const emoji = emojify(emojiName);
|
|
14
|
+
|
|
15
|
+
console[type](
|
|
16
|
+
emoji,
|
|
17
|
+
" ",
|
|
18
|
+
..._.map(messages, (message) =>
|
|
19
|
+
_.startsWith(message, "\n") ? `\n${emoji} ${message.replace(/\n/, "")}` : message,
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const logger = {
|
|
25
|
+
log: (...messages) =>
|
|
26
|
+
createLogMessage({
|
|
27
|
+
type: "log",
|
|
28
|
+
emojiName: ":sparkles:",
|
|
29
|
+
messages,
|
|
30
|
+
}),
|
|
31
|
+
event: (...messages) =>
|
|
32
|
+
createLogMessage({
|
|
33
|
+
type: "log",
|
|
34
|
+
emojiName: ":comet: ",
|
|
35
|
+
messages,
|
|
36
|
+
}),
|
|
37
|
+
success: (...messages) =>
|
|
38
|
+
createLogMessage({
|
|
39
|
+
type: "log",
|
|
40
|
+
emojiName: ":white_check_mark:",
|
|
41
|
+
messages,
|
|
42
|
+
}),
|
|
43
|
+
warn: (...messages) =>
|
|
44
|
+
createLogMessage({
|
|
45
|
+
type: "warn",
|
|
46
|
+
emojiName: ":warning: ",
|
|
47
|
+
messages,
|
|
48
|
+
}),
|
|
49
|
+
error: (...messages) =>
|
|
50
|
+
createLogMessage({
|
|
51
|
+
type: "error",
|
|
52
|
+
emojiName: ":exclamation:",
|
|
53
|
+
messages,
|
|
54
|
+
}),
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
logger,
|
|
59
|
+
};
|