@dnax/core 0.15.8 → 0.16.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/app/index.ts +5 -3
- package/bin/index.ts +26 -1
- package/define/index.ts +8 -0
- package/lib/index.ts +3 -0
- package/lib/scripts/index.ts +42 -0
- package/package.json +1 -1
- package/types/index.ts +7 -0
package/app/index.ts
CHANGED
|
@@ -67,16 +67,18 @@ async function runApp(config?: configRunApp, clb?: Function) {
|
|
|
67
67
|
|
|
68
68
|
console.log();
|
|
69
69
|
let info = "";
|
|
70
|
-
info += "SERVER
|
|
70
|
+
info += "SERVER :".gray.italic.underline;
|
|
71
71
|
info += `\n`;
|
|
72
72
|
info += `\n`;
|
|
73
73
|
info +=
|
|
74
74
|
`Env: ${
|
|
75
|
-
process.env.NODE_ENV === "production"
|
|
75
|
+
process.env.NODE_ENV === "production"
|
|
76
|
+
? "production"
|
|
77
|
+
: process.env?.NODE_ENV || "development"
|
|
76
78
|
}`.italic.blue.green + "\n";
|
|
77
79
|
info += `Server: http://localhost:${PORT}\n`.italic.blue;
|
|
78
80
|
info += `\n`;
|
|
79
|
-
info += "TENANTS
|
|
81
|
+
info += "TENANTS :".gray.italic.underline;
|
|
80
82
|
info += `\n`;
|
|
81
83
|
Cfg.tenants?.map((t: any) => {
|
|
82
84
|
info += `\n${t?.name?.blue || "_"} : ${t?.id?.green}`.italic;
|
package/bin/index.ts
CHANGED
|
@@ -33,18 +33,43 @@ process.on("SIGINT", () => {
|
|
|
33
33
|
ch.watch(".", {
|
|
34
34
|
cwd: process.cwd(),
|
|
35
35
|
ignored: [
|
|
36
|
-
/.*\.(jpg|jpeg|png|gif|bmp|svg|webp|dump|zip|rar|.git)$/i,
|
|
36
|
+
/.*\.(jpg|jpeg|png|gif|bmp|svg|webp|dump|zip|rar|.git|.lockb|package.json)$/i,
|
|
37
37
|
/node_modules|node_modules\/.*/,
|
|
38
38
|
/node_modules/,
|
|
39
39
|
/(^|[\/\\])\../,
|
|
40
40
|
"*/node_modules",
|
|
41
41
|
"node_modules",
|
|
42
|
+
"*.docs",
|
|
43
|
+
".docx",
|
|
44
|
+
".pdf",
|
|
45
|
+
".xlsx",
|
|
46
|
+
".pptx",
|
|
47
|
+
".zip",
|
|
48
|
+
"package-lock.json",
|
|
49
|
+
"yarn.lock",
|
|
50
|
+
"tsconfig.json",
|
|
51
|
+
"tsconfig.tsbuildinfo",
|
|
52
|
+
"*.tsbuildinfo",
|
|
53
|
+
"*.log",
|
|
54
|
+
"*.tgz",
|
|
55
|
+
"/.git",
|
|
56
|
+
"/.github",
|
|
57
|
+
"/.vscode",
|
|
58
|
+
"/.idea",
|
|
59
|
+
"/coverage",
|
|
60
|
+
"/dist",
|
|
61
|
+
"/build",
|
|
62
|
+
"/node_modules",
|
|
63
|
+
"/package-lock.json",
|
|
64
|
+
"/yarn.lock",
|
|
65
|
+
".cache",
|
|
42
66
|
"dist",
|
|
43
67
|
"*/dist",
|
|
44
68
|
"*.zip",
|
|
45
69
|
"*.tar",
|
|
46
70
|
"*.tar.gz",
|
|
47
71
|
"build",
|
|
72
|
+
"*.lockb",
|
|
48
73
|
"coverage",
|
|
49
74
|
"packages/*/dist",
|
|
50
75
|
"packages/*/build",
|
package/define/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ import type {
|
|
|
11
11
|
middlewareCtx,
|
|
12
12
|
permissionSchema,
|
|
13
13
|
routeCtx,
|
|
14
|
+
sessionCtx,
|
|
15
|
+
Script,
|
|
14
16
|
} from "../types";
|
|
15
17
|
import { Cfg } from "../config/";
|
|
16
18
|
import { deepMerge, freeze } from "../utils";
|
|
@@ -30,6 +32,11 @@ function Endpoint(config: Endpoint) {
|
|
|
30
32
|
return config;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
function Script(config: Script) {
|
|
36
|
+
config.ok = true;
|
|
37
|
+
return config;
|
|
38
|
+
}
|
|
39
|
+
|
|
33
40
|
function Route(config: routeCtx) {
|
|
34
41
|
config.ok = true;
|
|
35
42
|
return config;
|
|
@@ -100,6 +107,7 @@ const define = {
|
|
|
100
107
|
Api,
|
|
101
108
|
Access,
|
|
102
109
|
Route,
|
|
110
|
+
Script,
|
|
103
111
|
};
|
|
104
112
|
|
|
105
113
|
export default define;
|
package/lib/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { initCron } from "./cron";
|
|
|
6
6
|
import { loadPermissions } from "./permissions";
|
|
7
7
|
import { loadSocket } from "../lib/socket";
|
|
8
8
|
import { loadAutoRoutes } from "./routes";
|
|
9
|
+
import { initScript } from "../lib/scripts";
|
|
9
10
|
// load all ressource
|
|
10
11
|
async function init(cf = { app: null }) {
|
|
11
12
|
await loadSocket();
|
|
@@ -30,6 +31,8 @@ async function init(cf = { app: null }) {
|
|
|
30
31
|
await loadAutoRoutes();
|
|
31
32
|
|
|
32
33
|
await initCron();
|
|
34
|
+
|
|
35
|
+
initScript();
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export { init };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Cron } from "croner";
|
|
2
|
+
import { Glob } from "bun";
|
|
3
|
+
import { Cfg } from "../../config";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import type { cronConfig } from "../../types";
|
|
6
|
+
import cleanDeep from "clean-deep";
|
|
7
|
+
import { useRest } from "../../driver/mongo";
|
|
8
|
+
async function initScript() {
|
|
9
|
+
let cronTasks = [];
|
|
10
|
+
if (Cfg?.tenants?.length) {
|
|
11
|
+
for await (let t of Cfg.tenants) {
|
|
12
|
+
let tenantPath = `${t.dir}/scripts/**/**.{ts,js}`;
|
|
13
|
+
const glob = new Glob(tenantPath);
|
|
14
|
+
for await (let file of glob.scan({
|
|
15
|
+
cwd: Cfg.cwd,
|
|
16
|
+
})) {
|
|
17
|
+
let fullPathFile = path.join(Cfg.cwd || "", file);
|
|
18
|
+
await import(fullPathFile)
|
|
19
|
+
.then((inject) => {
|
|
20
|
+
let scriptInject = inject.default;
|
|
21
|
+
if (scriptInject?.ok && scriptInject?.enabled) {
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
scriptInject.exec({
|
|
24
|
+
io: Cfg.io,
|
|
25
|
+
rest: new useRest({
|
|
26
|
+
tenant_id: t.id,
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}, 1000);
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
.catch((err) => {
|
|
33
|
+
console.error(err);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//Cfg.endpoints = endpoints;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { initScript };
|
package/package.json
CHANGED
package/types/index.ts
CHANGED
|
@@ -478,8 +478,15 @@ export type routeCtx = {
|
|
|
478
478
|
}) => any;
|
|
479
479
|
};
|
|
480
480
|
|
|
481
|
+
type scriptCtx = {
|
|
482
|
+
enabled: boolean;
|
|
483
|
+
exec: (ctx: { rest: InstanceType<typeof useRest>; io: socketIoType }) => any;
|
|
484
|
+
};
|
|
485
|
+
|
|
481
486
|
export type Endpoint = endpointCtx;
|
|
482
487
|
|
|
488
|
+
export type Script = scriptCtx;
|
|
489
|
+
|
|
483
490
|
export type Service = {
|
|
484
491
|
/**
|
|
485
492
|
* @internal
|