@nestia/editor 0.6.2 → 0.7.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/dist/assets/index-CTk_peMA.js +4623 -0
- package/dist/index.html +19 -0
- package/lib/NestiaEditorModule.d.ts +30 -0
- package/lib/NestiaEditorModule.js +219 -0
- package/lib/NestiaEditorModule.js.map +1 -0
- package/package.json +11 -3
- package/src/NestiaEditorModule.ts +130 -0
package/dist/index.html
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<html lang="en">
|
|
2
|
+
<head>
|
|
3
|
+
<meta charset="UTF-8" />
|
|
4
|
+
<meta
|
|
5
|
+
name="viewport"
|
|
6
|
+
content="width=device-width, height=device-height, initial-scale=1, minimum-scale=1.0, maximum-scale=3.0s"
|
|
7
|
+
/>
|
|
8
|
+
<title>Nestia Editor</title>
|
|
9
|
+
<script type="module" src="./assets/index-CTk_peMA.js"></script>
|
|
10
|
+
</head>
|
|
11
|
+
<body style="width: 100%; height: 100%; margin: 0px; overflow: hidden;">
|
|
12
|
+
<div id="root" style="width: 100%; height: 100%"></div>
|
|
13
|
+
<script>
|
|
14
|
+
window.package = "@ORGANIZATION/PROJECT";
|
|
15
|
+
window.simulate = false;
|
|
16
|
+
window.e2e = false;
|
|
17
|
+
</script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
|
|
2
|
+
export declare namespace NestiaEditorModule {
|
|
3
|
+
const setup: (props: {
|
|
4
|
+
path: string;
|
|
5
|
+
application: INestApplication;
|
|
6
|
+
swagger: string | SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument;
|
|
7
|
+
package?: string;
|
|
8
|
+
simulate?: boolean;
|
|
9
|
+
e2e?: boolean;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
interface INestApplication {
|
|
13
|
+
use(...args: any[]): this;
|
|
14
|
+
getUrl(): Promise<string>;
|
|
15
|
+
getHttpAdapter(): INestHttpAdaptor;
|
|
16
|
+
setGlobalPrefix(prefix: string, options?: any): this;
|
|
17
|
+
}
|
|
18
|
+
interface INestHttpAdaptor {
|
|
19
|
+
getType(): string;
|
|
20
|
+
close(): any;
|
|
21
|
+
init?(): Promise<void>;
|
|
22
|
+
get: Function;
|
|
23
|
+
post: Function;
|
|
24
|
+
put: Function;
|
|
25
|
+
patch: Function;
|
|
26
|
+
delete: Function;
|
|
27
|
+
head: Function;
|
|
28
|
+
all: Function;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
35
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
36
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
37
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
|
+
function step(op) {
|
|
39
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
|
+
switch (op[0]) {
|
|
44
|
+
case 0: case 1: t = op; break;
|
|
45
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
46
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
47
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
48
|
+
default:
|
|
49
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
50
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
51
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
52
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
53
|
+
if (t[2]) _.ops.pop();
|
|
54
|
+
_.trys.pop(); continue;
|
|
55
|
+
}
|
|
56
|
+
op = body.call(thisArg, _);
|
|
57
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
58
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var __values = (this && this.__values) || function(o) {
|
|
62
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
63
|
+
if (m) return m.call(o);
|
|
64
|
+
if (o && typeof o.length === "number") return {
|
|
65
|
+
next: function () {
|
|
66
|
+
if (o && i >= o.length) o = void 0;
|
|
67
|
+
return { value: o && o[i++], done: !o };
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
71
|
+
};
|
|
72
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
73
|
+
exports.NestiaEditorModule = void 0;
|
|
74
|
+
var fs = __importStar(require("fs"));
|
|
75
|
+
var NestiaEditorModule;
|
|
76
|
+
(function (NestiaEditorModule) {
|
|
77
|
+
var _this = this;
|
|
78
|
+
NestiaEditorModule.setup = function (props) { return __awaiter(_this, void 0, void 0, function () {
|
|
79
|
+
var prefix, adaptor, staticFiles, _a, _b, _c, _d, _loop_1, staticFiles_1, staticFiles_1_1, f, _e, _f, p;
|
|
80
|
+
var _g, _h, e_1, _j, e_2, _k;
|
|
81
|
+
return __generator(this, function (_l) {
|
|
82
|
+
switch (_l.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
prefix = "/" +
|
|
85
|
+
[getGlobalPrefix(props.application), props.path]
|
|
86
|
+
.join("/")
|
|
87
|
+
.split("/")
|
|
88
|
+
.filter(function (str) { return str.length !== 0; })
|
|
89
|
+
.join("/");
|
|
90
|
+
adaptor = props.application.getHttpAdapter();
|
|
91
|
+
_g = {
|
|
92
|
+
path: "/index.html",
|
|
93
|
+
type: "text/html"
|
|
94
|
+
};
|
|
95
|
+
return [4 /*yield*/, getIndex(props)];
|
|
96
|
+
case 1:
|
|
97
|
+
_a = [
|
|
98
|
+
(_g.content = _l.sent(),
|
|
99
|
+
_g)
|
|
100
|
+
];
|
|
101
|
+
_h = {
|
|
102
|
+
path: "/swagger.json",
|
|
103
|
+
type: "application/json"
|
|
104
|
+
};
|
|
105
|
+
_c = (_b = JSON).stringify;
|
|
106
|
+
if (!(typeof props.swagger === "string")) return [3 /*break*/, 3];
|
|
107
|
+
return [4 /*yield*/, getSwagger(props.swagger)];
|
|
108
|
+
case 2:
|
|
109
|
+
_d = _l.sent();
|
|
110
|
+
return [3 /*break*/, 4];
|
|
111
|
+
case 3:
|
|
112
|
+
_d = props.swagger;
|
|
113
|
+
_l.label = 4;
|
|
114
|
+
case 4:
|
|
115
|
+
_a = _a.concat([
|
|
116
|
+
(_h.content = _c.apply(_b, [_d, null,
|
|
117
|
+
2]),
|
|
118
|
+
_h)
|
|
119
|
+
]);
|
|
120
|
+
return [4 /*yield*/, getJavaScript()];
|
|
121
|
+
case 5:
|
|
122
|
+
staticFiles = _a.concat([
|
|
123
|
+
_l.sent()
|
|
124
|
+
]);
|
|
125
|
+
_loop_1 = function (f) {
|
|
126
|
+
adaptor.get(prefix + f.path, function (_, res) {
|
|
127
|
+
res.type(f.type);
|
|
128
|
+
return res.send(f.content);
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
try {
|
|
132
|
+
for (staticFiles_1 = __values(staticFiles), staticFiles_1_1 = staticFiles_1.next(); !staticFiles_1_1.done; staticFiles_1_1 = staticFiles_1.next()) {
|
|
133
|
+
f = staticFiles_1_1.value;
|
|
134
|
+
_loop_1(f);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
138
|
+
finally {
|
|
139
|
+
try {
|
|
140
|
+
if (staticFiles_1_1 && !staticFiles_1_1.done && (_j = staticFiles_1.return)) _j.call(staticFiles_1);
|
|
141
|
+
}
|
|
142
|
+
finally { if (e_1) throw e_1.error; }
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
for (_e = __values(["", "/"]), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
146
|
+
p = _f.value;
|
|
147
|
+
adaptor.get(prefix + p, function (_, res) {
|
|
148
|
+
return res.redirect(prefix + "/index.html");
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
153
|
+
finally {
|
|
154
|
+
try {
|
|
155
|
+
if (_f && !_f.done && (_k = _e.return)) _k.call(_e);
|
|
156
|
+
}
|
|
157
|
+
finally { if (e_2) throw e_2.error; }
|
|
158
|
+
}
|
|
159
|
+
return [2 /*return*/];
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}); };
|
|
163
|
+
var getGlobalPrefix = function (app) {
|
|
164
|
+
var _a;
|
|
165
|
+
return typeof ((_a = app.config) === null || _a === void 0 ? void 0 : _a.globalPrefix) === "string"
|
|
166
|
+
? app.config.globalPrefix
|
|
167
|
+
: "";
|
|
168
|
+
};
|
|
169
|
+
})(NestiaEditorModule || (exports.NestiaEditorModule = NestiaEditorModule = {}));
|
|
170
|
+
var getIndex = function (props) { return __awaiter(void 0, void 0, void 0, function () {
|
|
171
|
+
var content;
|
|
172
|
+
var _a;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
175
|
+
case 0: return [4 /*yield*/, fs.promises.readFile("".concat(__dirname, "/../dist/index.html"), "utf8")];
|
|
176
|
+
case 1:
|
|
177
|
+
content = _b.sent();
|
|
178
|
+
return [2 /*return*/, content
|
|
179
|
+
.replace("\"@ORGANIZATION/PROJECT\"", JSON.stringify((_a = props.package) !== null && _a !== void 0 ? _a : "@ORGANIZATION/PROJECT"))
|
|
180
|
+
.replace("window.simulate = false", "window.simulate = ".concat(!!props.simulate))
|
|
181
|
+
.replace("window.e2e = false", "window.e2e = ".concat(!!props.e2e))];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}); };
|
|
185
|
+
var getJavaScript = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
186
|
+
var directory, path;
|
|
187
|
+
var _a;
|
|
188
|
+
return __generator(this, function (_b) {
|
|
189
|
+
switch (_b.label) {
|
|
190
|
+
case 0: return [4 /*yield*/, fs.promises.readdir("".concat(__dirname, "/../dist/assets"))];
|
|
191
|
+
case 1:
|
|
192
|
+
directory = _b.sent();
|
|
193
|
+
path = directory[0];
|
|
194
|
+
if (path === undefined)
|
|
195
|
+
throw new Error("Unreachable code, no JS file exists.");
|
|
196
|
+
_a = {
|
|
197
|
+
path: "/assets/".concat(path),
|
|
198
|
+
type: "application/javascript"
|
|
199
|
+
};
|
|
200
|
+
return [4 /*yield*/, fs.promises.readFile("".concat(__dirname, "/../dist/assets/").concat(path), "utf8")];
|
|
201
|
+
case 2: return [2 /*return*/, (_a.content = _b.sent(),
|
|
202
|
+
_a)];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}); };
|
|
206
|
+
var getSwagger = function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
207
|
+
var response;
|
|
208
|
+
return __generator(this, function (_a) {
|
|
209
|
+
switch (_a.label) {
|
|
210
|
+
case 0: return [4 /*yield*/, fetch(url)];
|
|
211
|
+
case 1:
|
|
212
|
+
response = _a.sent();
|
|
213
|
+
if (response.status !== 200)
|
|
214
|
+
throw new Error("Failed to fetch Swagger document from ".concat(url));
|
|
215
|
+
return [2 /*return*/, response.json()];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}); };
|
|
219
|
+
//# sourceMappingURL=NestiaEditorModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NestiaEditorModule.js","sourceRoot":"","sources":["../src/NestiaEditorModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qCAAyB;AAEzB,IAAiB,kBAAkB,CAwDlC;AAxDD,WAAiB,kBAAkB;;IACpB,wBAAK,GAAG,UAAO,KAW3B;;;;;;oBACO,MAAM,GACV,GAAG;wBACH,CAAC,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC;6BAC7C,IAAI,CAAC,GAAG,CAAC;6BACT,KAAK,CAAC,GAAG,CAAC;6BACV,MAAM,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,MAAM,KAAK,CAAC,EAAhB,CAAgB,CAAC;6BACjC,IAAI,CAAC,GAAG,CAAC,CAAC;oBACT,OAAO,GAAqB,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,CAAC;;wBAGjE,IAAI,EAAE,aAAa;wBACnB,IAAI,EAAE,WAAW;;oBACR,qBAAM,QAAQ,CAAC,KAAK,CAAC,EAAA;;;yBAA9B,UAAO,GAAE,SAAqB;;;;wBAG9B,IAAI,EAAE,eAAe;wBACrB,IAAI,EAAE,kBAAkB;;oBACf,KAAA,CAAA,KAAA,IAAI,CAAA,CAAC,SAAS,CAAA;yBACrB,CAAA,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,CAAA,EAAjC,wBAAiC;oBAC7B,qBAAM,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAA;;oBAA/B,KAAA,SAA+B,CAAA;;;oBAC/B,KAAA,KAAK,CAAC,OAA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|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"build
|
|
9
|
-
"build:static": "tsc -b && vite build",
|
|
8
|
+
"build": "npm run build:static && npm run build:lib",
|
|
9
|
+
"build:static": "rimraf dist && tsc -b && vite build",
|
|
10
|
+
"build:lib": "rimraf lib && tsc --project tsconfig.lib.json && rollup -c",
|
|
10
11
|
"dev": "vite",
|
|
11
12
|
"lint": "eslint .",
|
|
12
13
|
"preview": "vite preview"
|
|
@@ -42,9 +43,14 @@
|
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"@eslint/js": "^9.13.0",
|
|
46
|
+
"@nestjs/common": "^10.4.6",
|
|
47
|
+
"@nestjs/core": "^10.4.6",
|
|
48
|
+
"@nestjs/platform-express": "^10.4.6",
|
|
49
|
+
"@nestjs/platform-fastify": "^10.4.6",
|
|
45
50
|
"@rollup/plugin-terser": "^0.4.4",
|
|
46
51
|
"@rollup/plugin-typescript": "^12.1.1",
|
|
47
52
|
"@types/js-yaml": "^4.0.9",
|
|
53
|
+
"@types/node": "^22.8.6",
|
|
48
54
|
"@types/react": "^18.3.11",
|
|
49
55
|
"@types/react-dom": "^18.3.1",
|
|
50
56
|
"@vitejs/plugin-react": "^4.3.3",
|
|
@@ -55,6 +61,7 @@
|
|
|
55
61
|
"react": "^18.3.1",
|
|
56
62
|
"react-dom": "^18.3.1",
|
|
57
63
|
"rollup": "^4.24.2",
|
|
64
|
+
"ts-node": "^10.9.2",
|
|
58
65
|
"typescript": "^5.6.2",
|
|
59
66
|
"typescript-eslint": "^8.10.0",
|
|
60
67
|
"vite": "^5.4.9"
|
|
@@ -63,6 +70,7 @@
|
|
|
63
70
|
"README.md",
|
|
64
71
|
"LICENSE",
|
|
65
72
|
"package.json",
|
|
73
|
+
"dist",
|
|
66
74
|
"lib",
|
|
67
75
|
"src"
|
|
68
76
|
]
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@samchon/openapi";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
|
|
4
|
+
export namespace NestiaEditorModule {
|
|
5
|
+
export const setup = async (props: {
|
|
6
|
+
path: string;
|
|
7
|
+
application: INestApplication;
|
|
8
|
+
swagger:
|
|
9
|
+
| string
|
|
10
|
+
| SwaggerV2.IDocument
|
|
11
|
+
| OpenApiV3.IDocument
|
|
12
|
+
| OpenApiV3_1.IDocument;
|
|
13
|
+
package?: string;
|
|
14
|
+
simulate?: boolean;
|
|
15
|
+
e2e?: boolean;
|
|
16
|
+
}): Promise<void> => {
|
|
17
|
+
const prefix: string =
|
|
18
|
+
"/" +
|
|
19
|
+
[getGlobalPrefix(props.application), props.path]
|
|
20
|
+
.join("/")
|
|
21
|
+
.split("/")
|
|
22
|
+
.filter((str) => str.length !== 0)
|
|
23
|
+
.join("/");
|
|
24
|
+
const adaptor: INestHttpAdaptor = props.application.getHttpAdapter();
|
|
25
|
+
const staticFiles: IStaticFile[] = [
|
|
26
|
+
{
|
|
27
|
+
path: "/index.html",
|
|
28
|
+
type: "text/html",
|
|
29
|
+
content: await getIndex(props),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: "/swagger.json",
|
|
33
|
+
type: "application/json",
|
|
34
|
+
content: JSON.stringify(
|
|
35
|
+
typeof props.swagger === "string"
|
|
36
|
+
? await getSwagger(props.swagger)
|
|
37
|
+
: props.swagger,
|
|
38
|
+
null,
|
|
39
|
+
2,
|
|
40
|
+
),
|
|
41
|
+
},
|
|
42
|
+
await getJavaScript(),
|
|
43
|
+
];
|
|
44
|
+
for (const f of staticFiles) {
|
|
45
|
+
adaptor.get(prefix + f.path, (_: any, res: any) => {
|
|
46
|
+
res.type(f.type);
|
|
47
|
+
return res.send(f.content);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
for (const p of ["", "/"])
|
|
51
|
+
adaptor.get(prefix + p, (_: any, res: any) => {
|
|
52
|
+
return res.redirect(prefix + "/index.html");
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getGlobalPrefix = (app: INestApplication): string =>
|
|
57
|
+
typeof (app as any).config?.globalPrefix === "string"
|
|
58
|
+
? (app as any).config.globalPrefix
|
|
59
|
+
: "";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface INestApplication {
|
|
63
|
+
use(...args: any[]): this;
|
|
64
|
+
getUrl(): Promise<string>;
|
|
65
|
+
getHttpAdapter(): INestHttpAdaptor;
|
|
66
|
+
setGlobalPrefix(prefix: string, options?: any): this;
|
|
67
|
+
}
|
|
68
|
+
interface INestHttpAdaptor {
|
|
69
|
+
getType(): string;
|
|
70
|
+
close(): any;
|
|
71
|
+
init?(): Promise<void>;
|
|
72
|
+
get: Function;
|
|
73
|
+
post: Function;
|
|
74
|
+
put: Function;
|
|
75
|
+
patch: Function;
|
|
76
|
+
delete: Function;
|
|
77
|
+
head: Function;
|
|
78
|
+
all: Function;
|
|
79
|
+
}
|
|
80
|
+
interface IStaticFile {
|
|
81
|
+
path: string;
|
|
82
|
+
type: string;
|
|
83
|
+
content: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const getIndex = async (props: {
|
|
87
|
+
package?: string;
|
|
88
|
+
simulate?: boolean;
|
|
89
|
+
e2e?: boolean;
|
|
90
|
+
}): Promise<string> => {
|
|
91
|
+
const content: string = await fs.promises.readFile(
|
|
92
|
+
`${__dirname}/../dist/index.html`,
|
|
93
|
+
"utf8",
|
|
94
|
+
);
|
|
95
|
+
return content
|
|
96
|
+
.replace(
|
|
97
|
+
`"@ORGANIZATION/PROJECT"`,
|
|
98
|
+
JSON.stringify(props.package ?? "@ORGANIZATION/PROJECT"),
|
|
99
|
+
)
|
|
100
|
+
.replace("window.simulate = false", `window.simulate = ${!!props.simulate}`)
|
|
101
|
+
.replace("window.e2e = false", `window.e2e = ${!!props.e2e}`);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const getJavaScript = async (): Promise<IStaticFile> => {
|
|
105
|
+
const directory: string[] = await fs.promises.readdir(
|
|
106
|
+
`${__dirname}/../dist/assets`,
|
|
107
|
+
);
|
|
108
|
+
const path: string | undefined = directory[0];
|
|
109
|
+
if (path === undefined)
|
|
110
|
+
throw new Error("Unreachable code, no JS file exists.");
|
|
111
|
+
return {
|
|
112
|
+
path: `/assets/${path}`,
|
|
113
|
+
type: "application/javascript",
|
|
114
|
+
content: await fs.promises.readFile(
|
|
115
|
+
`${__dirname}/../dist/assets/${path}`,
|
|
116
|
+
"utf8",
|
|
117
|
+
),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const getSwagger = async (
|
|
122
|
+
url: string,
|
|
123
|
+
): Promise<
|
|
124
|
+
SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument
|
|
125
|
+
> => {
|
|
126
|
+
const response: Response = await fetch(url);
|
|
127
|
+
if (response.status !== 200)
|
|
128
|
+
throw new Error(`Failed to fetch Swagger document from ${url}`);
|
|
129
|
+
return response.json();
|
|
130
|
+
};
|