@modern-js/plugin-bff 2.69.4 → 3.0.0-alpha.0
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/dist/cjs/cli.js +256 -272
- package/dist/cjs/constants.js +43 -34
- package/dist/cjs/index.js +55 -19
- package/dist/cjs/loader.js +69 -65
- package/dist/cjs/runtime/create-request/index.js +39 -29
- package/dist/cjs/runtime/hono/adapter.js +128 -126
- package/dist/cjs/runtime/hono/index.js +78 -30
- package/dist/cjs/runtime/hono/operators.js +64 -67
- package/dist/cjs/server.js +159 -165
- package/dist/cjs/utils/clientGenerator.js +204 -206
- package/dist/cjs/utils/createHonoRoutes.js +128 -144
- package/dist/cjs/utils/crossProjectApiPlugin.js +91 -81
- package/dist/cjs/utils/pluginGenerator.js +66 -54
- package/dist/cjs/utils/runtimeGenerator.js +67 -45
- package/dist/esm/cli.mjs +214 -0
- package/dist/esm/constants.mjs +11 -0
- package/dist/esm/loader.mjs +39 -0
- package/dist/esm/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm-node/runtime/hono/index.js → esm/runtime/hono/index.mjs} +2 -4
- package/dist/esm/runtime/hono/operators.mjs +31 -0
- package/dist/esm/server.mjs +122 -0
- package/dist/esm/utils/clientGenerator.mjs +175 -0
- package/dist/esm/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm/utils/pluginGenerator.mjs +29 -0
- package/dist/esm/utils/runtimeGenerator.mjs +43 -0
- package/dist/esm-node/cli.mjs +214 -0
- package/dist/esm-node/constants.mjs +11 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/loader.mjs +39 -0
- package/dist/esm-node/runtime/create-request/{index.js → index.mjs} +1 -5
- package/dist/esm-node/runtime/hono/adapter.mjs +95 -0
- package/dist/{esm/runtime/hono/index.js → esm-node/runtime/hono/index.mjs} +3 -5
- package/dist/esm-node/runtime/hono/operators.mjs +31 -0
- package/dist/esm-node/server.mjs +122 -0
- package/dist/esm-node/utils/clientGenerator.mjs +175 -0
- package/dist/esm-node/utils/createHonoRoutes.mjs +91 -0
- package/dist/esm-node/utils/crossProjectApiPlugin.mjs +34 -0
- package/dist/esm-node/utils/pluginGenerator.mjs +29 -0
- package/dist/esm-node/utils/runtimeGenerator.mjs +43 -0
- package/dist/types/loader.d.ts +2 -2
- package/dist/types/runtime/hono/adapter.d.ts +3 -3
- package/dist/types/server.d.ts +2 -2
- package/dist/types/utils/runtimeGenerator.d.ts +2 -1
- package/package.json +54 -32
- package/rslib.config.mts +4 -0
- package/dist/cjs/helper.js +0 -48
- package/dist/esm/cli.js +0 -425
- package/dist/esm/constants.js +0 -14
- package/dist/esm/helper.js +0 -13
- package/dist/esm/index.js +0 -1
- package/dist/esm/loader.js +0 -75
- package/dist/esm/runtime/hono/adapter.js +0 -243
- package/dist/esm/runtime/hono/operators.js +0 -79
- package/dist/esm/server.js +0 -258
- package/dist/esm/utils/clientGenerator.js +0 -517
- package/dist/esm/utils/createHonoRoutes.js +0 -319
- package/dist/esm/utils/crossProjectApiPlugin.js +0 -49
- package/dist/esm/utils/pluginGenerator.js +0 -94
- package/dist/esm/utils/runtimeGenerator.js +0 -55
- package/dist/esm-node/cli.js +0 -246
- package/dist/esm-node/constants.js +0 -14
- package/dist/esm-node/helper.js +0 -14
- package/dist/esm-node/loader.js +0 -49
- package/dist/esm-node/runtime/hono/adapter.js +0 -103
- package/dist/esm-node/runtime/hono/operators.js +0 -46
- package/dist/esm-node/server.js +0 -142
- package/dist/esm-node/utils/clientGenerator.js +0 -192
- package/dist/esm-node/utils/createHonoRoutes.js +0 -120
- package/dist/esm-node/utils/crossProjectApiPlugin.js +0 -47
- package/dist/esm-node/utils/pluginGenerator.js +0 -31
- package/dist/esm-node/utils/runtimeGenerator.js +0 -35
- package/dist/types/helper.d.ts +0 -2
- package/types.d.ts +0 -3
- /package/dist/{esm-node/index.js → esm/index.mjs} +0 -0
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
3
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
4
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
6
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
|
-
var _path;
|
|
8
|
-
import path from "path";
|
|
9
|
-
import { generateClient } from "@modern-js/bff-core";
|
|
10
|
-
import { fs, logger } from "@modern-js/utils";
|
|
11
|
-
var API_DIR = "api";
|
|
12
|
-
var PLUGIN_DIR = "plugin";
|
|
13
|
-
var RUNTIME_DIR = "runtime";
|
|
14
|
-
var CLIENT_DIR = "client";
|
|
15
|
-
var EXPORT_PREFIX = "./".concat(API_DIR, "/");
|
|
16
|
-
var TYPE_PREFIX = "".concat(API_DIR, "/");
|
|
17
|
-
var toPosixPath = function(p) {
|
|
18
|
-
return p.replace(/\\/g, "/");
|
|
19
|
-
};
|
|
20
|
-
var posixJoin = function() {
|
|
21
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
|
-
args[_key] = arguments[_key];
|
|
23
|
-
}
|
|
24
|
-
return toPosixPath((_path = path).join.apply(_path, _to_consumable_array(args)));
|
|
25
|
-
};
|
|
26
|
-
function readDirectoryFiles(appDirectory, directory, relativeDistPath) {
|
|
27
|
-
return _readDirectoryFiles.apply(this, arguments);
|
|
28
|
-
}
|
|
29
|
-
function _readDirectoryFiles() {
|
|
30
|
-
_readDirectoryFiles = _async_to_generator(function(appDirectory, directory, relativeDistPath) {
|
|
31
|
-
var filesList;
|
|
32
|
-
function readFiles(currentPath) {
|
|
33
|
-
return _readFiles.apply(this, arguments);
|
|
34
|
-
}
|
|
35
|
-
function _readFiles() {
|
|
36
|
-
_readFiles = _async_to_generator(function(currentPath) {
|
|
37
|
-
var entries, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, entry, resourcePath, source, relativePath, parsedPath, targetDir, name, absTargetDir, relativePathFromAppDirectory, typesFilePath, relativeTargetDistDir, exportKey, err;
|
|
38
|
-
return _ts_generator(this, function(_state) {
|
|
39
|
-
switch (_state.label) {
|
|
40
|
-
case 0:
|
|
41
|
-
return [
|
|
42
|
-
4,
|
|
43
|
-
fs.readdir(currentPath, {
|
|
44
|
-
withFileTypes: true
|
|
45
|
-
})
|
|
46
|
-
];
|
|
47
|
-
case 1:
|
|
48
|
-
entries = _state.sent();
|
|
49
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
50
|
-
_state.label = 2;
|
|
51
|
-
case 2:
|
|
52
|
-
_state.trys.push([
|
|
53
|
-
2,
|
|
54
|
-
9,
|
|
55
|
-
10,
|
|
56
|
-
11
|
|
57
|
-
]);
|
|
58
|
-
_iterator = entries[Symbol.iterator]();
|
|
59
|
-
_state.label = 3;
|
|
60
|
-
case 3:
|
|
61
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
62
|
-
return [
|
|
63
|
-
3,
|
|
64
|
-
8
|
|
65
|
-
];
|
|
66
|
-
entry = _step.value;
|
|
67
|
-
if (entry.name === "_app.ts")
|
|
68
|
-
return [
|
|
69
|
-
3,
|
|
70
|
-
7
|
|
71
|
-
];
|
|
72
|
-
resourcePath = path.join(currentPath, entry.name);
|
|
73
|
-
if (!entry.isDirectory())
|
|
74
|
-
return [
|
|
75
|
-
3,
|
|
76
|
-
5
|
|
77
|
-
];
|
|
78
|
-
return [
|
|
79
|
-
4,
|
|
80
|
-
readFiles(resourcePath)
|
|
81
|
-
];
|
|
82
|
-
case 4:
|
|
83
|
-
_state.sent();
|
|
84
|
-
return [
|
|
85
|
-
3,
|
|
86
|
-
7
|
|
87
|
-
];
|
|
88
|
-
case 5:
|
|
89
|
-
return [
|
|
90
|
-
4,
|
|
91
|
-
fs.readFile(resourcePath, "utf8")
|
|
92
|
-
];
|
|
93
|
-
case 6:
|
|
94
|
-
source = _state.sent();
|
|
95
|
-
relativePath = path.relative(directory, resourcePath);
|
|
96
|
-
parsedPath = path.parse(relativePath);
|
|
97
|
-
targetDir = posixJoin("./".concat(relativeDistPath, "/").concat(CLIENT_DIR), parsedPath.dir, "".concat(parsedPath.name, ".js"));
|
|
98
|
-
name = parsedPath.name;
|
|
99
|
-
absTargetDir = path.resolve(targetDir);
|
|
100
|
-
relativePathFromAppDirectory = path.relative(appDirectory, currentPath);
|
|
101
|
-
typesFilePath = posixJoin("./".concat(relativeDistPath), relativePathFromAppDirectory, "".concat(name, ".d.ts"));
|
|
102
|
-
relativeTargetDistDir = "./".concat(typesFilePath);
|
|
103
|
-
exportKey = toPosixPath(path.join(parsedPath.dir, name));
|
|
104
|
-
filesList.push({
|
|
105
|
-
resourcePath,
|
|
106
|
-
source,
|
|
107
|
-
targetDir,
|
|
108
|
-
name,
|
|
109
|
-
absTargetDir,
|
|
110
|
-
relativeTargetDistDir,
|
|
111
|
-
exportKey
|
|
112
|
-
});
|
|
113
|
-
_state.label = 7;
|
|
114
|
-
case 7:
|
|
115
|
-
_iteratorNormalCompletion = true;
|
|
116
|
-
return [
|
|
117
|
-
3,
|
|
118
|
-
3
|
|
119
|
-
];
|
|
120
|
-
case 8:
|
|
121
|
-
return [
|
|
122
|
-
3,
|
|
123
|
-
11
|
|
124
|
-
];
|
|
125
|
-
case 9:
|
|
126
|
-
err = _state.sent();
|
|
127
|
-
_didIteratorError = true;
|
|
128
|
-
_iteratorError = err;
|
|
129
|
-
return [
|
|
130
|
-
3,
|
|
131
|
-
11
|
|
132
|
-
];
|
|
133
|
-
case 10:
|
|
134
|
-
try {
|
|
135
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
136
|
-
_iterator.return();
|
|
137
|
-
}
|
|
138
|
-
} finally {
|
|
139
|
-
if (_didIteratorError) {
|
|
140
|
-
throw _iteratorError;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return [
|
|
144
|
-
7
|
|
145
|
-
];
|
|
146
|
-
case 11:
|
|
147
|
-
return [
|
|
148
|
-
2
|
|
149
|
-
];
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
return _readFiles.apply(this, arguments);
|
|
154
|
-
}
|
|
155
|
-
return _ts_generator(this, function(_state) {
|
|
156
|
-
switch (_state.label) {
|
|
157
|
-
case 0:
|
|
158
|
-
filesList = [];
|
|
159
|
-
return [
|
|
160
|
-
4,
|
|
161
|
-
readFiles(directory)
|
|
162
|
-
];
|
|
163
|
-
case 1:
|
|
164
|
-
_state.sent();
|
|
165
|
-
return [
|
|
166
|
-
2,
|
|
167
|
-
filesList
|
|
168
|
-
];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
return _readDirectoryFiles.apply(this, arguments);
|
|
173
|
-
}
|
|
174
|
-
function mergePackageJson(packageJson, files, typesVersion, exports) {
|
|
175
|
-
var _packageJson, _packageJson1;
|
|
176
|
-
packageJson.files = _to_consumable_array(new Set(_to_consumable_array(packageJson.files || []).concat(_to_consumable_array(files))));
|
|
177
|
-
var _typesVersions;
|
|
178
|
-
(_typesVersions = (_packageJson = packageJson).typesVersions) !== null && _typesVersions !== void 0 ? _typesVersions : _packageJson.typesVersions = {};
|
|
179
|
-
var starTypes = packageJson.typesVersions["*"] || {};
|
|
180
|
-
Object.keys(starTypes).forEach(function(k) {
|
|
181
|
-
return k.startsWith(TYPE_PREFIX) && delete starTypes[k];
|
|
182
|
-
});
|
|
183
|
-
packageJson.typesVersions["*"] = _object_spread({}, starTypes, typesVersion["*"] || {});
|
|
184
|
-
var _exports;
|
|
185
|
-
(_exports = (_packageJson1 = packageJson).exports) !== null && _exports !== void 0 ? _exports : _packageJson1.exports = {};
|
|
186
|
-
Object.keys(packageJson.exports).forEach(function(k) {
|
|
187
|
-
return k.startsWith(EXPORT_PREFIX) && delete packageJson.exports[k];
|
|
188
|
-
});
|
|
189
|
-
Object.assign(packageJson.exports, exports);
|
|
190
|
-
}
|
|
191
|
-
function writeTargetFile(absTargetDir, content) {
|
|
192
|
-
return _writeTargetFile.apply(this, arguments);
|
|
193
|
-
}
|
|
194
|
-
function _writeTargetFile() {
|
|
195
|
-
_writeTargetFile = _async_to_generator(function(absTargetDir, content) {
|
|
196
|
-
return _ts_generator(this, function(_state) {
|
|
197
|
-
switch (_state.label) {
|
|
198
|
-
case 0:
|
|
199
|
-
return [
|
|
200
|
-
4,
|
|
201
|
-
fs.mkdir(path.dirname(absTargetDir), {
|
|
202
|
-
recursive: true
|
|
203
|
-
})
|
|
204
|
-
];
|
|
205
|
-
case 1:
|
|
206
|
-
_state.sent();
|
|
207
|
-
return [
|
|
208
|
-
4,
|
|
209
|
-
fs.writeFile(absTargetDir, content)
|
|
210
|
-
];
|
|
211
|
-
case 2:
|
|
212
|
-
_state.sent();
|
|
213
|
-
return [
|
|
214
|
-
2
|
|
215
|
-
];
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
return _writeTargetFile.apply(this, arguments);
|
|
220
|
-
}
|
|
221
|
-
function setPackage(files, appDirectory, relativeDistPath) {
|
|
222
|
-
return _setPackage.apply(this, arguments);
|
|
223
|
-
}
|
|
224
|
-
function _setPackage() {
|
|
225
|
-
_setPackage = _async_to_generator(function(files, appDirectory, relativeDistPath) {
|
|
226
|
-
var packagePath, packageContent, packageJson, addFiles, _obj, typesVersions, _obj1, exports, error;
|
|
227
|
-
return _ts_generator(this, function(_state) {
|
|
228
|
-
switch (_state.label) {
|
|
229
|
-
case 0:
|
|
230
|
-
_state.trys.push([
|
|
231
|
-
0,
|
|
232
|
-
3,
|
|
233
|
-
,
|
|
234
|
-
4
|
|
235
|
-
]);
|
|
236
|
-
packagePath = path.resolve(appDirectory, "./package.json");
|
|
237
|
-
return [
|
|
238
|
-
4,
|
|
239
|
-
fs.readFile(packagePath, "utf8")
|
|
240
|
-
];
|
|
241
|
-
case 1:
|
|
242
|
-
packageContent = _state.sent();
|
|
243
|
-
packageJson = JSON.parse(packageContent);
|
|
244
|
-
addFiles = [
|
|
245
|
-
posixJoin(relativeDistPath, CLIENT_DIR, "**", "*"),
|
|
246
|
-
posixJoin(relativeDistPath, RUNTIME_DIR, "**", "*"),
|
|
247
|
-
posixJoin(relativeDistPath, PLUGIN_DIR, "**", "*")
|
|
248
|
-
];
|
|
249
|
-
typesVersions = {
|
|
250
|
-
"*": files.reduce(function(acc, file) {
|
|
251
|
-
var typeFilePath = toPosixPath("./".concat(file.targetDir)).replace("js", "d.ts");
|
|
252
|
-
return _object_spread_props(_object_spread({}, acc), _define_property({}, toPosixPath("".concat(TYPE_PREFIX).concat(file.exportKey)), [
|
|
253
|
-
typeFilePath
|
|
254
|
-
]));
|
|
255
|
-
}, (_obj = {}, _define_property(_obj, "".concat(API_DIR, "/*"), [
|
|
256
|
-
toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.d.ts"))
|
|
257
|
-
]), _define_property(_obj, RUNTIME_DIR, [
|
|
258
|
-
toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.d.ts"))
|
|
259
|
-
]), _define_property(_obj, PLUGIN_DIR, [
|
|
260
|
-
toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.d.ts"))
|
|
261
|
-
]), _obj))
|
|
262
|
-
};
|
|
263
|
-
exports = files.reduce(function(acc, file) {
|
|
264
|
-
var exportKey = "".concat(EXPORT_PREFIX).concat(file.exportKey);
|
|
265
|
-
var jsFilePath = toPosixPath("./".concat(file.targetDir));
|
|
266
|
-
return _object_spread_props(_object_spread({}, acc), _define_property({}, toPosixPath(exportKey), {
|
|
267
|
-
import: jsFilePath,
|
|
268
|
-
types: toPosixPath(jsFilePath.replace(/\.js$/, ".d.ts"))
|
|
269
|
-
}));
|
|
270
|
-
}, (_obj1 = {}, _define_property(_obj1, toPosixPath("./".concat(API_DIR, "/*")), {
|
|
271
|
-
import: toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.js")),
|
|
272
|
-
types: toPosixPath("./".concat(relativeDistPath, "/").concat(CLIENT_DIR, "/*.d.ts"))
|
|
273
|
-
}), _define_property(_obj1, toPosixPath("./".concat(PLUGIN_DIR)), {
|
|
274
|
-
import: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.js")),
|
|
275
|
-
require: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.js")),
|
|
276
|
-
types: toPosixPath("./".concat(relativeDistPath, "/").concat(PLUGIN_DIR, "/index.d.ts"))
|
|
277
|
-
}), _define_property(_obj1, toPosixPath("./".concat(RUNTIME_DIR)), {
|
|
278
|
-
import: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.js")),
|
|
279
|
-
require: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.js")),
|
|
280
|
-
types: toPosixPath("./".concat(relativeDistPath, "/").concat(RUNTIME_DIR, "/index.d.ts"))
|
|
281
|
-
}), _obj1));
|
|
282
|
-
mergePackageJson(packageJson, addFiles, typesVersions, exports);
|
|
283
|
-
return [
|
|
284
|
-
4,
|
|
285
|
-
fs.promises.writeFile(packagePath, JSON.stringify(packageJson, null, 2))
|
|
286
|
-
];
|
|
287
|
-
case 2:
|
|
288
|
-
_state.sent();
|
|
289
|
-
return [
|
|
290
|
-
3,
|
|
291
|
-
4
|
|
292
|
-
];
|
|
293
|
-
case 3:
|
|
294
|
-
error = _state.sent();
|
|
295
|
-
logger.error("package.json update failed: ".concat(error));
|
|
296
|
-
return [
|
|
297
|
-
3,
|
|
298
|
-
4
|
|
299
|
-
];
|
|
300
|
-
case 4:
|
|
301
|
-
return [
|
|
302
|
-
2
|
|
303
|
-
];
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
return _setPackage.apply(this, arguments);
|
|
308
|
-
}
|
|
309
|
-
function copyFiles(from, to) {
|
|
310
|
-
return _copyFiles.apply(this, arguments);
|
|
311
|
-
}
|
|
312
|
-
function _copyFiles() {
|
|
313
|
-
_copyFiles = _async_to_generator(function(from, to) {
|
|
314
|
-
return _ts_generator(this, function(_state) {
|
|
315
|
-
switch (_state.label) {
|
|
316
|
-
case 0:
|
|
317
|
-
return [
|
|
318
|
-
4,
|
|
319
|
-
fs.pathExists(from)
|
|
320
|
-
];
|
|
321
|
-
case 1:
|
|
322
|
-
if (!_state.sent())
|
|
323
|
-
return [
|
|
324
|
-
3,
|
|
325
|
-
3
|
|
326
|
-
];
|
|
327
|
-
return [
|
|
328
|
-
4,
|
|
329
|
-
fs.copy(toPosixPath(from), toPosixPath(to))
|
|
330
|
-
];
|
|
331
|
-
case 2:
|
|
332
|
-
_state.sent();
|
|
333
|
-
_state.label = 3;
|
|
334
|
-
case 3:
|
|
335
|
-
return [
|
|
336
|
-
2
|
|
337
|
-
];
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
return _copyFiles.apply(this, arguments);
|
|
342
|
-
}
|
|
343
|
-
function clientGenerator(draftOptions) {
|
|
344
|
-
return _clientGenerator.apply(this, arguments);
|
|
345
|
-
}
|
|
346
|
-
function _clientGenerator() {
|
|
347
|
-
_clientGenerator = _async_to_generator(function(draftOptions) {
|
|
348
|
-
var sourceList, getClitentCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, source, code, err, error;
|
|
349
|
-
return _ts_generator(this, function(_state) {
|
|
350
|
-
switch (_state.label) {
|
|
351
|
-
case 0:
|
|
352
|
-
return [
|
|
353
|
-
4,
|
|
354
|
-
readDirectoryFiles(draftOptions.appDir, draftOptions.lambdaDir, draftOptions.relativeDistPath)
|
|
355
|
-
];
|
|
356
|
-
case 1:
|
|
357
|
-
sourceList = _state.sent();
|
|
358
|
-
getClitentCode = function() {
|
|
359
|
-
var _ref = _async_to_generator(function(resourcePath, source2) {
|
|
360
|
-
var warning, options, lambdaDir, result;
|
|
361
|
-
return _ts_generator(this, function(_state2) {
|
|
362
|
-
switch (_state2.label) {
|
|
363
|
-
case 0:
|
|
364
|
-
warning = "The file ".concat(resourcePath, " is not allowd to be imported in src directory, only API definition files are allowed.");
|
|
365
|
-
if (!draftOptions.existLambda) {
|
|
366
|
-
logger.warn(warning);
|
|
367
|
-
return [
|
|
368
|
-
2
|
|
369
|
-
];
|
|
370
|
-
}
|
|
371
|
-
options = {
|
|
372
|
-
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
373
|
-
appDir: draftOptions.appDir,
|
|
374
|
-
apiDir: draftOptions.apiDir,
|
|
375
|
-
lambdaDir: draftOptions.lambdaDir,
|
|
376
|
-
port: Number(draftOptions.port),
|
|
377
|
-
source: source2,
|
|
378
|
-
resourcePath,
|
|
379
|
-
target: "bundle",
|
|
380
|
-
httpMethodDecider: draftOptions.httpMethodDecider,
|
|
381
|
-
requestCreator: draftOptions.requestCreator
|
|
382
|
-
};
|
|
383
|
-
lambdaDir = draftOptions.lambdaDir;
|
|
384
|
-
if (!resourcePath.startsWith(lambdaDir)) {
|
|
385
|
-
logger.warn(warning);
|
|
386
|
-
return [
|
|
387
|
-
2
|
|
388
|
-
];
|
|
389
|
-
}
|
|
390
|
-
return [
|
|
391
|
-
4,
|
|
392
|
-
generateClient(options)
|
|
393
|
-
];
|
|
394
|
-
case 1:
|
|
395
|
-
result = _state2.sent();
|
|
396
|
-
return [
|
|
397
|
-
2,
|
|
398
|
-
result
|
|
399
|
-
];
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
return function getClitentCode2(resourcePath, source2) {
|
|
404
|
-
return _ref.apply(this, arguments);
|
|
405
|
-
};
|
|
406
|
-
}();
|
|
407
|
-
_state.label = 2;
|
|
408
|
-
case 2:
|
|
409
|
-
_state.trys.push([
|
|
410
|
-
2,
|
|
411
|
-
13,
|
|
412
|
-
,
|
|
413
|
-
14
|
|
414
|
-
]);
|
|
415
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
416
|
-
_state.label = 3;
|
|
417
|
-
case 3:
|
|
418
|
-
_state.trys.push([
|
|
419
|
-
3,
|
|
420
|
-
10,
|
|
421
|
-
11,
|
|
422
|
-
12
|
|
423
|
-
]);
|
|
424
|
-
_iterator = sourceList[Symbol.iterator]();
|
|
425
|
-
_state.label = 4;
|
|
426
|
-
case 4:
|
|
427
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
428
|
-
return [
|
|
429
|
-
3,
|
|
430
|
-
9
|
|
431
|
-
];
|
|
432
|
-
source = _step.value;
|
|
433
|
-
return [
|
|
434
|
-
4,
|
|
435
|
-
getClitentCode(source.resourcePath, source.source)
|
|
436
|
-
];
|
|
437
|
-
case 5:
|
|
438
|
-
code = _state.sent();
|
|
439
|
-
if (!(code === null || code === void 0 ? void 0 : code.value))
|
|
440
|
-
return [
|
|
441
|
-
3,
|
|
442
|
-
8
|
|
443
|
-
];
|
|
444
|
-
return [
|
|
445
|
-
4,
|
|
446
|
-
writeTargetFile(source.absTargetDir, code.value)
|
|
447
|
-
];
|
|
448
|
-
case 6:
|
|
449
|
-
_state.sent();
|
|
450
|
-
return [
|
|
451
|
-
4,
|
|
452
|
-
copyFiles(source.relativeTargetDistDir, source.targetDir.replace("js", "d.ts"))
|
|
453
|
-
];
|
|
454
|
-
case 7:
|
|
455
|
-
_state.sent();
|
|
456
|
-
_state.label = 8;
|
|
457
|
-
case 8:
|
|
458
|
-
_iteratorNormalCompletion = true;
|
|
459
|
-
return [
|
|
460
|
-
3,
|
|
461
|
-
4
|
|
462
|
-
];
|
|
463
|
-
case 9:
|
|
464
|
-
return [
|
|
465
|
-
3,
|
|
466
|
-
12
|
|
467
|
-
];
|
|
468
|
-
case 10:
|
|
469
|
-
err = _state.sent();
|
|
470
|
-
_didIteratorError = true;
|
|
471
|
-
_iteratorError = err;
|
|
472
|
-
return [
|
|
473
|
-
3,
|
|
474
|
-
12
|
|
475
|
-
];
|
|
476
|
-
case 11:
|
|
477
|
-
try {
|
|
478
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
479
|
-
_iterator.return();
|
|
480
|
-
}
|
|
481
|
-
} finally {
|
|
482
|
-
if (_didIteratorError) {
|
|
483
|
-
throw _iteratorError;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return [
|
|
487
|
-
7
|
|
488
|
-
];
|
|
489
|
-
case 12:
|
|
490
|
-
logger.info("Client bundle generate succeed");
|
|
491
|
-
return [
|
|
492
|
-
3,
|
|
493
|
-
14
|
|
494
|
-
];
|
|
495
|
-
case 13:
|
|
496
|
-
error = _state.sent();
|
|
497
|
-
logger.error("Client bundle generate failed: ".concat(error));
|
|
498
|
-
return [
|
|
499
|
-
3,
|
|
500
|
-
14
|
|
501
|
-
];
|
|
502
|
-
case 14:
|
|
503
|
-
setPackage(sourceList, draftOptions.appDir, draftOptions.relativeDistPath);
|
|
504
|
-
return [
|
|
505
|
-
2
|
|
506
|
-
];
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
return _clientGenerator.apply(this, arguments);
|
|
511
|
-
}
|
|
512
|
-
var clientGenerator_default = clientGenerator;
|
|
513
|
-
export {
|
|
514
|
-
copyFiles,
|
|
515
|
-
clientGenerator_default as default,
|
|
516
|
-
readDirectoryFiles
|
|
517
|
-
};
|