mushroom-cli 1.0.17 → 1.1.0-alpha.1
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/gen/gen-js-driver-tarball.js +17 -10
- package/gen/gen-js-driver.js +26 -6
- package/gen/gen-ts-driver.js +266 -11
- package/gen.js +4 -4
- package/package.json +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require('path');
|
|
3
3
|
var targz = require('targz');
|
|
4
|
-
const
|
|
4
|
+
const javascriptDriverGenerator = require("./gen-js-driver");
|
|
5
|
+
const typescriptDriverGenerator = require("./gen-ts-driver");
|
|
5
6
|
|
|
6
7
|
function compressAsync(src, dest, folderName) {
|
|
7
8
|
return new Promise((resolve, reject) => {
|
|
@@ -30,22 +31,23 @@ function compressAsync(src, dest, folderName) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
async function genJavascriptDriverTarball(args, projectName, project, alias, source) {
|
|
33
|
-
genJavascriptDriver(args, projectName, project, alias, source);
|
|
34
|
-
|
|
35
34
|
const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
|
|
36
35
|
|
|
37
36
|
let tarballName = aliasProject.tarballName ? aliasProject.tarballName : projectName;
|
|
38
37
|
tarballName = tarballName.toLowerCase().replace(/[^a-z-]/g, "-");
|
|
39
38
|
|
|
40
39
|
const dirPath = path.join(path.dirname(aliasProject.output), tarballName);
|
|
41
|
-
const mainFileName = path.basename(aliasProject.output);
|
|
40
|
+
//const mainFileName = path.basename(aliasProject.output);
|
|
41
|
+
//const dtsFileName = mainFileName.replace(/\.js$/i, ".d.ts");
|
|
42
42
|
|
|
43
43
|
const packageContent = `{
|
|
44
|
+
"version": "1.0.${new Date().getTime()}",
|
|
44
45
|
"name": "${tarballName}",
|
|
45
46
|
"private": true,
|
|
46
|
-
"main": "${
|
|
47
|
+
"main": "${tarballName}.js",
|
|
48
|
+
"types": "${tarballName}.d.ts",
|
|
47
49
|
"dependencies": {
|
|
48
|
-
"mushroomjs": "^1.0.4"
|
|
50
|
+
"mushroomjs": "^1.1.0-alpha.5"${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? ',\n "mushroomjs-auth": "^1.1.0-alpha.4"' : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? ',\n "mushroomjs-file": "^1.1.0-alpha.1"' : ""}
|
|
49
51
|
}
|
|
50
52
|
}`;
|
|
51
53
|
|
|
@@ -65,16 +67,21 @@ async function genJavascriptDriverTarball(args, projectName, project, alias, sou
|
|
|
65
67
|
|
|
66
68
|
fs.mkdirSync(dirPath, { recursive: true, mode: 0755 });
|
|
67
69
|
|
|
70
|
+
console.log("Generating main file: " + tarballName + ".js");
|
|
71
|
+
let code = javascriptDriverGenerator.genJavascriptDriverString(aliasProject, source);
|
|
72
|
+
fs.writeFileSync(path.join(dirPath, tarballName + ".js"), code);
|
|
68
73
|
|
|
69
|
-
console.log("Generating
|
|
70
|
-
|
|
71
|
-
fs.
|
|
74
|
+
console.log("Generating types file: " + tarballName + ".d.ts");
|
|
75
|
+
code = typescriptDriverGenerator.genDtsString(aliasProject, source);
|
|
76
|
+
fs.writeFileSync(path.join(dirPath, tarballName + ".d.ts"), code);
|
|
72
77
|
|
|
78
|
+
console.log("Generating package file: package.json");
|
|
73
79
|
fs.writeFileSync(path.join(dirPath, "package.json"), packageContent);
|
|
74
80
|
|
|
81
|
+
console.log("Generating tarball file: " + tarballFileName);
|
|
75
82
|
await compressAsync(dirPath, tarballFileName, tarballName);
|
|
76
83
|
|
|
77
|
-
console.log(
|
|
84
|
+
console.log("Generated tarball file");
|
|
78
85
|
fs.rmdirSync(dirPath, { recursive: true });
|
|
79
86
|
console.log("Cleaned up tarball folder");
|
|
80
87
|
}
|
package/gen/gen-js-driver.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const common = require("../common.js");
|
|
3
|
+
const typescriptDriverGenerator = require("./gen-ts-driver");
|
|
3
4
|
|
|
4
5
|
function isAllowCache(actions, defaultValue) {
|
|
5
6
|
let result = defaultValue;
|
|
@@ -22,11 +23,9 @@ function isAllowCache(actions, defaultValue) {
|
|
|
22
23
|
return result;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
function
|
|
26
|
-
const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
|
|
27
|
-
|
|
26
|
+
function genJavascriptDriverString(aliasProject, source) {
|
|
28
27
|
if (!aliasProject) {
|
|
29
|
-
|
|
28
|
+
return "";
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
@@ -70,10 +69,31 @@ mushroom.$using(rootApiUrl);
|
|
|
70
69
|
|
|
71
70
|
export default mushroom;`;
|
|
72
71
|
|
|
72
|
+
return code;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function genJavascriptDriver(args, projectName, project, alias, source) {
|
|
76
|
+
const aliasProject = ((project.jsDriver || {}).alias || {})[alias];
|
|
77
|
+
|
|
78
|
+
if (!aliasProject) {
|
|
79
|
+
throw new Error(`Not found gen js-driver configuration. Please run 'npx mr config gen ${projectName} js-driver OUTPUT_FILE.js${alias === "default" ? "" : " alias " + alias}' first`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let code = genJavascriptDriverString(aliasProject, source);
|
|
83
|
+
|
|
73
84
|
common.ensureFolder(aliasProject.output);
|
|
74
85
|
|
|
75
86
|
fs.writeFileSync(aliasProject.output, code);
|
|
76
|
-
console.log(`Generated
|
|
87
|
+
console.log(`Generated ${aliasProject.output}`);
|
|
88
|
+
|
|
89
|
+
code = typescriptDriverGenerator.genDtsString(aliasProject, source);
|
|
90
|
+
const dtsFilePath = aliasProject.output.replace(/\.js$/i, ".d.ts");
|
|
91
|
+
fs.writeFileSync(dtsFilePath, code);
|
|
92
|
+
console.log(`Generated ${dtsFilePath}`);
|
|
93
|
+
console.log(`Generated Javascript driver for ${projectName}@${alias}`);
|
|
77
94
|
}
|
|
78
95
|
|
|
79
|
-
module.exports =
|
|
96
|
+
module.exports = {
|
|
97
|
+
genJavascriptDriver,
|
|
98
|
+
genJavascriptDriverString
|
|
99
|
+
};
|
package/gen/gen-ts-driver.js
CHANGED
|
@@ -90,32 +90,42 @@ function generateTypescriptClass(objectDefination, indent) {
|
|
|
90
90
|
return code;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
function
|
|
94
|
-
|
|
93
|
+
function generateTypescriptClassFromViewParameters(parameters) {
|
|
94
|
+
if (Array.isArray(parameters)){
|
|
95
|
+
return '{\n' + parameters.map(p => ` ${p.field}?: ${getCSharpTypeFromMushroomType(p.type || "string")}${p.isArray ? "[]" : ""}`).join(',\n') + '\n}';
|
|
96
|
+
}
|
|
97
|
+
return '{}';
|
|
98
|
+
}
|
|
95
99
|
|
|
100
|
+
function genTypescriptDriverString(aliasProject, source) {
|
|
96
101
|
if (!aliasProject) {
|
|
97
|
-
|
|
102
|
+
return "";
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
101
106
|
|
|
102
|
-
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomError } from "mushroomjs";
|
|
107
|
+
let code = `import mushroom, { defineAsyncResource, defineAsyncView, fireEvent, createRestfulAsyncFunction, IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
108
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? 'import { IMushroomAuth, useAuth, AuthLocalStorage } from "mushroomjs-auth";' : ""}
|
|
109
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? 'import { IMushroomFile, useFile } from "mushroomjs-file";' : ""}
|
|
103
110
|
|
|
104
111
|
export type ISODateValue = string | Date;
|
|
105
112
|
export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
|
|
106
113
|
|
|
107
114
|
`;
|
|
115
|
+
let iApiClassBody = "";
|
|
108
116
|
for (let entityName in entities) {
|
|
109
117
|
if (!entities.hasOwnProperty(entityName))
|
|
110
118
|
continue;
|
|
111
119
|
|
|
112
120
|
const entity = entities[entityName];
|
|
113
|
-
|
|
114
|
-
code += `interface ${
|
|
121
|
+
const typescriptClassName = toTypeScriptClassName(entityName);
|
|
122
|
+
code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
115
123
|
`;
|
|
116
124
|
|
|
117
125
|
|
|
118
126
|
const actions = {};
|
|
127
|
+
iApiClassBody += ` ${entityName}: MushroomResourceBase`;
|
|
128
|
+
let customMethodCode = "";
|
|
119
129
|
for (const actionName in entity.actions) {
|
|
120
130
|
if (!entity.actions.hasOwnProperty(actionName))
|
|
121
131
|
continue;
|
|
@@ -123,23 +133,264 @@ export type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoI
|
|
|
123
133
|
actions[actionName] = {
|
|
124
134
|
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
|
|
125
135
|
};
|
|
136
|
+
|
|
137
|
+
switch (actionName) {
|
|
138
|
+
case "findMany": {
|
|
139
|
+
iApiClassBody += ` & MushroomListResource<${typescriptClassName}>`;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case "findById": {
|
|
143
|
+
iApiClassBody += ` & MushroomFindByIdResource<${typescriptClassName}>`;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "createOne": {
|
|
147
|
+
iApiClassBody += ` & MushroomCreateResource<${typescriptClassName}>`;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case "createMany": {
|
|
151
|
+
iApiClassBody += ` & MushroomBatchCreateResource<${typescriptClassName}>`;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "updateOne": {
|
|
155
|
+
iApiClassBody += ` & MushroomUpdateResource<${typescriptClassName}>`;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "updateMany": {
|
|
159
|
+
iApiClassBody += ` & MushroomBatchUpdateResource<${typescriptClassName}>`;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
case "updatePartially": {
|
|
163
|
+
iApiClassBody += ` & MushroomPartialUpdateResource<${typescriptClassName}>`;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "deleteOne": {
|
|
167
|
+
iApiClassBody += " & MushroomDeleteResource";
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
case "deleteMany": {
|
|
171
|
+
iApiClassBody += " & MushroomBatchDeleteResource";
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
default: {
|
|
175
|
+
if (actionName.indexOf("_raw_http_method_") === 0) {
|
|
176
|
+
customMethodCode += ` ${actionName.substr("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
|
|
177
|
+
`;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
console.warn(`Unknown action name: ${entityName}.${actionName}`);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (customMethodCode) {
|
|
189
|
+
code += `interface ${typescriptClassName}$CustomMethodResource {
|
|
190
|
+
${customMethodCode}}
|
|
191
|
+
`;
|
|
192
|
+
iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
|
|
126
193
|
}
|
|
127
194
|
|
|
128
195
|
const views = {};
|
|
196
|
+
let viewCode = "";
|
|
129
197
|
for (const viewName in entity.views) {
|
|
130
|
-
if (!entity.views.hasOwnProperty(viewName))
|
|
131
|
-
|
|
198
|
+
if (!entity.views.hasOwnProperty(viewName)) continue;
|
|
199
|
+
|
|
200
|
+
const viewRoles = entity.views[viewName];
|
|
201
|
+
if (!Array.isArray(viewRoles) || !viewRoles.length) continue;
|
|
132
202
|
|
|
133
203
|
views[viewName] = { clientCache: true };
|
|
204
|
+
|
|
205
|
+
const viewParameterTypes = viewRoles.map(view => {
|
|
206
|
+
const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
207
|
+
code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
208
|
+
`;
|
|
209
|
+
return `MushroomViewFunction<any, ${type}>`;
|
|
210
|
+
});
|
|
211
|
+
viewCode += `
|
|
212
|
+
${viewName}Async: ${viewParameterTypes.join(' & ')},`;
|
|
134
213
|
}
|
|
135
|
-
|
|
214
|
+
|
|
215
|
+
if (viewCode) {
|
|
216
|
+
code += `interface ${typescriptClassName}$ViewsResource {
|
|
217
|
+
views: {${viewCode}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
iApiClassBody += ` & ${typescriptClassName}$ViewsResource`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
iApiClassBody +=`,
|
|
225
|
+
`;
|
|
226
|
+
|
|
227
|
+
code += `defineAsyncResource<${typescriptClassName}>(${JSON.stringify({ name: entityName, actions: actions, views: views })});
|
|
136
228
|
|
|
137
229
|
`;
|
|
138
230
|
}
|
|
231
|
+
|
|
139
232
|
code += `
|
|
233
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useAuth(AuthLocalStorage);" : ""}
|
|
234
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "useFile();" : ""}
|
|
140
235
|
mushroom.$using(${JSON.stringify(common.getRootUrl(source))});
|
|
141
236
|
|
|
142
|
-
|
|
237
|
+
interface IApi extends IMushroom {
|
|
238
|
+
${iApiClassBody}};
|
|
239
|
+
|
|
240
|
+
type Api = ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "IMushroomAuth & " : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? "IMushroomFile & " : ""}IApi;
|
|
241
|
+
|
|
242
|
+
export default mushroom as Api;`;
|
|
243
|
+
|
|
244
|
+
return code;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function genDtsString(aliasProject, source) {
|
|
248
|
+
if (!aliasProject) {
|
|
249
|
+
return "";
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
253
|
+
|
|
254
|
+
let code = `import { IdType, IMushroom, Mushroom, MushroomRequest, MushroomRequestSetting, MushroomRestfulRequest, MushroomResponse, MushroomResourceBase, MushroomListResource, MushroomFindByIdResource, MushroomCreateResource, MushroomBatchCreateResource, MushroomUpdateResource, MushroomBatchUpdateResource, MushroomPartialUpdateResource, MushroomDeleteResource, MushroomBatchDeleteResource, MushroomExtensibleResource, MushroomViewFunction, MushroomError } from "mushroomjs";
|
|
255
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? 'import { IMushroomAuth } from "mushroomjs-auth";' : ""}
|
|
256
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? 'import { IMushroomFile } from "mushroomjs-file";' : ""}
|
|
257
|
+
|
|
258
|
+
export declare type ISODateValue = string | Date;
|
|
259
|
+
export declare type IdValue = ${source.idType == "AutoIncInt" || source.idType == "AutoIncLong" ? "number" : "string"};
|
|
260
|
+
|
|
261
|
+
`;
|
|
262
|
+
let iApiClassBody = "";
|
|
263
|
+
for (let entityName in entities) {
|
|
264
|
+
if (!entities.hasOwnProperty(entityName))
|
|
265
|
+
continue;
|
|
266
|
+
|
|
267
|
+
const entity = entities[entityName];
|
|
268
|
+
const typescriptClassName = toTypeScriptClassName(entityName);
|
|
269
|
+
code += `interface ${typescriptClassName} ${generateTypescriptClass(entity.fields)};
|
|
270
|
+
`;
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
const actions = {};
|
|
274
|
+
iApiClassBody += ` ${entityName}: MushroomResourceBase`;
|
|
275
|
+
let customMethodCode = "";
|
|
276
|
+
for (const actionName in entity.actions) {
|
|
277
|
+
if (!entity.actions.hasOwnProperty(actionName))
|
|
278
|
+
continue;
|
|
279
|
+
|
|
280
|
+
actions[actionName] = {
|
|
281
|
+
clientCache: (actionName === "findById" || actionName === "findMany") && isAllowCache(entity.actions[actionName], true) ? true : undefined
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
switch (actionName) {
|
|
285
|
+
case "findMany": {
|
|
286
|
+
iApiClassBody += ` & MushroomListResource<${typescriptClassName}>`;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
case "findById": {
|
|
290
|
+
iApiClassBody += ` & MushroomFindByIdResource<${typescriptClassName}>`;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
case "createOne": {
|
|
294
|
+
iApiClassBody += ` & MushroomCreateResource<${typescriptClassName}>`;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
case "createMany": {
|
|
298
|
+
iApiClassBody += ` & MushroomBatchCreateResource<${typescriptClassName}>`;
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case "updateOne": {
|
|
302
|
+
iApiClassBody += ` & MushroomUpdateResource<${typescriptClassName}>`;
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
case "updateMany": {
|
|
306
|
+
iApiClassBody += ` & MushroomBatchUpdateResource<${typescriptClassName}>`;
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
case "updatePartially": {
|
|
310
|
+
iApiClassBody += ` & MushroomPartialUpdateResource<${typescriptClassName}>`;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case "deleteOne": {
|
|
314
|
+
iApiClassBody += " & MushroomDeleteResource";
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
case "deleteMany": {
|
|
318
|
+
iApiClassBody += " & MushroomBatchDeleteResource";
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
default: {
|
|
322
|
+
if (actionName.indexOf("_raw_http_method_") === 0) {
|
|
323
|
+
customMethodCode += ` ${actionName.substr("_raw_http_method_".length)}Async: (rawRequest: MushroomRequest) => Promise<MushroomResponse<any>>,
|
|
324
|
+
`;
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
console.warn(`Unknown action name: ${entityName}.${actionName}`);
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (customMethodCode) {
|
|
336
|
+
code += `interface ${typescriptClassName}$CustomMethodResource {
|
|
337
|
+
${customMethodCode}}
|
|
338
|
+
`;
|
|
339
|
+
iApiClassBody += ` & ${typescriptClassName}$CustomMethodResource`;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const views = {};
|
|
343
|
+
let viewCode = "";
|
|
344
|
+
for (const viewName in entity.views) {
|
|
345
|
+
if (!entity.views.hasOwnProperty(viewName)) continue;
|
|
346
|
+
|
|
347
|
+
const viewRoles = entity.views[viewName];
|
|
348
|
+
if (!Array.isArray(viewRoles) || !viewRoles.length) continue;
|
|
349
|
+
|
|
350
|
+
views[viewName] = { clientCache: true };
|
|
351
|
+
|
|
352
|
+
const viewParameterTypes = viewRoles.map(view => {
|
|
353
|
+
const type = `${typescriptClassName}$ViewsResource_${viewName}View_${view.grant === "*" ? "" : toTypeScriptClassName(view.grant)}Parameters`;
|
|
354
|
+
code += `interface ${type} ${generateTypescriptClassFromViewParameters(view.parameters)};
|
|
355
|
+
`;
|
|
356
|
+
return `MushroomViewFunction<any, ${type}>`;
|
|
357
|
+
});
|
|
358
|
+
viewCode += `
|
|
359
|
+
${viewName}Async: ${viewParameterTypes.join(' & ')},`;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (viewCode) {
|
|
363
|
+
code += `interface ${typescriptClassName}$ViewsResource {
|
|
364
|
+
views: {${viewCode}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
368
|
+
iApiClassBody += ` & ${typescriptClassName}$ViewsResource`;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
iApiClassBody +=`,
|
|
372
|
+
`;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
code += `
|
|
376
|
+
interface IApi extends IMushroom {
|
|
377
|
+
${iApiClassBody}};
|
|
378
|
+
|
|
379
|
+
declare type Api = ${Array.isArray(aliasProject.features) && aliasProject.features.includes("auth") ? "IMushroomAuth & " : ""}${Array.isArray(aliasProject.features) && aliasProject.features.includes("file") ? "IMushroomFile & " : ""}IApi;
|
|
380
|
+
declare const _default: Api;
|
|
381
|
+
export default _default;`;
|
|
382
|
+
|
|
383
|
+
return code;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function genTypescriptDriver(args, projectName, project, alias, source) {
|
|
387
|
+
const aliasProject = ((project.tsDriver || {}).alias || {})[alias];
|
|
388
|
+
|
|
389
|
+
if (!aliasProject) {
|
|
390
|
+
throw new Error(`Not found gen ts-driver configuration. Please run 'npx mr config gen ${projectName} ts-driver OUTPUT_FILE.ts${alias === "default" ? "" : " alias " + alias}' first`);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const code = genTypescriptDriverString(aliasProject, source);
|
|
143
394
|
|
|
144
395
|
common.ensureFolder(aliasProject.output);
|
|
145
396
|
|
|
@@ -147,4 +398,8 @@ export default mushroom;`;
|
|
|
147
398
|
console.log(`Generated Typescript driver for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
148
399
|
}
|
|
149
400
|
|
|
150
|
-
module.exports =
|
|
401
|
+
module.exports = {
|
|
402
|
+
genTypescriptDriver,
|
|
403
|
+
genTypescriptDriverString,
|
|
404
|
+
genDtsString
|
|
405
|
+
};
|
package/gen.js
CHANGED
|
@@ -7,9 +7,9 @@ const masterFile = require("./master-file/master-file");
|
|
|
7
7
|
|
|
8
8
|
const genApiDocs = require("./gen/gen-api-docs");
|
|
9
9
|
const genDatabaseDocs = require("./gen/gen-db-docs");
|
|
10
|
-
const
|
|
10
|
+
const javascriptDriverGenerator = require("./gen/gen-js-driver");
|
|
11
11
|
const genJavascriptDriverTarball = require("./gen/gen-js-driver-tarball");
|
|
12
|
-
const
|
|
12
|
+
const typescriptDriverGenerator = require("./gen/gen-ts-driver");
|
|
13
13
|
const csharp = require("./gen/gen-csharp");
|
|
14
14
|
|
|
15
15
|
|
|
@@ -91,13 +91,13 @@ async function gen(args) {
|
|
|
91
91
|
genDatabaseDocs(args, projectName, project, alias, source);
|
|
92
92
|
break;
|
|
93
93
|
case "js-driver":
|
|
94
|
-
genJavascriptDriver(args, projectName, project, alias, source);
|
|
94
|
+
javascriptDriverGenerator.genJavascriptDriver(args, projectName, project, alias, source);
|
|
95
95
|
break;
|
|
96
96
|
case "js-driver-tarball":
|
|
97
97
|
await genJavascriptDriverTarball(args, projectName, project, alias, source);
|
|
98
98
|
break;
|
|
99
99
|
case "ts-driver":
|
|
100
|
-
genTypescriptDriver(args, projectName, project, alias, source);
|
|
100
|
+
typescriptDriverGenerator.genTypescriptDriver(args, projectName, project, alias, source);
|
|
101
101
|
break;
|
|
102
102
|
case "c#-mongo":
|
|
103
103
|
csharp.genCSharpMongoDbClasses(args, projectName, project, alias, source);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mushroom-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-alpha.1",
|
|
4
4
|
"description": "Mushroom CLI",
|
|
5
5
|
"main": "mr.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"release": "npm publish --access public"
|
|
7
|
+
"release": "npm publish --access public --tag alpha"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"Mushroom",
|