miqro 6.1.3 → 6.1.4
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/build/editor.bundle.js +16 -0
- package/build/esm/editor/common/templates.js +16 -0
- package/build/esm/src/bin/types.js +8 -0
- package/build/esm/src/common/arguments.d.ts +7 -1
- package/build/esm/src/common/arguments.js +72 -10
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +33 -29
- package/build/esm/src/inflate/setup-ws.d.ts +1 -1
- package/build/esm/src/inflate/setup-ws.js +2 -2
- package/build/esm/src/main.js +3 -1
- package/build/esm/src/services/app.d.ts +2 -0
- package/build/esm/src/services/app.js +2 -2
- package/build/esm/src/services/utils/log-transport.d.ts +2 -2
- package/build/esm/src/services/utils/log-transport.js +8 -3
- package/build/esm/src/services/utils/server-interface.d.ts +1 -1
- package/build/esm/src/services/utils/server-interface.js +19 -14
- package/build/lib.cjs +23 -21
- package/editor/common/templates.ts +15 -0
- package/package.json +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/src/bin/types.ts +7 -0
- package/src/common/arguments.ts +84 -11
- package/src/common/help.ts +33 -29
- package/src/inflate/setup-db.ts +3 -1
- package/src/inflate/setup-ws.ts +4 -3
- package/src/main.ts +3 -1
- package/src/services/app.ts +4 -2
- package/src/services/utils/log-transport.ts +10 -4
- package/src/services/utils/server-interface.ts +20 -13
package/build/editor.bundle.js
CHANGED
|
@@ -9577,6 +9577,22 @@ export default {
|
|
|
9577
9577
|
]
|
|
9578
9578
|
}
|
|
9579
9579
|
}
|
|
9580
|
+
`
|
|
9581
|
+
},
|
|
9582
|
+
MIQROJSON: {
|
|
9583
|
+
prefix: "",
|
|
9584
|
+
sufix: ".json",
|
|
9585
|
+
filename: "miqro",
|
|
9586
|
+
displayName: "miqro.json file",
|
|
9587
|
+
language: "json",
|
|
9588
|
+
template: () => `{
|
|
9589
|
+
"services": ["src/"],
|
|
9590
|
+
"inflateDir": "build/",
|
|
9591
|
+
"name": "server",
|
|
9592
|
+
"browser": true,
|
|
9593
|
+
"logFile": false,
|
|
9594
|
+
"port": "3000"
|
|
9595
|
+
}
|
|
9580
9596
|
`
|
|
9581
9597
|
},
|
|
9582
9598
|
MINIFIEDJSX: {
|
|
@@ -281,6 +281,22 @@ export default {
|
|
|
281
281
|
]
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
+
`
|
|
285
|
+
},
|
|
286
|
+
MIQROJSON: {
|
|
287
|
+
prefix: "",
|
|
288
|
+
sufix: ".json",
|
|
289
|
+
filename: "miqro",
|
|
290
|
+
displayName: "miqro.json file",
|
|
291
|
+
language: "json",
|
|
292
|
+
template: () => `{
|
|
293
|
+
"services": ["src/"],
|
|
294
|
+
"inflateDir": "build/",
|
|
295
|
+
"name": "server",
|
|
296
|
+
"browser": true,
|
|
297
|
+
"logFile": false,
|
|
298
|
+
"port": "3000"
|
|
299
|
+
}
|
|
284
300
|
`
|
|
285
301
|
},
|
|
286
302
|
MINIFIEDJSX: {
|
|
@@ -16,5 +16,13 @@ export async function installTypings(args, logger) {
|
|
|
16
16
|
logger.error("tsconfig.json already exists!");
|
|
17
17
|
process.exit(EXIT_CODES.ABNORMAL);
|
|
18
18
|
}
|
|
19
|
+
if (args.installMiqroJSON && !existsSync("miqro.json")) {
|
|
20
|
+
logger.info("writing miqro.json");
|
|
21
|
+
writeFileSync("miqro.json", TEMPLATES["MIQROJSON"].template("", ""));
|
|
22
|
+
}
|
|
23
|
+
else if (args.installMiqroJSON) {
|
|
24
|
+
logger.error("miqro.json already exists!");
|
|
25
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
26
|
+
}
|
|
19
27
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
20
28
|
}
|
|
@@ -3,12 +3,18 @@ interface MiqroJSON {
|
|
|
3
3
|
port?: string | number;
|
|
4
4
|
inflateDir?: string;
|
|
5
5
|
name?: string;
|
|
6
|
+
browser?: string | boolean;
|
|
7
|
+
logFile?: string | boolean;
|
|
8
|
+
editor?: boolean;
|
|
6
9
|
}
|
|
7
10
|
export declare function importMiqroJSON(inFile: string): MiqroJSON;
|
|
8
11
|
export declare function getPORT(): string;
|
|
9
12
|
export interface Arguments {
|
|
10
|
-
name
|
|
13
|
+
name?: string;
|
|
14
|
+
browser?: string | boolean;
|
|
15
|
+
logFile?: string | boolean;
|
|
11
16
|
installTypes: boolean;
|
|
17
|
+
installMiqroJSON: boolean;
|
|
12
18
|
installTSConfig: boolean;
|
|
13
19
|
test: boolean;
|
|
14
20
|
port: string;
|
|
@@ -18,7 +18,10 @@ const MiqroJSONSchema = {
|
|
|
18
18
|
name: "string?",
|
|
19
19
|
services: "string[]?",
|
|
20
20
|
port: "number?|string?",
|
|
21
|
-
inflateDir: "string?"
|
|
21
|
+
inflateDir: "string?",
|
|
22
|
+
browser: "boolean?|string?",
|
|
23
|
+
logFile: "boolean?|string?",
|
|
24
|
+
editor: "boolean?"
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
27
|
export function importMiqroJSON(inFile) {
|
|
@@ -42,8 +45,11 @@ export function parseArguments() {
|
|
|
42
45
|
const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
|
|
43
46
|
const flags = {
|
|
44
47
|
name: null,
|
|
48
|
+
browser: null,
|
|
49
|
+
logFile: null,
|
|
45
50
|
hotreload: null,
|
|
46
51
|
miqroJSONPath: null,
|
|
52
|
+
installMiqroJSON: null,
|
|
47
53
|
disableMiqroJSON: null,
|
|
48
54
|
installTypes: null,
|
|
49
55
|
port: null,
|
|
@@ -130,7 +136,7 @@ export function parseArguments() {
|
|
|
130
136
|
console.error(usage);
|
|
131
137
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
132
138
|
}
|
|
133
|
-
const cPort = String(args[i + 1])
|
|
139
|
+
const cPort = String(args[i + 1]);
|
|
134
140
|
if (typeof cPort !== "string") {
|
|
135
141
|
console.error("bad arguments. --port must be a string.");
|
|
136
142
|
console.error(usage);
|
|
@@ -154,6 +160,36 @@ export function parseArguments() {
|
|
|
154
160
|
flags.name = cName;
|
|
155
161
|
i++;
|
|
156
162
|
continue;
|
|
163
|
+
case "--log-file":
|
|
164
|
+
if (flags.logFile !== null) {
|
|
165
|
+
console.error("bad arguments.");
|
|
166
|
+
console.error(usage);
|
|
167
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
168
|
+
}
|
|
169
|
+
const cLofFile = String(args[i + 1]);
|
|
170
|
+
if (typeof cLofFile !== "string") {
|
|
171
|
+
console.error("bad arguments. --port must be a string.");
|
|
172
|
+
console.error(usage);
|
|
173
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
174
|
+
}
|
|
175
|
+
flags.logFile = cLofFile;
|
|
176
|
+
i++;
|
|
177
|
+
continue;
|
|
178
|
+
case "--browser":
|
|
179
|
+
if (flags.browser !== null) {
|
|
180
|
+
console.error("bad arguments.");
|
|
181
|
+
console.error(usage);
|
|
182
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
183
|
+
}
|
|
184
|
+
const cBrowser = String(args[i + 1]);
|
|
185
|
+
if (typeof cBrowser !== "string") {
|
|
186
|
+
console.error("bad arguments. --port must be a string.");
|
|
187
|
+
console.error(usage);
|
|
188
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
189
|
+
}
|
|
190
|
+
flags.browser = cBrowser;
|
|
191
|
+
i++;
|
|
192
|
+
continue;
|
|
157
193
|
case "--generate-doc":
|
|
158
194
|
if (flags.generateDoc !== null) {
|
|
159
195
|
console.error("bad arguments.");
|
|
@@ -228,6 +264,14 @@ export function parseArguments() {
|
|
|
228
264
|
}
|
|
229
265
|
flags.editor = true;
|
|
230
266
|
continue;
|
|
267
|
+
case "--install-miqrojson":
|
|
268
|
+
if (flags.installMiqroJSON !== null) {
|
|
269
|
+
console.error("bad arguments. --install-miqrojson already set.");
|
|
270
|
+
console.error(usage);
|
|
271
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
272
|
+
}
|
|
273
|
+
flags.installMiqroJSON = true;
|
|
274
|
+
continue;
|
|
231
275
|
case "--inflate-sea":
|
|
232
276
|
if (flags.inflateSEA !== null) {
|
|
233
277
|
console.error("bad arguments. --inflate-sea already set.");
|
|
@@ -308,7 +352,6 @@ export function parseArguments() {
|
|
|
308
352
|
}
|
|
309
353
|
}
|
|
310
354
|
flags.inflate = flags.inflate ? flags.inflate : false;
|
|
311
|
-
flags.editor = flags.editor ? flags.editor : false;
|
|
312
355
|
flags.test = flags.test ? flags.test : false;
|
|
313
356
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
314
357
|
const miqroJSONPath = !flags.disableMiqroJSON ? flags.miqroJSONPath ? resolve(flags.miqroJSONPath) : getMiqroJSONPath() : false;
|
|
@@ -322,7 +365,7 @@ export function parseArguments() {
|
|
|
322
365
|
}
|
|
323
366
|
}
|
|
324
367
|
}
|
|
325
|
-
if (
|
|
368
|
+
if (flags.port === null) {
|
|
326
369
|
if (miqroRC.port) {
|
|
327
370
|
flags.port = String(miqroRC.port);
|
|
328
371
|
}
|
|
@@ -332,13 +375,29 @@ export function parseArguments() {
|
|
|
332
375
|
flags.inflateDir = miqroRC.inflateDir;
|
|
333
376
|
}
|
|
334
377
|
}
|
|
335
|
-
if (
|
|
378
|
+
if (flags.name === null) {
|
|
336
379
|
if (miqroRC.name) {
|
|
337
380
|
flags.name = miqroRC.name;
|
|
338
381
|
}
|
|
339
382
|
}
|
|
383
|
+
if (flags.logFile === null) {
|
|
384
|
+
if (miqroRC.logFile !== undefined) {
|
|
385
|
+
flags.logFile = miqroRC.logFile;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (flags.browser === null) {
|
|
389
|
+
if (miqroRC.browser !== undefined) {
|
|
390
|
+
flags.browser = miqroRC.browser;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (flags.editor === null) {
|
|
394
|
+
if (miqroRC.editor !== undefined) {
|
|
395
|
+
flags.editor = miqroRC.editor;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
340
398
|
}
|
|
341
|
-
|
|
399
|
+
flags.editor = flags.editor ? flags.editor : false;
|
|
400
|
+
if (services.length === 0 && (!flags.installTSConfig && !flags.installTypes && !flags.installMiqroJSON)) {
|
|
342
401
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
343
402
|
console.error(`bad arguments. missing --service argument`);
|
|
344
403
|
console.error(usage);
|
|
@@ -368,16 +427,16 @@ export function parseArguments() {
|
|
|
368
427
|
console.error("bad arguments. cannot use --inflate with --editor");
|
|
369
428
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
370
429
|
}
|
|
371
|
-
if (flags.inflate && (flags.installTypes || flags.installTSConfig)) {
|
|
372
|
-
console.error("bad arguments. cannot use --inflate with --install-types");
|
|
430
|
+
if (flags.inflate && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
431
|
+
console.error("bad arguments. cannot use --inflate with --install-types, --install-tsconfig or --install-miqrojson");
|
|
373
432
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
374
433
|
}
|
|
375
434
|
if (flags.inflateSEA && !flags.inflate) {
|
|
376
435
|
console.error("bad arguments. cannot use --inflate-sea without --inflate");
|
|
377
436
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
378
437
|
}
|
|
379
|
-
if (flags.editor && (flags.installTypes || flags.installTSConfig)) {
|
|
380
|
-
console.error("bad arguments. cannot use --editor with --install-
|
|
438
|
+
if (flags.editor && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
439
|
+
console.error("bad arguments. cannot use --editor with--install-types, --install-tsconfig or --install-miqrojson");
|
|
381
440
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
382
441
|
}
|
|
383
442
|
if (flags.test && (flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
|
|
@@ -403,11 +462,14 @@ export function parseArguments() {
|
|
|
403
462
|
const generateDocType = flags.generateDocType ? flags.generateDocType : "MD";
|
|
404
463
|
return {
|
|
405
464
|
name: flags.name ? flags.name : undefined,
|
|
465
|
+
browser: flags.browser !== null ? flags.browser : undefined,
|
|
466
|
+
logFile: flags.logFile !== null ? flags.logFile : undefined,
|
|
406
467
|
generateDocAll: flags.generateDocAll ? true : false,
|
|
407
468
|
hotreload: flags.hotreload ? true : false,
|
|
408
469
|
disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
|
|
409
470
|
miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
|
|
410
471
|
installTypes: flags.installTypes ? true : false,
|
|
472
|
+
installMiqroJSON: flags.installMiqroJSON ? true : false,
|
|
411
473
|
installTSConfig: flags.installTSConfig ? true : false,
|
|
412
474
|
inflate: flags.inflate,
|
|
413
475
|
port: flags.port ? flags.port : getPORT(),
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const BIN_NAME = "miqro";
|
|
2
2
|
export declare const usage = "usage: miqro [...FLAGS] --service app/\n\n==examples==\n\nmiqro --watch --service front/\nPORT=8181 miqro --service api/ --service front/\nmiqro --test --service front/\nmiqro --inflate --service front/\nmiqro --generate-doc --generate-doc-out API.md --service front/\nCLUSTER_COUNT=10 miqro-cluster --service api/";
|
|
3
|
-
export declare const help = "\n==flags==\n\n-v, --version\
|
|
3
|
+
export declare const help = "\n==flags==\n\n-v, --version\n\toutputs the version number\n-h, --help\n\toutputs this page.\n--watch\n\tuse to enable the hot-reload functionality.\n--test\n\trun the tests for a service.\n--migrate-up\n\tmigrations up.\n--migrate-down\n\tmigrations down.\n--inflate\n\tinflates the application.\n--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.\n--editor\n\truns the application with a built-in editor.\n--generate-doc\n\tgenerates a documentation for the api endpoints of the service.\n--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.\n--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.\n--generate-doc-all\n\toutputs all the server routes in the documentation output.\n--compile\n\tinflates the application and tries to create a NODE SEA binary.\n--inflate-sea\n\tinflates the application with sea compilation scripts.\n--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.\n--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.\n--install-miqrojson\n\tcreates a default miqro.json file.\n--disable-miqrojson\n\tdisables the load of miqro.json file.\n--log-file\n\toverrides the default log file from LOG_FILE.\n--browser\n\toverrides the default browser from BROWSER.\n--config\n\toverrides the default miqro.json path.\n--port\n\toverrides the default port from PORT.\n--name\n\toverrides the default name of the server.\n\n==environment variables==\n\nPORT\n\toverride the default 8080 port.\nBROWSER\n\toverride the default browser. change to none to disable.\".\nLOG_FILE\n\toverride the default ./server.log file\nDB\n\tenable the server.db features\nDB_STORAGE\n\toverride the default local db location ./db.sqlite3\nDB_DIALECT\n\toverride the default node:sqlite\nDB_CONNECTION\n\toverride the default connection url\nCLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.\nJSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.\n";
|
|
@@ -13,36 +13,40 @@ CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
|
|
|
13
13
|
export const help = `
|
|
14
14
|
==flags==
|
|
15
15
|
|
|
16
|
-
-v, --version\
|
|
17
|
-
-h, --help\
|
|
18
|
-
--watch\
|
|
19
|
-
--test\
|
|
20
|
-
--migrate-up\
|
|
21
|
-
--migrate-down\
|
|
22
|
-
--inflate\
|
|
23
|
-
--inflate-dir\
|
|
24
|
-
--editor\
|
|
25
|
-
--generate-doc\
|
|
26
|
-
--generate-doc-out\tthe output file for the generated documentation. default value is API.md.
|
|
27
|
-
--generate-doc-type\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
|
|
28
|
-
--generate-doc-all\toutputs all the server routes in the documentation output.
|
|
29
|
-
--compile\
|
|
30
|
-
--inflate-sea\
|
|
31
|
-
--install-tsconfig\tcreates a tsconfig.json configured to use with --install-types.
|
|
32
|
-
--install-types\
|
|
33
|
-
--
|
|
34
|
-
--
|
|
35
|
-
--
|
|
36
|
-
--
|
|
16
|
+
-v, --version\n\toutputs the version number
|
|
17
|
+
-h, --help\n\toutputs this page.
|
|
18
|
+
--watch\n\tuse to enable the hot-reload functionality.
|
|
19
|
+
--test\n\trun the tests for a service.
|
|
20
|
+
--migrate-up\n\tmigrations up.
|
|
21
|
+
--migrate-down\n\tmigrations down.
|
|
22
|
+
--inflate\n\tinflates the application.
|
|
23
|
+
--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.
|
|
24
|
+
--editor\n\truns the application with a built-in editor.
|
|
25
|
+
--generate-doc\n\tgenerates a documentation for the api endpoints of the service.
|
|
26
|
+
--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.
|
|
27
|
+
--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
|
|
28
|
+
--generate-doc-all\n\toutputs all the server routes in the documentation output.
|
|
29
|
+
--compile\n\tinflates the application and tries to create a NODE SEA binary.
|
|
30
|
+
--inflate-sea\n\tinflates the application with sea compilation scripts.
|
|
31
|
+
--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.
|
|
32
|
+
--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.
|
|
33
|
+
--install-miqrojson\n\tcreates a default miqro.json file.
|
|
34
|
+
--disable-miqrojson\n\tdisables the load of miqro.json file.
|
|
35
|
+
--log-file\n\toverrides the default log file from LOG_FILE.
|
|
36
|
+
--browser\n\toverrides the default browser from BROWSER.
|
|
37
|
+
--config\n\toverrides the default miqro.json path.
|
|
38
|
+
--port\n\toverrides the default port from PORT.
|
|
39
|
+
--name\n\toverrides the default name of the server.
|
|
37
40
|
|
|
38
41
|
==environment variables==
|
|
39
42
|
|
|
40
|
-
PORT\
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
PORT\n\toverride the default 8080 port.
|
|
44
|
+
BROWSER\n\toverride the default browser. change to none to disable.".
|
|
45
|
+
LOG_FILE\n\toverride the default ./server.log file
|
|
46
|
+
DB\n\tenable the server.db features
|
|
47
|
+
DB_STORAGE\n\toverride the default local db location ./db.sqlite3
|
|
48
|
+
DB_DIALECT\n\toverride the default node:sqlite
|
|
49
|
+
DB_CONNECTION\n\toverride the default connection url
|
|
50
|
+
CLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
|
|
51
|
+
JSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
|
|
48
52
|
`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Logger } from "@miqro/core";
|
|
2
2
|
import { InflateError } from "../common/jsx.js";
|
|
3
3
|
import { WSConfig } from "../types.js";
|
|
4
|
-
export declare function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<
|
|
4
|
+
export declare function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<void>;
|
|
@@ -30,7 +30,7 @@ export async function inflateWSConfig(logger, servicePath, service, wsConfigList
|
|
|
30
30
|
logger
|
|
31
31
|
}));
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
//return wsConfigList;
|
|
34
34
|
}
|
|
35
35
|
catch (e) {
|
|
36
36
|
errors.push({
|
|
@@ -39,7 +39,7 @@ export async function inflateWSConfig(logger, servicePath, service, wsConfigList
|
|
|
39
39
|
});
|
|
40
40
|
logger.error("error with " + wsPath);
|
|
41
41
|
logger.error(e);
|
|
42
|
-
return false;
|
|
42
|
+
//return false;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
}
|
package/build/esm/src/main.js
CHANGED
|
@@ -9,7 +9,7 @@ import { Miqro } from "./services/app.js";
|
|
|
9
9
|
import { TEST_SOCKET } from "./common/paths.js";
|
|
10
10
|
import { Logger } from "@miqro/core";
|
|
11
11
|
async function main(args) {
|
|
12
|
-
if (args.installTypes || args.installTSConfig) {
|
|
12
|
+
if (args.installTypes || args.installTSConfig || args.installMiqroJSON) {
|
|
13
13
|
await installTypings(args, new Logger(""));
|
|
14
14
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
15
15
|
}
|
|
@@ -19,6 +19,8 @@ async function main(args) {
|
|
|
19
19
|
name: args.name ? args.name : undefined,
|
|
20
20
|
port: args.test ? TEST_SOCKET : args.port,
|
|
21
21
|
services: args.services,
|
|
22
|
+
browser: args.browser,
|
|
23
|
+
logFile: args.logFile,
|
|
22
24
|
hotreload: args.test ? false : args.hotreload
|
|
23
25
|
});
|
|
24
26
|
// check arguments
|
|
@@ -183,9 +183,9 @@ export class Miqro {
|
|
|
183
183
|
async loadDBConfig(options) {
|
|
184
184
|
const errors = [];
|
|
185
185
|
const dbList = [];
|
|
186
|
-
const
|
|
186
|
+
const dbConfigListALL = [];
|
|
187
187
|
for (const service of this.options.services) {
|
|
188
|
-
const dbConfig = await inflateDBConfig(this.logger, service,
|
|
188
|
+
const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, errors);
|
|
189
189
|
if (dbConfig) {
|
|
190
190
|
const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, errors);
|
|
191
191
|
dbList.push({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WriteArgs } from "@miqro/core";
|
|
1
|
+
import { LoggerTransport, WriteArgs } from "@miqro/core";
|
|
2
2
|
import { Miqro } from "../app.js";
|
|
3
3
|
export declare function createLogProviderOptions(app: Miqro): {
|
|
4
4
|
name: string;
|
|
5
|
-
transports:
|
|
5
|
+
transports: LoggerTransport[];
|
|
6
6
|
formatter: (args: WriteArgs) => string;
|
|
7
7
|
};
|
|
@@ -3,7 +3,12 @@ import { format } from "node:util";
|
|
|
3
3
|
import { LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../../editor/common/constants.js";
|
|
4
4
|
export function createLogProviderOptions(app) {
|
|
5
5
|
const defaultConsole = ConsoleTransport();
|
|
6
|
-
|
|
6
|
+
//console.log("app.options.logFile [%s]", app.options.logFile);
|
|
7
|
+
const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" &&
|
|
8
|
+
app.options.logFile ? FileTransport(app.options.logFile) :
|
|
9
|
+
String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === undefined ?
|
|
10
|
+
FileTransport() :
|
|
11
|
+
undefined;
|
|
7
12
|
const defaultWrite = async (args, level) => {
|
|
8
13
|
try {
|
|
9
14
|
const serviceNamesWithLogConfigReplaceConsole = level === undefined && app.inflated ?
|
|
@@ -12,9 +17,9 @@ export function createLogProviderOptions(app) {
|
|
|
12
17
|
Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
13
18
|
await Promise.allSettled((level === undefined ?
|
|
14
19
|
[
|
|
15
|
-
level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 ?
|
|
20
|
+
level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ?
|
|
16
21
|
defaultConsole.write(args) : Promise.resolve(),
|
|
17
|
-
level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 ?
|
|
22
|
+
level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ?
|
|
18
23
|
defaultFile.write(args) : Promise.resolve()
|
|
19
24
|
] : []).concat(app.inflated ?
|
|
20
25
|
Object.keys(app.inflated.logConfigMap).map(serviceName => app.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []));
|
|
@@ -30,11 +30,11 @@ export declare class ServerInterfaceImpl implements ServerInterface {
|
|
|
30
30
|
disconnectAll(path: string): void;
|
|
31
31
|
};
|
|
32
32
|
loggerProvider?: LogProvider;
|
|
33
|
+
openBrowser: (path: string) => void;
|
|
33
34
|
constructor(options: ServerInterfaceImplOptions);
|
|
34
35
|
getWorkerNumber(): number;
|
|
35
36
|
getWorkerCount(): number;
|
|
36
37
|
isPrimaryWorker(): boolean;
|
|
37
|
-
openBrowser(path: string): void;
|
|
38
38
|
getLogger(identifier: string, options?: {
|
|
39
39
|
level?: any;
|
|
40
40
|
transports?: any[];
|
|
@@ -8,6 +8,7 @@ export class ServerInterfaceImpl {
|
|
|
8
8
|
db;
|
|
9
9
|
ws;
|
|
10
10
|
loggerProvider;
|
|
11
|
+
openBrowser;
|
|
11
12
|
constructor(options) {
|
|
12
13
|
this.cache = options.cache;
|
|
13
14
|
this.localCache = options.localCache;
|
|
@@ -17,6 +18,24 @@ export class ServerInterfaceImpl {
|
|
|
17
18
|
const wsManager = options.wsManager;
|
|
18
19
|
this.loggerProvider = options.loggerProvider;
|
|
19
20
|
const app = options.app;
|
|
21
|
+
this.openBrowser = (path) => {
|
|
22
|
+
const PORT = this.port;
|
|
23
|
+
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
24
|
+
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
25
|
+
const OPEN = app.options.browser !== undefined && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ?
|
|
26
|
+
String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ?
|
|
27
|
+
app.options.browser : false :
|
|
28
|
+
process.env["BROWSER"] ?
|
|
29
|
+
process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
30
|
+
if (OPEN) {
|
|
31
|
+
const openCMD = `${OPEN} "${URL}"`;
|
|
32
|
+
this.logger?.info("opening browser with [%s]", openCMD);
|
|
33
|
+
execSync(openCMD);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.logger?.warn("ignoring browser [%s]", OPEN);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
20
39
|
this.db = Object.freeze({
|
|
21
40
|
get: (name) => {
|
|
22
41
|
return dbManager.getDB(name);
|
|
@@ -59,20 +78,6 @@ export class ServerInterfaceImpl {
|
|
|
59
78
|
isPrimaryWorker() {
|
|
60
79
|
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
61
80
|
}
|
|
62
|
-
openBrowser(path) {
|
|
63
|
-
const PORT = this.port;
|
|
64
|
-
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
65
|
-
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
66
|
-
const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
67
|
-
if (OPEN) {
|
|
68
|
-
const openCMD = `${OPEN} "${URL}"`;
|
|
69
|
-
this.logger?.info("opening browser with [%s]", openCMD);
|
|
70
|
-
execSync(openCMD);
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.logger?.warn("ignoring browser [%s]", process.env["BROWSER"]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
81
|
getLogger(identifier, options) {
|
|
77
82
|
return this.loggerProvider?.getLogger(identifier, options);
|
|
78
83
|
}
|
package/build/lib.cjs
CHANGED
|
@@ -12892,7 +12892,6 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
|
|
|
12892
12892
|
logger
|
|
12893
12893
|
}));
|
|
12894
12894
|
}
|
|
12895
|
-
return wsConfig;
|
|
12896
12895
|
} catch (e) {
|
|
12897
12896
|
errors.push({
|
|
12898
12897
|
filePath: wsPath,
|
|
@@ -12900,7 +12899,6 @@ async function inflateWSConfig(logger, servicePath, service, wsConfigList, infla
|
|
|
12900
12899
|
});
|
|
12901
12900
|
logger.error("error with " + wsPath);
|
|
12902
12901
|
logger.error(e);
|
|
12903
|
-
return false;
|
|
12904
12902
|
}
|
|
12905
12903
|
}
|
|
12906
12904
|
}
|
|
@@ -13929,6 +13927,7 @@ var ServerInterfaceImpl = class {
|
|
|
13929
13927
|
db;
|
|
13930
13928
|
ws;
|
|
13931
13929
|
loggerProvider;
|
|
13930
|
+
openBrowser;
|
|
13932
13931
|
constructor(options) {
|
|
13933
13932
|
this.cache = options.cache;
|
|
13934
13933
|
this.localCache = options.localCache;
|
|
@@ -13938,6 +13937,19 @@ var ServerInterfaceImpl = class {
|
|
|
13938
13937
|
const wsManager = options.wsManager;
|
|
13939
13938
|
this.loggerProvider = options.loggerProvider;
|
|
13940
13939
|
const app = options.app;
|
|
13940
|
+
this.openBrowser = (path) => {
|
|
13941
|
+
const PORT2 = this.port;
|
|
13942
|
+
const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
|
|
13943
|
+
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
13944
|
+
const OPEN = app.options.browser !== void 0 && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ? String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ? app.options.browser : false : process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
13945
|
+
if (OPEN) {
|
|
13946
|
+
const openCMD = `${OPEN} "${URL2}"`;
|
|
13947
|
+
this.logger?.info("opening browser with [%s]", openCMD);
|
|
13948
|
+
(0, import_node_child_process2.execSync)(openCMD);
|
|
13949
|
+
} else {
|
|
13950
|
+
this.logger?.warn("ignoring browser [%s]", OPEN);
|
|
13951
|
+
}
|
|
13952
|
+
};
|
|
13941
13953
|
this.db = Object.freeze({
|
|
13942
13954
|
get: (name) => {
|
|
13943
13955
|
return dbManager.getDB(name);
|
|
@@ -13980,19 +13992,6 @@ var ServerInterfaceImpl = class {
|
|
|
13980
13992
|
isPrimaryWorker() {
|
|
13981
13993
|
return import_node_cluster2.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
13982
13994
|
}
|
|
13983
|
-
openBrowser(path) {
|
|
13984
|
-
const PORT2 = this.port;
|
|
13985
|
-
const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
|
|
13986
|
-
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
13987
|
-
const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
13988
|
-
if (OPEN) {
|
|
13989
|
-
const openCMD = `${OPEN} "${URL2}"`;
|
|
13990
|
-
this.logger?.info("opening browser with [%s]", openCMD);
|
|
13991
|
-
(0, import_node_child_process2.execSync)(openCMD);
|
|
13992
|
-
} else {
|
|
13993
|
-
this.logger?.warn("ignoring browser [%s]", process.env["BROWSER"]);
|
|
13994
|
-
}
|
|
13995
|
-
}
|
|
13996
13995
|
getLogger(identifier, options) {
|
|
13997
13996
|
return this.loggerProvider?.getLogger(identifier, options);
|
|
13998
13997
|
}
|
|
@@ -14024,7 +14023,10 @@ var MiqroJSONSchema = {
|
|
|
14024
14023
|
name: "string?",
|
|
14025
14024
|
services: "string[]?",
|
|
14026
14025
|
port: "number?|string?",
|
|
14027
|
-
inflateDir: "string?"
|
|
14026
|
+
inflateDir: "string?",
|
|
14027
|
+
browser: "boolean?|string?",
|
|
14028
|
+
logFile: "boolean?|string?",
|
|
14029
|
+
editor: "boolean?"
|
|
14028
14030
|
}
|
|
14029
14031
|
};
|
|
14030
14032
|
function importMiqroJSON(inFile) {
|
|
@@ -14045,14 +14047,14 @@ var import_node_util3 = require("node:util");
|
|
|
14045
14047
|
init_constants();
|
|
14046
14048
|
function createLogProviderOptions(app) {
|
|
14047
14049
|
const defaultConsole = ConsoleTransport();
|
|
14048
|
-
const defaultFile = FileTransport();
|
|
14050
|
+
const defaultFile = app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" && app.options.logFile ? FileTransport(app.options.logFile) : String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === void 0 ? FileTransport() : void 0;
|
|
14049
14051
|
const defaultWrite = async (args, level) => {
|
|
14050
14052
|
try {
|
|
14051
14053
|
const serviceNamesWithLogConfigReplaceConsole = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceConsoleTransport) : [];
|
|
14052
14054
|
const serviceNamesWithLogConfigReplaceFile = level === void 0 && app.inflated ? Object.keys(app.inflated.logConfigMap).filter((serviceName) => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
14053
14055
|
await Promise.allSettled((level === void 0 ? [
|
|
14054
|
-
level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 ? defaultConsole.write(args) : Promise.resolve(),
|
|
14055
|
-
level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 ? defaultFile.write(args) : Promise.resolve()
|
|
14056
|
+
level === void 0 && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ? defaultConsole.write(args) : Promise.resolve(),
|
|
14057
|
+
level === void 0 && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ? defaultFile.write(args) : Promise.resolve()
|
|
14056
14058
|
] : []).concat(
|
|
14057
14059
|
app.inflated ? Object.keys(app.inflated.logConfigMap).map((serviceName) => app.inflated.logConfigMap[serviceName]).filter((c) => c.level === level).map((c) => c.write(args)) : []
|
|
14058
14060
|
));
|
|
@@ -14290,9 +14292,9 @@ var Miqro = class _Miqro {
|
|
|
14290
14292
|
async loadDBConfig(options) {
|
|
14291
14293
|
const errors = [];
|
|
14292
14294
|
const dbList = [];
|
|
14293
|
-
const
|
|
14295
|
+
const dbConfigListALL = [];
|
|
14294
14296
|
for (const service of this.options.services) {
|
|
14295
|
-
const dbConfig = await inflateDBConfig(this.logger, service,
|
|
14297
|
+
const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : void 0, errors);
|
|
14296
14298
|
if (dbConfig) {
|
|
14297
14299
|
const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : void 0, errors);
|
|
14298
14300
|
dbList.push({
|
|
@@ -290,6 +290,21 @@ export default {
|
|
|
290
290
|
]
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
|
+
`},
|
|
294
|
+
MIQROJSON: {
|
|
295
|
+
prefix: "",
|
|
296
|
+
sufix: ".json",
|
|
297
|
+
filename: "miqro",
|
|
298
|
+
displayName: "miqro.json file",
|
|
299
|
+
language: "json",
|
|
300
|
+
template: () => `{
|
|
301
|
+
"services": ["src/"],
|
|
302
|
+
"inflateDir": "build/",
|
|
303
|
+
"name": "server",
|
|
304
|
+
"browser": true,
|
|
305
|
+
"logFile": false,
|
|
306
|
+
"port": "3000"
|
|
307
|
+
}
|
|
293
308
|
`},
|
|
294
309
|
MINIFIEDJSX: {
|
|
295
310
|
prefix: "http",
|
package/package.json
CHANGED
package/sea/install-nodejs.sh
CHANGED
package/sea/node.version.tag
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
24.0.
|
|
1
|
+
24.0.2
|
package/src/bin/types.ts
CHANGED
|
@@ -18,5 +18,12 @@ export async function installTypings(args: Arguments, logger: MinimalLogger) {
|
|
|
18
18
|
logger.error("tsconfig.json already exists!");
|
|
19
19
|
process.exit(EXIT_CODES.ABNORMAL);
|
|
20
20
|
}
|
|
21
|
+
if (args.installMiqroJSON && !existsSync("miqro.json")) {
|
|
22
|
+
logger.info("writing miqro.json");
|
|
23
|
+
writeFileSync("miqro.json", TEMPLATES["MIQROJSON"].template("", ""));
|
|
24
|
+
} else if (args.installMiqroJSON) {
|
|
25
|
+
logger.error("miqro.json already exists!");
|
|
26
|
+
process.exit(EXIT_CODES.ABNORMAL);
|
|
27
|
+
}
|
|
21
28
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
22
29
|
}
|
package/src/common/arguments.ts
CHANGED
|
@@ -20,6 +20,9 @@ interface MiqroJSON {
|
|
|
20
20
|
port?: string | number;
|
|
21
21
|
inflateDir?: string;
|
|
22
22
|
name?: string;
|
|
23
|
+
browser?: string | boolean;
|
|
24
|
+
logFile?: string | boolean;
|
|
25
|
+
editor?: boolean;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const MiqroJSONSchema: Schema<MiqroJSON> = {
|
|
@@ -28,7 +31,10 @@ const MiqroJSONSchema: Schema<MiqroJSON> = {
|
|
|
28
31
|
name: "string?",
|
|
29
32
|
services: "string[]?",
|
|
30
33
|
port: "number?|string?",
|
|
31
|
-
inflateDir: "string?"
|
|
34
|
+
inflateDir: "string?",
|
|
35
|
+
browser: "boolean?|string?",
|
|
36
|
+
logFile: "boolean?|string?",
|
|
37
|
+
editor: "boolean?"
|
|
32
38
|
}
|
|
33
39
|
}
|
|
34
40
|
|
|
@@ -47,8 +53,11 @@ export function getPORT() {
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
export interface Arguments {
|
|
50
|
-
name
|
|
56
|
+
name?: string;
|
|
57
|
+
browser?: string | boolean;
|
|
58
|
+
logFile?: string | boolean;
|
|
51
59
|
installTypes: boolean;
|
|
60
|
+
installMiqroJSON: boolean;
|
|
52
61
|
installTSConfig: boolean;
|
|
53
62
|
test: boolean;
|
|
54
63
|
port: string;
|
|
@@ -78,8 +87,11 @@ export function parseArguments(): Arguments {
|
|
|
78
87
|
|
|
79
88
|
const args = cluster.isPrimary ? process.argv.slice(2, process.argv.length) : process.argv.slice(3, process.argv.length);
|
|
80
89
|
const flags: {
|
|
90
|
+
logFile: string | boolean | null;
|
|
91
|
+
browser: string | boolean | null;
|
|
81
92
|
name: string | null;
|
|
82
93
|
installTypes: boolean | null;
|
|
94
|
+
installMiqroJSON: boolean | null;
|
|
83
95
|
installTSConfig: boolean | null;
|
|
84
96
|
inflate: boolean | null;
|
|
85
97
|
port: string | null;
|
|
@@ -99,8 +111,11 @@ export function parseArguments(): Arguments {
|
|
|
99
111
|
hotreload?: boolean | null;
|
|
100
112
|
} = {
|
|
101
113
|
name: null,
|
|
114
|
+
browser: null,
|
|
115
|
+
logFile: null,
|
|
102
116
|
hotreload: null,
|
|
103
117
|
miqroJSONPath: null,
|
|
118
|
+
installMiqroJSON: null,
|
|
104
119
|
disableMiqroJSON: null,
|
|
105
120
|
installTypes: null,
|
|
106
121
|
port: null,
|
|
@@ -187,7 +202,7 @@ export function parseArguments(): Arguments {
|
|
|
187
202
|
console.error(usage);
|
|
188
203
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
189
204
|
}
|
|
190
|
-
const cPort = String(args[i + 1])
|
|
205
|
+
const cPort = String(args[i + 1]) as any;
|
|
191
206
|
if (typeof cPort !== "string") {
|
|
192
207
|
console.error("bad arguments. --port must be a string.");
|
|
193
208
|
console.error(usage);
|
|
@@ -211,6 +226,36 @@ export function parseArguments(): Arguments {
|
|
|
211
226
|
flags.name = cName;
|
|
212
227
|
i++;
|
|
213
228
|
continue;
|
|
229
|
+
case "--log-file":
|
|
230
|
+
if (flags.logFile !== null) {
|
|
231
|
+
console.error("bad arguments.");
|
|
232
|
+
console.error(usage);
|
|
233
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
234
|
+
}
|
|
235
|
+
const cLofFile = String(args[i + 1]) as any;
|
|
236
|
+
if (typeof cLofFile !== "string") {
|
|
237
|
+
console.error("bad arguments. --port must be a string.");
|
|
238
|
+
console.error(usage);
|
|
239
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
240
|
+
}
|
|
241
|
+
flags.logFile = cLofFile;
|
|
242
|
+
i++;
|
|
243
|
+
continue;
|
|
244
|
+
case "--browser":
|
|
245
|
+
if (flags.browser !== null) {
|
|
246
|
+
console.error("bad arguments.");
|
|
247
|
+
console.error(usage);
|
|
248
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
249
|
+
}
|
|
250
|
+
const cBrowser = String(args[i + 1]) as any;
|
|
251
|
+
if (typeof cBrowser !== "string") {
|
|
252
|
+
console.error("bad arguments. --port must be a string.");
|
|
253
|
+
console.error(usage);
|
|
254
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
255
|
+
}
|
|
256
|
+
flags.browser = cBrowser;
|
|
257
|
+
i++;
|
|
258
|
+
continue;
|
|
214
259
|
case "--generate-doc":
|
|
215
260
|
if (flags.generateDoc !== null) {
|
|
216
261
|
console.error("bad arguments.");
|
|
@@ -285,6 +330,14 @@ export function parseArguments(): Arguments {
|
|
|
285
330
|
}
|
|
286
331
|
flags.editor = true;
|
|
287
332
|
continue;
|
|
333
|
+
case "--install-miqrojson":
|
|
334
|
+
if (flags.installMiqroJSON !== null) {
|
|
335
|
+
console.error("bad arguments. --install-miqrojson already set.");
|
|
336
|
+
console.error(usage);
|
|
337
|
+
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
338
|
+
}
|
|
339
|
+
flags.installMiqroJSON = true;
|
|
340
|
+
continue;
|
|
288
341
|
case "--inflate-sea":
|
|
289
342
|
if (flags.inflateSEA !== null) {
|
|
290
343
|
console.error("bad arguments. --inflate-sea already set.");
|
|
@@ -366,7 +419,7 @@ export function parseArguments(): Arguments {
|
|
|
366
419
|
}
|
|
367
420
|
|
|
368
421
|
flags.inflate = flags.inflate ? flags.inflate : false;
|
|
369
|
-
|
|
422
|
+
|
|
370
423
|
flags.test = flags.test ? flags.test : false;
|
|
371
424
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
372
425
|
|
|
@@ -382,7 +435,7 @@ export function parseArguments(): Arguments {
|
|
|
382
435
|
}
|
|
383
436
|
}
|
|
384
437
|
}
|
|
385
|
-
if (
|
|
438
|
+
if (flags.port === null) {
|
|
386
439
|
if (miqroRC.port) {
|
|
387
440
|
flags.port = String(miqroRC.port);
|
|
388
441
|
}
|
|
@@ -392,14 +445,31 @@ export function parseArguments(): Arguments {
|
|
|
392
445
|
flags.inflateDir = miqroRC.inflateDir;
|
|
393
446
|
}
|
|
394
447
|
}
|
|
395
|
-
if (
|
|
448
|
+
if (flags.name === null) {
|
|
396
449
|
if (miqroRC.name) {
|
|
397
450
|
flags.name = miqroRC.name;
|
|
398
451
|
}
|
|
399
452
|
}
|
|
453
|
+
if (flags.logFile === null) {
|
|
454
|
+
if (miqroRC.logFile !== undefined) {
|
|
455
|
+
flags.logFile = miqroRC.logFile;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (flags.browser === null) {
|
|
459
|
+
if (miqroRC.browser !== undefined) {
|
|
460
|
+
flags.browser = miqroRC.browser;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (flags.editor === null) {
|
|
464
|
+
if (miqroRC.editor !== undefined) {
|
|
465
|
+
flags.editor = miqroRC.editor;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
400
468
|
}
|
|
401
469
|
|
|
402
|
-
|
|
470
|
+
flags.editor = flags.editor ? flags.editor : false;
|
|
471
|
+
|
|
472
|
+
if (services.length === 0 && (!flags.installTSConfig && !flags.installTypes && !flags.installMiqroJSON)) {
|
|
403
473
|
flags.inflateDir = flags.inflateDir ? flags.inflateDir : undefined;
|
|
404
474
|
console.error(`bad arguments. missing --service argument`);
|
|
405
475
|
console.error(usage);
|
|
@@ -436,8 +506,8 @@ export function parseArguments(): Arguments {
|
|
|
436
506
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
437
507
|
}
|
|
438
508
|
|
|
439
|
-
if (flags.inflate && (flags.installTypes || flags.installTSConfig)) {
|
|
440
|
-
console.error("bad arguments. cannot use --inflate with --install-types");
|
|
509
|
+
if (flags.inflate && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
510
|
+
console.error("bad arguments. cannot use --inflate with --install-types, --install-tsconfig or --install-miqrojson");
|
|
441
511
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
442
512
|
}
|
|
443
513
|
|
|
@@ -446,8 +516,8 @@ export function parseArguments(): Arguments {
|
|
|
446
516
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
447
517
|
}
|
|
448
518
|
|
|
449
|
-
if (flags.editor && (flags.installTypes || flags.installTSConfig)) {
|
|
450
|
-
console.error("bad arguments. cannot use --editor with --install-
|
|
519
|
+
if (flags.editor && (flags.installTypes || flags.installTSConfig || flags.installMiqroJSON)) {
|
|
520
|
+
console.error("bad arguments. cannot use --editor with--install-types, --install-tsconfig or --install-miqrojson");
|
|
451
521
|
process.exit(EXIT_CODES.BAD_ARGUMENTS);
|
|
452
522
|
}
|
|
453
523
|
|
|
@@ -480,11 +550,14 @@ export function parseArguments(): Arguments {
|
|
|
480
550
|
|
|
481
551
|
return {
|
|
482
552
|
name: flags.name ? flags.name : undefined,
|
|
553
|
+
browser: flags.browser !== null ? flags.browser : undefined,
|
|
554
|
+
logFile: flags.logFile !== null ? flags.logFile : undefined,
|
|
483
555
|
generateDocAll: flags.generateDocAll ? true : false,
|
|
484
556
|
hotreload: flags.hotreload ? true : false,
|
|
485
557
|
disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
|
|
486
558
|
miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
|
|
487
559
|
installTypes: flags.installTypes ? true : false,
|
|
560
|
+
installMiqroJSON: flags.installMiqroJSON ? true : false,
|
|
488
561
|
installTSConfig: flags.installTSConfig ? true : false,
|
|
489
562
|
inflate: flags.inflate,
|
|
490
563
|
port: flags.port ? flags.port : getPORT(),
|
package/src/common/help.ts
CHANGED
|
@@ -16,36 +16,40 @@ CLUSTER_COUNT=10 ${BIN_NAME}-cluster --service api/`;
|
|
|
16
16
|
export const help = `
|
|
17
17
|
==flags==
|
|
18
18
|
|
|
19
|
-
-v, --version\
|
|
20
|
-
-h, --help\
|
|
21
|
-
--watch\
|
|
22
|
-
--test\
|
|
23
|
-
--migrate-up\
|
|
24
|
-
--migrate-down\
|
|
25
|
-
--inflate\
|
|
26
|
-
--inflate-dir\
|
|
27
|
-
--editor\
|
|
28
|
-
--generate-doc\
|
|
29
|
-
--generate-doc-out\tthe output file for the generated documentation. default value is API.md.
|
|
30
|
-
--generate-doc-type\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
|
|
31
|
-
--generate-doc-all\toutputs all the server routes in the documentation output.
|
|
32
|
-
--compile\
|
|
33
|
-
--inflate-sea\
|
|
34
|
-
--install-tsconfig\tcreates a tsconfig.json configured to use with --install-types.
|
|
35
|
-
--install-types\
|
|
36
|
-
--
|
|
37
|
-
--
|
|
38
|
-
--
|
|
39
|
-
--
|
|
19
|
+
-v, --version\n\toutputs the version number
|
|
20
|
+
-h, --help\n\toutputs this page.
|
|
21
|
+
--watch\n\tuse to enable the hot-reload functionality.
|
|
22
|
+
--test\n\trun the tests for a service.
|
|
23
|
+
--migrate-up\n\tmigrations up.
|
|
24
|
+
--migrate-down\n\tmigrations down.
|
|
25
|
+
--inflate\n\tinflates the application.
|
|
26
|
+
--inflate-dir\n\tto set the output directory of the --inflate command. default value is inflated/.
|
|
27
|
+
--editor\n\truns the application with a built-in editor.
|
|
28
|
+
--generate-doc\n\tgenerates a documentation for the api endpoints of the service.
|
|
29
|
+
--generate-doc-out\n\tthe output file for the generated documentation. default value is API.md.
|
|
30
|
+
--generate-doc-type\n\tthe format of the generated documentation. it can be JSON or MD. default value is MD.
|
|
31
|
+
--generate-doc-all\n\toutputs all the server routes in the documentation output.
|
|
32
|
+
--compile\n\tinflates the application and tries to create a NODE SEA binary.
|
|
33
|
+
--inflate-sea\n\tinflates the application with sea compilation scripts.
|
|
34
|
+
--install-tsconfig\n\tcreates a tsconfig.json configured to use with --install-types.
|
|
35
|
+
--install-types\n\tcreates and updates the .types/ folder use together with --install-tsconfig.
|
|
36
|
+
--install-miqrojson\n\tcreates a default miqro.json file.
|
|
37
|
+
--disable-miqrojson\n\tdisables the load of miqro.json file.
|
|
38
|
+
--log-file\n\toverrides the default log file from LOG_FILE.
|
|
39
|
+
--browser\n\toverrides the default browser from BROWSER.
|
|
40
|
+
--config\n\toverrides the default miqro.json path.
|
|
41
|
+
--port\n\toverrides the default port from PORT.
|
|
42
|
+
--name\n\toverrides the default name of the server.
|
|
40
43
|
|
|
41
44
|
==environment variables==
|
|
42
45
|
|
|
43
|
-
PORT\
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
PORT\n\toverride the default 8080 port.
|
|
47
|
+
BROWSER\n\toverride the default browser. change to none to disable.".
|
|
48
|
+
LOG_FILE\n\toverride the default ./server.log file
|
|
49
|
+
DB\n\tenable the server.db features
|
|
50
|
+
DB_STORAGE\n\toverride the default local db location ./db.sqlite3
|
|
51
|
+
DB_DIALECT\n\toverride the default node:sqlite
|
|
52
|
+
DB_CONNECTION\n\toverride the default connection url
|
|
53
|
+
CLEAR_JSX_CACHE\n\tset to 1 or 0 to enable or disable the clearing of the esbuild cache defaults to 1.
|
|
54
|
+
JSX_TMP\n\tset custom location of esbuild builds defaults to /tmp/jsx_tmp.
|
|
51
55
|
`;
|
package/src/inflate/setup-db.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { cwd } from "node:process";
|
|
|
8
8
|
import { DBConfig, NamedMigration } from "../types.js";
|
|
9
9
|
|
|
10
10
|
export interface MigrationModule extends Migration, NamedMigration {
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export async function inflateDBConfig(logger: Logger, service: string, dbConfigList: DBConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]) {
|
|
@@ -26,6 +26,8 @@ export async function inflateDBConfig(logger: Logger, service: string, dbConfigL
|
|
|
26
26
|
dbConfigList.push(config);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
|
|
30
|
+
|
|
29
31
|
if (config) {
|
|
30
32
|
if (inflateDir) {
|
|
31
33
|
const inflatePath = resolve(inflateDir, service, "db.js");
|
package/src/inflate/setup-ws.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { importWSConfigModule, InflateError, inflateJSX } from "../common/jsx.js
|
|
|
7
7
|
import { getWSConfigPath } from "../common/paths.js";
|
|
8
8
|
import { WSConfig } from "../types.js";
|
|
9
9
|
|
|
10
|
-
export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<
|
|
10
|
+
export async function inflateWSConfig(logger: Logger, servicePath: string, service: string, wsConfigList: WSConfig[] | undefined, inflateDir: string | undefined | false, errors: InflateError[]): Promise<void> {
|
|
11
11
|
const wsPath = getWSConfigPath(servicePath); // resolve(process.cwd(), service, "ws.ts");
|
|
12
12
|
|
|
13
13
|
if (wsPath) {
|
|
@@ -21,6 +21,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
|
|
|
21
21
|
wsConfigList.push(wsConfig);
|
|
22
22
|
//wsMap[wsConfig.path] = { name: service, options: wsConfig };
|
|
23
23
|
}
|
|
24
|
+
|
|
24
25
|
if (inflateDir) {
|
|
25
26
|
const inflatePath = resolve(inflateDir, service, "ws.js");
|
|
26
27
|
mkdirSync(dirname(inflatePath), {
|
|
@@ -34,7 +35,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
|
|
|
34
35
|
logger
|
|
35
36
|
}));
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
//return wsConfigList;
|
|
38
39
|
} catch (e) {
|
|
39
40
|
errors.push({
|
|
40
41
|
filePath: wsPath,
|
|
@@ -42,7 +43,7 @@ export async function inflateWSConfig(logger: Logger, servicePath: string, servi
|
|
|
42
43
|
});
|
|
43
44
|
logger.error("error with " + wsPath);
|
|
44
45
|
logger.error(e);
|
|
45
|
-
return false;
|
|
46
|
+
//return false;
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
package/src/main.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { TEST_SOCKET } from "./common/paths.js";
|
|
|
11
11
|
import { Logger } from "@miqro/core";
|
|
12
12
|
|
|
13
13
|
async function main(args: Arguments) {
|
|
14
|
-
if (args.installTypes || args.installTSConfig) {
|
|
14
|
+
if (args.installTypes || args.installTSConfig || args.installMiqroJSON) {
|
|
15
15
|
await installTypings(args, new Logger(""));
|
|
16
16
|
process.exit(EXIT_CODES.NORMAL_EXIT);
|
|
17
17
|
} else {
|
|
@@ -20,6 +20,8 @@ async function main(args: Arguments) {
|
|
|
20
20
|
name: args.name ? args.name : undefined,
|
|
21
21
|
port: args.test ? TEST_SOCKET : args.port,
|
|
22
22
|
services: args.services,
|
|
23
|
+
browser: args.browser,
|
|
24
|
+
logFile: args.logFile,
|
|
23
25
|
hotreload: args.test ? false : args.hotreload
|
|
24
26
|
});
|
|
25
27
|
// check arguments
|
package/src/services/app.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface MiqroOptions {
|
|
|
39
39
|
services: string[];
|
|
40
40
|
editor: boolean;
|
|
41
41
|
port: string;
|
|
42
|
+
browser?: string | boolean;
|
|
43
|
+
logFile?: string | boolean;
|
|
42
44
|
hotreload?: boolean;
|
|
43
45
|
}
|
|
44
46
|
|
|
@@ -249,9 +251,9 @@ export class Miqro {
|
|
|
249
251
|
dbConfig: DBConfig;
|
|
250
252
|
migrations: MigrationModule[];
|
|
251
253
|
}[] = [];
|
|
252
|
-
const
|
|
254
|
+
const dbConfigListALL: DBConfig[] = [];
|
|
253
255
|
for (const service of this.options.services) {
|
|
254
|
-
const dbConfig = await inflateDBConfig(this.logger, service,
|
|
256
|
+
const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, errors);
|
|
255
257
|
if (dbConfig) {
|
|
256
258
|
const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, errors);
|
|
257
259
|
dbList.push({
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { ConsoleTransport, FileTransport, LoggerTransportWriteArgs, LogLevel, WriteArgs } from "@miqro/core";
|
|
1
|
+
import { ConsoleTransport, FileTransport, LoggerTransport, LoggerTransportWriteArgs, LogLevel, WriteArgs } from "@miqro/core";
|
|
2
2
|
import { format } from "node:util";
|
|
3
3
|
import { LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../../editor/common/constants.js";
|
|
4
4
|
import { Miqro } from "../app.js";
|
|
5
5
|
|
|
6
6
|
export function createLogProviderOptions(app: Miqro) {
|
|
7
7
|
const defaultConsole = ConsoleTransport();
|
|
8
|
-
|
|
8
|
+
//console.log("app.options.logFile [%s]", app.options.logFile);
|
|
9
|
+
const defaultFile: LoggerTransport | undefined =
|
|
10
|
+
app.options.logFile !== true && app.options.logFile !== false && String(app.options.logFile).toUpperCase() !== "TRUE" && String(app.options.logFile).toUpperCase() !== "FALSE" &&
|
|
11
|
+
app.options.logFile ? FileTransport(app.options.logFile) :
|
|
12
|
+
String(app.options.logFile).toUpperCase() === "TRUE" || app.options.logFile === true || app.options.logFile === undefined ?
|
|
13
|
+
FileTransport() :
|
|
14
|
+
undefined;
|
|
9
15
|
const defaultWrite = async (args: LoggerTransportWriteArgs, level?: LogLevel) => {
|
|
10
16
|
try {
|
|
11
17
|
const serviceNamesWithLogConfigReplaceConsole = level === undefined && app.inflated ?
|
|
@@ -14,9 +20,9 @@ export function createLogProviderOptions(app: Miqro) {
|
|
|
14
20
|
Object.keys(app.inflated.logConfigMap).filter(serviceName => app.inflated.logConfigMap[serviceName].replaceFileTransport) : [];
|
|
15
21
|
await Promise.allSettled((level === undefined ?
|
|
16
22
|
[
|
|
17
|
-
level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 ?
|
|
23
|
+
level === undefined && serviceNamesWithLogConfigReplaceConsole.length === 0 && defaultConsole ?
|
|
18
24
|
defaultConsole.write(args) : Promise.resolve(),
|
|
19
|
-
level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 ?
|
|
25
|
+
level === undefined && serviceNamesWithLogConfigReplaceFile.length === 0 && defaultFile ?
|
|
20
26
|
defaultFile.write(args) : Promise.resolve()
|
|
21
27
|
] : []).concat(app.inflated ?
|
|
22
28
|
Object.keys(app.inflated.logConfigMap).map(serviceName => app.inflated.logConfigMap[serviceName]).filter(c => c.level === level).map(c => c.write(args)) : []
|
|
@@ -99,6 +99,7 @@ export class ServerInterfaceImpl implements ServerInterface {
|
|
|
99
99
|
disconnectAll(path: string): void;
|
|
100
100
|
};
|
|
101
101
|
public loggerProvider?: LogProvider;
|
|
102
|
+
openBrowser: (path: string) => void;
|
|
102
103
|
|
|
103
104
|
constructor(options: ServerInterfaceImplOptions) {
|
|
104
105
|
this.cache = options.cache;
|
|
@@ -111,6 +112,24 @@ export class ServerInterfaceImpl implements ServerInterface {
|
|
|
111
112
|
this.loggerProvider = options.loggerProvider;
|
|
112
113
|
const app = options.app;
|
|
113
114
|
|
|
115
|
+
this.openBrowser = (path: string) => {
|
|
116
|
+
const PORT = this.port;
|
|
117
|
+
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
118
|
+
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
119
|
+
const OPEN = app.options.browser !== undefined && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ?
|
|
120
|
+
String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ?
|
|
121
|
+
app.options.browser : false :
|
|
122
|
+
process.env["BROWSER"] ?
|
|
123
|
+
process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
124
|
+
if (OPEN) {
|
|
125
|
+
const openCMD = `${OPEN} "${URL}"`;
|
|
126
|
+
this.logger?.info("opening browser with [%s]", openCMD);
|
|
127
|
+
execSync(openCMD);
|
|
128
|
+
} else {
|
|
129
|
+
this.logger?.warn("ignoring browser [%s]", OPEN);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
114
133
|
this.db = Object.freeze({
|
|
115
134
|
get: (name: string) => {
|
|
116
135
|
return dbManager.getDB(name);
|
|
@@ -153,19 +172,7 @@ export class ServerInterfaceImpl implements ServerInterface {
|
|
|
153
172
|
public isPrimaryWorker(): boolean {
|
|
154
173
|
return cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
155
174
|
}
|
|
156
|
-
|
|
157
|
-
const PORT = this.port;
|
|
158
|
-
const URL = `http://localhost${PORT ? `:${PORT}` : ""}${path}`;
|
|
159
|
-
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
160
|
-
const OPEN = process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
161
|
-
if (OPEN) {
|
|
162
|
-
const openCMD = `${OPEN} "${URL}"`;
|
|
163
|
-
this.logger?.info("opening browser with [%s]", openCMD);
|
|
164
|
-
execSync(openCMD);
|
|
165
|
-
} else {
|
|
166
|
-
this.logger?.warn("ignoring browser [%s]", process.env["BROWSER"]);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
175
|
+
|
|
169
176
|
public getLogger(identifier: string, options?: { level?: any; transports?: any[]; formatter?: any; }): Logger {
|
|
170
177
|
return this.loggerProvider?.getLogger(identifier, options);
|
|
171
178
|
}
|