opticore-webapp 1.0.28 → 1.0.30
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/index.cjs +54 -41
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +54 -41
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -41,14 +41,14 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
|
|
|
41
41
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
42
42
|
|
|
43
43
|
// src/core/webServer.core.ts
|
|
44
|
-
var
|
|
44
|
+
var path3 = __toESM(require("path"), 1);
|
|
45
45
|
var import_node_process3 = __toESM(require("process"), 1);
|
|
46
|
-
var
|
|
46
|
+
var import_module2 = require("module");
|
|
47
47
|
var import_cors = __toESM(require("cors"), 1);
|
|
48
48
|
var import_opticore_catch_exception_error4 = require("opticore-catch-exception-error");
|
|
49
49
|
var import_opticore_express2 = require("opticore-express");
|
|
50
50
|
var import_opticore_env_access3 = require("opticore-env-access");
|
|
51
|
-
var
|
|
51
|
+
var import_opticore_translator5 = require("opticore-translator");
|
|
52
52
|
|
|
53
53
|
// src/core/handlers/eventProcess.handler.ts
|
|
54
54
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -108,11 +108,11 @@ function eventProcessHandler(localeLanguage) {
|
|
|
108
108
|
// src/application/service/core.service.ts
|
|
109
109
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
110
110
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
111
|
-
var
|
|
111
|
+
var path2 = __toESM(require("path"), 1);
|
|
112
112
|
var fs = __toESM(require("fs"), 1);
|
|
113
113
|
var import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
114
114
|
var import_opticore_http_response = require("opticore-http-response");
|
|
115
|
-
var
|
|
115
|
+
var import_opticore_translator3 = require("opticore-translator");
|
|
116
116
|
var import_opticore_env_access2 = require("opticore-env-access");
|
|
117
117
|
var import_opticore_logger = require("opticore-logger");
|
|
118
118
|
|
|
@@ -192,6 +192,17 @@ var loggerConfig = (envDir) => {
|
|
|
192
192
|
};
|
|
193
193
|
};
|
|
194
194
|
|
|
195
|
+
// src/core/config/loaders/translateLanguage.loader.ts
|
|
196
|
+
var import_path = __toESM(require("path"), 1);
|
|
197
|
+
var import_module = require("module");
|
|
198
|
+
var import_opticore_translator2 = require("opticore-translator");
|
|
199
|
+
var translateWebAppCoreLanguageLoader = () => {
|
|
200
|
+
const require2 = (0, import_module.createRequire)(importMetaUrl);
|
|
201
|
+
const packagePath = import_path.default.dirname(require2.resolve("opticore-webapp"));
|
|
202
|
+
const translateMsgJsonFilePath = import_path.default.join(packagePath, "utils", "translations");
|
|
203
|
+
import_opticore_translator2.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
204
|
+
};
|
|
205
|
+
|
|
195
206
|
// src/application/service/core.service.ts
|
|
196
207
|
var CoreService = class {
|
|
197
208
|
loggerConfig;
|
|
@@ -201,6 +212,7 @@ var CoreService = class {
|
|
|
201
212
|
this.loggerConfig = new import_opticore_logger.LoggerCore(loggerConfig(environnementPath));
|
|
202
213
|
this.environnementPath = environnementPath;
|
|
203
214
|
this.localLanguage = localLang;
|
|
215
|
+
translateWebAppCoreLanguageLoader();
|
|
204
216
|
}
|
|
205
217
|
/**
|
|
206
218
|
*
|
|
@@ -237,20 +249,20 @@ var CoreService = class {
|
|
|
237
249
|
getUsageMemory() {
|
|
238
250
|
const memoryData = import_node_process2.default.memoryUsage();
|
|
239
251
|
const data = {
|
|
240
|
-
[`${
|
|
241
|
-
[`${
|
|
242
|
-
[`${
|
|
243
|
-
[`${
|
|
244
|
-
[`${
|
|
245
|
-
[`${
|
|
252
|
+
[`${import_opticore_translator3.TranslationLoader.t("totalMemoryAllocated", this.localLanguage)}}`]: this.formatMemoryUsage(memoryData.rss),
|
|
253
|
+
[`${import_opticore_translator3.TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapTotal),
|
|
254
|
+
[`${import_opticore_translator3.TranslationLoader.t("memoryUsedExecution", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapUsed),
|
|
255
|
+
[`${import_opticore_translator3.TranslationLoader.t("externalMemory", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.external),
|
|
256
|
+
[`${import_opticore_translator3.TranslationLoader.t("memoryUsageUser", this.localLanguage)}`]: this.formatMemoryUsage(import_node_process2.default.cpuUsage().user),
|
|
257
|
+
[`${import_opticore_translator3.TranslationLoader.t("memoryUsageSystem", this.localLanguage)}`]: this.formatMemoryUsage(import_node_process2.default.cpuUsage().system)
|
|
246
258
|
};
|
|
247
259
|
return {
|
|
248
|
-
"rss": data[`${
|
|
249
|
-
"heapTotal": data[`${
|
|
250
|
-
"heapUsed": data[`${
|
|
251
|
-
"external": data[`${
|
|
252
|
-
"user": data[`${
|
|
253
|
-
"system": data[`${
|
|
260
|
+
"rss": data[`${import_opticore_translator3.TranslationLoader.t("totalMemoryAllocated", this.localLanguage)}}`],
|
|
261
|
+
"heapTotal": data[`${import_opticore_translator3.TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)}`],
|
|
262
|
+
"heapUsed": data[`${import_opticore_translator3.TranslationLoader.t("memoryUsedExecution", this.localLanguage)}`],
|
|
263
|
+
"external": data[`${import_opticore_translator3.TranslationLoader.t("externalMemory", this.localLanguage)}`],
|
|
264
|
+
"user": data[`${import_opticore_translator3.TranslationLoader.t("memoryUsageUser", this.localLanguage)}`],
|
|
265
|
+
"system": data[`${import_opticore_translator3.TranslationLoader.t("memoryUsageSystem", this.localLanguage)}`]
|
|
254
266
|
};
|
|
255
267
|
}
|
|
256
268
|
/**
|
|
@@ -261,7 +273,7 @@ var CoreService = class {
|
|
|
261
273
|
const endTime = import_node_process2.default.hrtime(startTime);
|
|
262
274
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
263
275
|
return {
|
|
264
|
-
"projectPath":
|
|
276
|
+
"projectPath": path2.join(import_node_process2.default.cwd()),
|
|
265
277
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
266
278
|
};
|
|
267
279
|
}
|
|
@@ -271,7 +283,7 @@ var CoreService = class {
|
|
|
271
283
|
* @private
|
|
272
284
|
*/
|
|
273
285
|
getEnvFileLoading(filePath) {
|
|
274
|
-
const fullPath =
|
|
286
|
+
const fullPath = path2.resolve(import_node_process2.default.cwd(), filePath);
|
|
275
287
|
if (fs.existsSync(fullPath)) {
|
|
276
288
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
277
289
|
const lines = env.split("\n");
|
|
@@ -293,22 +305,22 @@ var CoreService = class {
|
|
|
293
305
|
this.getEnvFileLoading(".env");
|
|
294
306
|
const isDevelopment = import_node_process2.default.env.NODE_ENV === "development";
|
|
295
307
|
if (isDevelopment) {
|
|
296
|
-
return `${
|
|
308
|
+
return `${import_opticore_translator3.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors3.default.bgBlue(`${import_ansi_colors3.default.bold(`${development}`)}`)} mode`;
|
|
297
309
|
} else {
|
|
298
|
-
return `${
|
|
310
|
+
return `${import_opticore_translator3.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors3.default.bgBlue(`${import_ansi_colors3.default.bold(`${production}`)}`)} mode`;
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
313
|
infoServer(nodeVersion, startingTime, host, port) {
|
|
302
314
|
const paddingLength = 52;
|
|
303
315
|
const getEnvironnement = (0, import_opticore_env_access2.getEnvironnementValue)(this.environnementPath);
|
|
304
316
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
305
|
-
const msg1 = ` ${
|
|
317
|
+
const msg1 = ` ${import_opticore_translator3.TranslationLoader.t("webServerListening", this.localLanguage)}`;
|
|
306
318
|
const msg2Value = `${import_ansi_colors3.default.bgBlue(`${import_ansi_colors3.default.bold(`${nodeVersion}`)}`)}`;
|
|
307
|
-
const msg2 = ` ${
|
|
319
|
+
const msg2 = ` ${import_opticore_translator3.TranslationLoader.t("webServerUsingNodeVersion", this.localLanguage)}`;
|
|
308
320
|
const msg3Value = `${import_ansi_colors3.default.bgBlue(`${import_ansi_colors3.default.bold(`${startingTime}`)}`)}`;
|
|
309
|
-
const msg3 = ` ${
|
|
310
|
-
const msg4 = ` ${this.getServerRunningMode(`${
|
|
311
|
-
const msg5 = ` ${import_ansi_colors3.default.underline(`${getEnvironnement.protocolTransfert}://${host}:${port}`)}`;
|
|
321
|
+
const msg3 = ` ${import_opticore_translator3.TranslationLoader.t("startTime", this.localLanguage)}`;
|
|
322
|
+
const msg4 = ` ${this.getServerRunningMode(`${import_opticore_translator3.TranslationLoader.t("runningModeDev", this.localLanguage)}`, `${import_opticore_translator3.TranslationLoader.t("runningModeProd", this.localLanguage)}`)}`;
|
|
323
|
+
const msg5 = getEnvironnement.protocolTransfert === "" ? "http" : ` ${import_ansi_colors3.default.underline(`${getEnvironnement.protocolTransfert}://${host}:${port}`)}`;
|
|
312
324
|
console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
313
325
|
console.log(import_chalk.default.bgGreen.white(msg1.padEnd(paddingLength, " ")));
|
|
314
326
|
console.log(import_chalk.default.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
|
|
@@ -335,8 +347,8 @@ var CoreService = class {
|
|
|
335
347
|
})();
|
|
336
348
|
} else {
|
|
337
349
|
const stackTrace = STraceError(
|
|
338
|
-
|
|
339
|
-
|
|
350
|
+
import_opticore_translator3.TranslationLoader.t("loadedModulesError", this.localLanguage),
|
|
351
|
+
import_opticore_translator3.TranslationLoader.t("loadedModules", this.localLanguage),
|
|
340
352
|
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE,
|
|
341
353
|
true
|
|
342
354
|
);
|
|
@@ -349,7 +361,7 @@ var CoreService = class {
|
|
|
349
361
|
var import_assert = __toESM(require("assert"), 1);
|
|
350
362
|
var import_opticore_catch_exception_error3 = require("opticore-catch-exception-error");
|
|
351
363
|
var import_opticore_http_response2 = require("opticore-http-response");
|
|
352
|
-
var
|
|
364
|
+
var import_opticore_translator4 = require("opticore-translator");
|
|
353
365
|
var SServerStartError = (err, javaScriptErrors, systemErrors, openSSLErrors, internalErrors, logger, localLanguage) => {
|
|
354
366
|
switch (err.name) {
|
|
355
367
|
case import_opticore_catch_exception_error3.CErrorName.typeError:
|
|
@@ -420,13 +432,13 @@ var SServerStartError = (err, javaScriptErrors, systemErrors, openSSLErrors, int
|
|
|
420
432
|
true
|
|
421
433
|
);
|
|
422
434
|
err instanceof import_assert.default.AssertionError ? logger.error(
|
|
423
|
-
|
|
435
|
+
import_opticore_translator4.TranslationLoader.t(stackTrace.name, localLanguage),
|
|
424
436
|
"AssertionError",
|
|
425
437
|
stackTrace.name,
|
|
426
438
|
stackTrace.stack,
|
|
427
439
|
import_opticore_http_response2.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
428
440
|
) : logger.error(
|
|
429
|
-
|
|
441
|
+
import_opticore_translator4.TranslationLoader.t(stackTrace.name, localLanguage),
|
|
430
442
|
"Another Error",
|
|
431
443
|
stackTrace.name,
|
|
432
444
|
stackTrace.stack,
|
|
@@ -500,7 +512,7 @@ var WebServerCore = class {
|
|
|
500
512
|
this.stackTraceErrorHandling(localLanguage);
|
|
501
513
|
this.translationWebAppLoader();
|
|
502
514
|
}
|
|
503
|
-
onStartServer(routers, dbConnexion) {
|
|
515
|
+
onStartServer(routers, dbConnexion, dependenciesContainerService) {
|
|
504
516
|
return this.expressApp.listen(
|
|
505
517
|
Number(this.getEnvironnement.appPort),
|
|
506
518
|
() => {
|
|
@@ -513,7 +525,8 @@ var WebServerCore = class {
|
|
|
513
525
|
this.serverListenEvent.portUndefined();
|
|
514
526
|
} else {
|
|
515
527
|
dbConnexion;
|
|
516
|
-
|
|
528
|
+
dependenciesContainerService;
|
|
529
|
+
this.expressApp.use(import_opticore_express2.express.static(path3.join(import_node_process3.default.cwd(), "public/template")));
|
|
517
530
|
this.registerRoutes(routers);
|
|
518
531
|
}
|
|
519
532
|
} catch (err) {
|
|
@@ -555,10 +568,10 @@ var WebServerCore = class {
|
|
|
555
568
|
});
|
|
556
569
|
}
|
|
557
570
|
translationWebAppLoader() {
|
|
558
|
-
const require2 = (0,
|
|
559
|
-
const packagePath =
|
|
560
|
-
const translateMsgJsonFilePath =
|
|
561
|
-
|
|
571
|
+
const require2 = (0, import_module2.createRequire)(importMetaUrl);
|
|
572
|
+
const packagePath = path3.dirname(require2.resolve("opticore-webapp"));
|
|
573
|
+
const translateMsgJsonFilePath = path3.join(packagePath, "utils", "translations");
|
|
574
|
+
import_opticore_translator5.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
562
575
|
}
|
|
563
576
|
registerRoutes(allFeatureRoutes) {
|
|
564
577
|
allFeatureRoutes.map((router) => {
|
|
@@ -587,7 +600,7 @@ var envPath = import_process.default.cwd() + "/config/env/.env";
|
|
|
587
600
|
// src/utils/stopServer.utils.ts
|
|
588
601
|
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
589
602
|
var import_child_process = require("child_process");
|
|
590
|
-
var
|
|
603
|
+
var import_opticore_translator6 = require("opticore-translator");
|
|
591
604
|
|
|
592
605
|
// src/application/service/logger.service.ts
|
|
593
606
|
var import_opticore_logger2 = require("opticore-logger");
|
|
@@ -603,12 +616,12 @@ var UStopServer = () => {
|
|
|
603
616
|
const pid = (0, import_child_process.execSync)(`lsof -i :${port} -t`, { encoding: "utf-8" }).trim();
|
|
604
617
|
if (pid) {
|
|
605
618
|
(0, import_child_process.execSync)(`kill ${pid}`);
|
|
606
|
-
SLogger().success("serverPortKill",
|
|
619
|
+
SLogger().success("serverPortKill", import_opticore_translator6.TranslationLoader.t("serverPortKill", "en", { port }));
|
|
607
620
|
} else {
|
|
608
|
-
SLogger().warn("pidOnPortNotFound",
|
|
621
|
+
SLogger().warn("pidOnPortNotFound", import_opticore_translator6.TranslationLoader.t("pidOnPortNotFound", "en", { port }));
|
|
609
622
|
}
|
|
610
623
|
} catch (error) {
|
|
611
|
-
SLogger().error("noProcessRunningOnPort",
|
|
624
|
+
SLogger().error("noProcessRunningOnPort", import_opticore_translator6.TranslationLoader.t("noProcessRunningOnPort", "en", { port }));
|
|
612
625
|
}
|
|
613
626
|
};
|
|
614
627
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import { CorsOptions } from 'cors';
|
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import { Router, express } from 'opticore-express';
|
|
4
4
|
import { LoggerCore } from 'opticore-logger';
|
|
5
|
+
import { SContainer } from 'opticore-inject-dependency';
|
|
5
6
|
|
|
6
7
|
interface IRouteDefinition {
|
|
7
8
|
path: string;
|
|
@@ -27,7 +28,7 @@ declare class WebServerCore {
|
|
|
27
28
|
private readonly openSSLErrors;
|
|
28
29
|
private readonly systemErrors;
|
|
29
30
|
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, environnementPath: any, corsOriginOptions?: Partial<CorsOptions>);
|
|
30
|
-
onStartServer(routers: TFeatureRoutes[], dbConnexion: (envPath: any, optionalArgumentConnection?: string | any) => void): any;
|
|
31
|
+
onStartServer(routers: TFeatureRoutes[], dbConnexion: (envPath: any, optionalArgumentConnection?: string | any) => void, dependenciesContainerService: () => SContainer): any;
|
|
31
32
|
onListeningOnServerEvent(serverWeb: Server): void;
|
|
32
33
|
onRequestOnServerEvent(serverWeb: Server): void;
|
|
33
34
|
private translationWebAppLoader;
|
|
@@ -40,8 +41,10 @@ declare const envPath: string;
|
|
|
40
41
|
|
|
41
42
|
declare const UStopServer: () => void;
|
|
42
43
|
|
|
43
|
-
type
|
|
44
|
+
type TFeatureRouteDefinition = {
|
|
44
45
|
featureRoute: IRouteDefinition[];
|
|
45
|
-
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type KernelModuleType = [TFeatureRouteDefinition[], () => void];
|
|
46
49
|
|
|
47
50
|
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, UStopServer, WebServerCore as WebServer, envPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { CorsOptions } from 'cors';
|
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import { Router, express } from 'opticore-express';
|
|
4
4
|
import { LoggerCore } from 'opticore-logger';
|
|
5
|
+
import { SContainer } from 'opticore-inject-dependency';
|
|
5
6
|
|
|
6
7
|
interface IRouteDefinition {
|
|
7
8
|
path: string;
|
|
@@ -27,7 +28,7 @@ declare class WebServerCore {
|
|
|
27
28
|
private readonly openSSLErrors;
|
|
28
29
|
private readonly systemErrors;
|
|
29
30
|
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, environnementPath: any, corsOriginOptions?: Partial<CorsOptions>);
|
|
30
|
-
onStartServer(routers: TFeatureRoutes[], dbConnexion: (envPath: any, optionalArgumentConnection?: string | any) => void): any;
|
|
31
|
+
onStartServer(routers: TFeatureRoutes[], dbConnexion: (envPath: any, optionalArgumentConnection?: string | any) => void, dependenciesContainerService: () => SContainer): any;
|
|
31
32
|
onListeningOnServerEvent(serverWeb: Server): void;
|
|
32
33
|
onRequestOnServerEvent(serverWeb: Server): void;
|
|
33
34
|
private translationWebAppLoader;
|
|
@@ -40,8 +41,10 @@ declare const envPath: string;
|
|
|
40
41
|
|
|
41
42
|
declare const UStopServer: () => void;
|
|
42
43
|
|
|
43
|
-
type
|
|
44
|
+
type TFeatureRouteDefinition = {
|
|
44
45
|
featureRoute: IRouteDefinition[];
|
|
45
|
-
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type KernelModuleType = [TFeatureRouteDefinition[], () => void];
|
|
46
49
|
|
|
47
50
|
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, UStopServer, WebServerCore as WebServer, envPath };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/core/webServer.core.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as path3 from "path";
|
|
3
3
|
import process4 from "node:process";
|
|
4
|
-
import { createRequire } from "module";
|
|
4
|
+
import { createRequire as createRequire2 } from "module";
|
|
5
5
|
import corsOrigin from "cors";
|
|
6
6
|
import {
|
|
7
7
|
CEventNameError as eventName2,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "opticore-catch-exception-error";
|
|
15
15
|
import { express as express2 } from "opticore-express";
|
|
16
16
|
import { getEnvironnementValue as getEnvironnementValue3 } from "opticore-env-access";
|
|
17
|
-
import { TranslationLoader as
|
|
17
|
+
import { TranslationLoader as TranslationLoader5 } from "opticore-translator";
|
|
18
18
|
|
|
19
19
|
// src/core/handlers/eventProcess.handler.ts
|
|
20
20
|
import process2 from "node:process";
|
|
@@ -78,11 +78,11 @@ function eventProcessHandler(localeLanguage) {
|
|
|
78
78
|
// src/application/service/core.service.ts
|
|
79
79
|
import process3 from "node:process";
|
|
80
80
|
import chalk from "chalk";
|
|
81
|
-
import * as
|
|
81
|
+
import * as path2 from "path";
|
|
82
82
|
import * as fs from "fs";
|
|
83
83
|
import colors3 from "ansi-colors";
|
|
84
84
|
import { HttpStatusCode as status } from "opticore-http-response";
|
|
85
|
-
import { TranslationLoader as
|
|
85
|
+
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
86
86
|
import { getEnvironnementValue as getEnvironnementValue2 } from "opticore-env-access";
|
|
87
87
|
import { LoggerCore } from "opticore-logger";
|
|
88
88
|
|
|
@@ -162,6 +162,17 @@ var loggerConfig = (envDir) => {
|
|
|
162
162
|
};
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
+
// src/core/config/loaders/translateLanguage.loader.ts
|
|
166
|
+
import path from "path";
|
|
167
|
+
import { createRequire } from "module";
|
|
168
|
+
import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
169
|
+
var translateWebAppCoreLanguageLoader = () => {
|
|
170
|
+
const require2 = createRequire(import.meta.url);
|
|
171
|
+
const packagePath = path.dirname(require2.resolve("opticore-webapp"));
|
|
172
|
+
const translateMsgJsonFilePath = path.join(packagePath, "utils", "translations");
|
|
173
|
+
TranslationLoader2.loadTranslations(translateMsgJsonFilePath);
|
|
174
|
+
};
|
|
175
|
+
|
|
165
176
|
// src/application/service/core.service.ts
|
|
166
177
|
var CoreService = class {
|
|
167
178
|
loggerConfig;
|
|
@@ -171,6 +182,7 @@ var CoreService = class {
|
|
|
171
182
|
this.loggerConfig = new LoggerCore(loggerConfig(environnementPath));
|
|
172
183
|
this.environnementPath = environnementPath;
|
|
173
184
|
this.localLanguage = localLang;
|
|
185
|
+
translateWebAppCoreLanguageLoader();
|
|
174
186
|
}
|
|
175
187
|
/**
|
|
176
188
|
*
|
|
@@ -207,20 +219,20 @@ var CoreService = class {
|
|
|
207
219
|
getUsageMemory() {
|
|
208
220
|
const memoryData = process3.memoryUsage();
|
|
209
221
|
const data = {
|
|
210
|
-
[`${
|
|
211
|
-
[`${
|
|
212
|
-
[`${
|
|
213
|
-
[`${
|
|
214
|
-
[`${
|
|
215
|
-
[`${
|
|
222
|
+
[`${TranslationLoader3.t("totalMemoryAllocated", this.localLanguage)}}`]: this.formatMemoryUsage(memoryData.rss),
|
|
223
|
+
[`${TranslationLoader3.t("sizeAllocatedHeap", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapTotal),
|
|
224
|
+
[`${TranslationLoader3.t("memoryUsedExecution", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapUsed),
|
|
225
|
+
[`${TranslationLoader3.t("externalMemory", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.external),
|
|
226
|
+
[`${TranslationLoader3.t("memoryUsageUser", this.localLanguage)}`]: this.formatMemoryUsage(process3.cpuUsage().user),
|
|
227
|
+
[`${TranslationLoader3.t("memoryUsageSystem", this.localLanguage)}`]: this.formatMemoryUsage(process3.cpuUsage().system)
|
|
216
228
|
};
|
|
217
229
|
return {
|
|
218
|
-
"rss": data[`${
|
|
219
|
-
"heapTotal": data[`${
|
|
220
|
-
"heapUsed": data[`${
|
|
221
|
-
"external": data[`${
|
|
222
|
-
"user": data[`${
|
|
223
|
-
"system": data[`${
|
|
230
|
+
"rss": data[`${TranslationLoader3.t("totalMemoryAllocated", this.localLanguage)}}`],
|
|
231
|
+
"heapTotal": data[`${TranslationLoader3.t("sizeAllocatedHeap", this.localLanguage)}`],
|
|
232
|
+
"heapUsed": data[`${TranslationLoader3.t("memoryUsedExecution", this.localLanguage)}`],
|
|
233
|
+
"external": data[`${TranslationLoader3.t("externalMemory", this.localLanguage)}`],
|
|
234
|
+
"user": data[`${TranslationLoader3.t("memoryUsageUser", this.localLanguage)}`],
|
|
235
|
+
"system": data[`${TranslationLoader3.t("memoryUsageSystem", this.localLanguage)}`]
|
|
224
236
|
};
|
|
225
237
|
}
|
|
226
238
|
/**
|
|
@@ -231,7 +243,7 @@ var CoreService = class {
|
|
|
231
243
|
const endTime = process3.hrtime(startTime);
|
|
232
244
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
233
245
|
return {
|
|
234
|
-
"projectPath":
|
|
246
|
+
"projectPath": path2.join(process3.cwd()),
|
|
235
247
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
236
248
|
};
|
|
237
249
|
}
|
|
@@ -241,7 +253,7 @@ var CoreService = class {
|
|
|
241
253
|
* @private
|
|
242
254
|
*/
|
|
243
255
|
getEnvFileLoading(filePath) {
|
|
244
|
-
const fullPath =
|
|
256
|
+
const fullPath = path2.resolve(process3.cwd(), filePath);
|
|
245
257
|
if (fs.existsSync(fullPath)) {
|
|
246
258
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
247
259
|
const lines = env.split("\n");
|
|
@@ -263,22 +275,22 @@ var CoreService = class {
|
|
|
263
275
|
this.getEnvFileLoading(".env");
|
|
264
276
|
const isDevelopment = process3.env.NODE_ENV === "development";
|
|
265
277
|
if (isDevelopment) {
|
|
266
|
-
return `${
|
|
278
|
+
return `${TranslationLoader3.t("serverRunning", this.localLanguage)} ${colors3.bgBlue(`${colors3.bold(`${development}`)}`)} mode`;
|
|
267
279
|
} else {
|
|
268
|
-
return `${
|
|
280
|
+
return `${TranslationLoader3.t("serverRunning", this.localLanguage)} ${colors3.bgBlue(`${colors3.bold(`${production}`)}`)} mode`;
|
|
269
281
|
}
|
|
270
282
|
}
|
|
271
283
|
infoServer(nodeVersion, startingTime, host, port) {
|
|
272
284
|
const paddingLength = 52;
|
|
273
285
|
const getEnvironnement = getEnvironnementValue2(this.environnementPath);
|
|
274
286
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
275
|
-
const msg1 = ` ${
|
|
287
|
+
const msg1 = ` ${TranslationLoader3.t("webServerListening", this.localLanguage)}`;
|
|
276
288
|
const msg2Value = `${colors3.bgBlue(`${colors3.bold(`${nodeVersion}`)}`)}`;
|
|
277
|
-
const msg2 = ` ${
|
|
289
|
+
const msg2 = ` ${TranslationLoader3.t("webServerUsingNodeVersion", this.localLanguage)}`;
|
|
278
290
|
const msg3Value = `${colors3.bgBlue(`${colors3.bold(`${startingTime}`)}`)}`;
|
|
279
|
-
const msg3 = ` ${
|
|
280
|
-
const msg4 = ` ${this.getServerRunningMode(`${
|
|
281
|
-
const msg5 = ` ${colors3.underline(`${getEnvironnement.protocolTransfert}://${host}:${port}`)}`;
|
|
291
|
+
const msg3 = ` ${TranslationLoader3.t("startTime", this.localLanguage)}`;
|
|
292
|
+
const msg4 = ` ${this.getServerRunningMode(`${TranslationLoader3.t("runningModeDev", this.localLanguage)}`, `${TranslationLoader3.t("runningModeProd", this.localLanguage)}`)}`;
|
|
293
|
+
const msg5 = getEnvironnement.protocolTransfert === "" ? "http" : ` ${colors3.underline(`${getEnvironnement.protocolTransfert}://${host}:${port}`)}`;
|
|
282
294
|
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
283
295
|
console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, " ")));
|
|
284
296
|
console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
|
|
@@ -305,8 +317,8 @@ var CoreService = class {
|
|
|
305
317
|
})();
|
|
306
318
|
} else {
|
|
307
319
|
const stackTrace = STraceError(
|
|
308
|
-
|
|
309
|
-
|
|
320
|
+
TranslationLoader3.t("loadedModulesError", this.localLanguage),
|
|
321
|
+
TranslationLoader3.t("loadedModules", this.localLanguage),
|
|
310
322
|
status.NOT_ACCEPTABLE,
|
|
311
323
|
true
|
|
312
324
|
);
|
|
@@ -319,7 +331,7 @@ var CoreService = class {
|
|
|
319
331
|
import assert from "assert";
|
|
320
332
|
import { CErrorName } from "opticore-catch-exception-error";
|
|
321
333
|
import { HttpStatusCode } from "opticore-http-response";
|
|
322
|
-
import { TranslationLoader as
|
|
334
|
+
import { TranslationLoader as TranslationLoader4 } from "opticore-translator";
|
|
323
335
|
var SServerStartError = (err, javaScriptErrors, systemErrors, openSSLErrors, internalErrors, logger, localLanguage) => {
|
|
324
336
|
switch (err.name) {
|
|
325
337
|
case CErrorName.typeError:
|
|
@@ -390,13 +402,13 @@ var SServerStartError = (err, javaScriptErrors, systemErrors, openSSLErrors, int
|
|
|
390
402
|
true
|
|
391
403
|
);
|
|
392
404
|
err instanceof assert.AssertionError ? logger.error(
|
|
393
|
-
|
|
405
|
+
TranslationLoader4.t(stackTrace.name, localLanguage),
|
|
394
406
|
"AssertionError",
|
|
395
407
|
stackTrace.name,
|
|
396
408
|
stackTrace.stack,
|
|
397
409
|
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
398
410
|
) : logger.error(
|
|
399
|
-
|
|
411
|
+
TranslationLoader4.t(stackTrace.name, localLanguage),
|
|
400
412
|
"Another Error",
|
|
401
413
|
stackTrace.name,
|
|
402
414
|
stackTrace.stack,
|
|
@@ -470,7 +482,7 @@ var WebServerCore = class {
|
|
|
470
482
|
this.stackTraceErrorHandling(localLanguage);
|
|
471
483
|
this.translationWebAppLoader();
|
|
472
484
|
}
|
|
473
|
-
onStartServer(routers, dbConnexion) {
|
|
485
|
+
onStartServer(routers, dbConnexion, dependenciesContainerService) {
|
|
474
486
|
return this.expressApp.listen(
|
|
475
487
|
Number(this.getEnvironnement.appPort),
|
|
476
488
|
() => {
|
|
@@ -483,7 +495,8 @@ var WebServerCore = class {
|
|
|
483
495
|
this.serverListenEvent.portUndefined();
|
|
484
496
|
} else {
|
|
485
497
|
dbConnexion;
|
|
486
|
-
|
|
498
|
+
dependenciesContainerService;
|
|
499
|
+
this.expressApp.use(express2.static(path3.join(process4.cwd(), "public/template")));
|
|
487
500
|
this.registerRoutes(routers);
|
|
488
501
|
}
|
|
489
502
|
} catch (err) {
|
|
@@ -525,10 +538,10 @@ var WebServerCore = class {
|
|
|
525
538
|
});
|
|
526
539
|
}
|
|
527
540
|
translationWebAppLoader() {
|
|
528
|
-
const require2 =
|
|
529
|
-
const packagePath =
|
|
530
|
-
const translateMsgJsonFilePath =
|
|
531
|
-
|
|
541
|
+
const require2 = createRequire2(import.meta.url);
|
|
542
|
+
const packagePath = path3.dirname(require2.resolve("opticore-webapp"));
|
|
543
|
+
const translateMsgJsonFilePath = path3.join(packagePath, "utils", "translations");
|
|
544
|
+
TranslationLoader5.loadTranslations(translateMsgJsonFilePath);
|
|
532
545
|
}
|
|
533
546
|
registerRoutes(allFeatureRoutes) {
|
|
534
547
|
allFeatureRoutes.map((router) => {
|
|
@@ -557,7 +570,7 @@ var envPath = process5.cwd() + "/config/env/.env";
|
|
|
557
570
|
// src/utils/stopServer.utils.ts
|
|
558
571
|
import dotenv from "dotenv";
|
|
559
572
|
import { execSync } from "child_process";
|
|
560
|
-
import { TranslationLoader as
|
|
573
|
+
import { TranslationLoader as TranslationLoader6 } from "opticore-translator";
|
|
561
574
|
|
|
562
575
|
// src/application/service/logger.service.ts
|
|
563
576
|
import { LoggerCore as LoggerCore2 } from "opticore-logger";
|
|
@@ -573,12 +586,12 @@ var UStopServer = () => {
|
|
|
573
586
|
const pid = execSync(`lsof -i :${port} -t`, { encoding: "utf-8" }).trim();
|
|
574
587
|
if (pid) {
|
|
575
588
|
execSync(`kill ${pid}`);
|
|
576
|
-
SLogger().success("serverPortKill",
|
|
589
|
+
SLogger().success("serverPortKill", TranslationLoader6.t("serverPortKill", "en", { port }));
|
|
577
590
|
} else {
|
|
578
|
-
SLogger().warn("pidOnPortNotFound",
|
|
591
|
+
SLogger().warn("pidOnPortNotFound", TranslationLoader6.t("pidOnPortNotFound", "en", { port }));
|
|
579
592
|
}
|
|
580
593
|
} catch (error) {
|
|
581
|
-
SLogger().error("noProcessRunningOnPort",
|
|
594
|
+
SLogger().error("noProcessRunningOnPort", TranslationLoader6.t("noProcessRunningOnPort", "en", { port }));
|
|
582
595
|
}
|
|
583
596
|
};
|
|
584
597
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.30",
|
|
4
4
|
"description": "wep server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"opticore-env-access": "^1.0.6",
|
|
34
34
|
"opticore-express": "^1.0.3",
|
|
35
35
|
"opticore-http-response": "^1.0.3",
|
|
36
|
+
"opticore-inject-dependency": "^1.0.6",
|
|
36
37
|
"opticore-logger": "^1.0.14",
|
|
37
38
|
"opticore-request-call-event": "^1.0.2",
|
|
38
39
|
"opticore-router": "^1.0.11",
|
|
@@ -40,9 +41,9 @@
|
|
|
40
41
|
"opticore-validator": "^1.0.3"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^22.13.14",
|
|
44
44
|
"@types/cors": "^2.8.17",
|
|
45
45
|
"@types/gradient-string": "^1.1.6",
|
|
46
|
+
"@types/node": "^22.13.14",
|
|
46
47
|
"reflect-metadata": "^0.2.2",
|
|
47
48
|
"tslib": "^2.8.1",
|
|
48
49
|
"tsup": "^8.4.0",
|