miqro 6.2.13 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,7 @@ export interface Arguments {
38
38
  services: string[];
39
39
  editor: boolean;
40
40
  hotreload: boolean;
41
+ watch: boolean;
41
42
  https: boolean;
42
43
  serverOptions: ServerOptions;
43
44
  httpsRedirect?: number;
@@ -56,6 +56,7 @@ export function parseArguments() {
56
56
  browser: null,
57
57
  logFile: null,
58
58
  hotreload: null,
59
+ watch: null,
59
60
  miqroJSONPath: null,
60
61
  installMiqroJSON: null,
61
62
  disableMiqroJSON: null,
@@ -133,6 +134,14 @@ export function parseArguments() {
133
134
  flags.installTSConfig = true;
134
135
  continue;
135
136
  case "--watch":
137
+ if (flags.watch !== null) {
138
+ console.error("bad arguments.");
139
+ console.error(usage);
140
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
141
+ }
142
+ flags.watch = true;
143
+ continue;
144
+ case "--hot-reload":
136
145
  if (flags.hotreload !== null) {
137
146
  console.error("bad arguments.");
138
147
  console.error(usage);
@@ -564,19 +573,19 @@ export function parseArguments() {
564
573
  console.error("bad arguments. cannot use --editor with--install-types, --install-tsconfig or --install-miqrojson");
565
574
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
566
575
  }
567
- if (flags.test && (flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
576
+ if (flags.test && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
568
577
  console.error("bad arguments. cannot use --editor with --test");
569
578
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
570
579
  }
571
- if (flags.migrateUp && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
580
+ if (flags.migrateUp && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
572
581
  console.error("bad arguments. cannot use with --migrate-up");
573
582
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
574
583
  }
575
- if (flags.migrateDown && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
584
+ if (flags.migrateDown && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
576
585
  console.error("bad arguments. cannot use with --migrate-down");
577
586
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
578
587
  }
579
- if (flags.generateDoc && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
588
+ if (flags.generateDoc && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
580
589
  console.error("bad arguments. cannot use with --generate-doc");
581
590
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
582
591
  }
@@ -604,6 +613,7 @@ export function parseArguments() {
604
613
  logFile: flags.logFile !== null ? flags.logFile : undefined,
605
614
  generateDocAll: flags.generateDocAll ? true : false,
606
615
  hotreload: flags.hotreload ? true : false,
616
+ watch: flags.watch ? true : false,
607
617
  disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
608
618
  miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
609
619
  installTypes: flags.installTypes ? true : false,
@@ -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\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--https\n\tserves the server in https instead of http\n--https-key\n\tpoint to a server.key file for https.\n--https-cert\n\tpoint to a server.cert file for https.\n--https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.\n--inflate-parallel\n\tsets the max parallel esbuild instances. defaults to 1.\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";
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 auto reload the server when files change.\n--hot-reload\n\tenables the hot-reload functionality use with --watch.\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--https\n\tserves the server in https instead of http\n--https-key\n\tpoint to a server.key file for https.\n--https-cert\n\tpoint to a server.cert file for https.\n--https-redirect\n\tserves an aditional http server that redirects to https. it needs a port number.\n--inflate-parallel\n\tsets the max parallel esbuild instances. defaults to 1.\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";
@@ -15,7 +15,8 @@ export const help = `
15
15
 
16
16
  -v, --version\n\toutputs the version number
17
17
  -h, --help\n\toutputs this page.
18
- --watch\n\tuse to enable the hot-reload functionality.
18
+ --watch\n\tuse to auto reload the server when files change.
19
+ --hot-reload\n\tenables the hot-reload functionality use with --watch.
19
20
  --test\n\trun the tests for a service.
20
21
  --migrate-up\n\tmigrations up.
21
22
  --migrate-down\n\tmigrations down.
@@ -43,6 +43,7 @@ export async function watchAndServer(app) {
43
43
  }, 2000);
44
44
  }
45
45
  function watchDir(toWatch) {
46
+ clearTimeout(timeout);
46
47
  const files = existsSync(toWatch) ? readdirSync(toWatch) : [];
47
48
  for (const file of files) {
48
49
  const filePath = resolve(toWatch, file);
@@ -56,6 +57,7 @@ export async function watchAndServer(app) {
56
57
  }
57
58
  }
58
59
  function stopWatch() {
60
+ clearTimeout(timeout);
59
61
  const toClose = watchers.splice(0, watchers.length);
60
62
  for (const watcher of toClose) {
61
63
  watcher.close();
@@ -63,6 +65,7 @@ export async function watchAndServer(app) {
63
65
  }
64
66
  function reWatch() {
65
67
  stopWatch();
68
+ clearTimeout(timeout);
66
69
  for (const service of app.options.services) {
67
70
  const toWatch = resolve(process.cwd(), service);
68
71
  watchDir(toWatch);
@@ -22,6 +22,7 @@ async function main(args) {
22
22
  browser: args.browser,
23
23
  logFile: args.logFile,
24
24
  hotreload: args.test ? false : args.hotreload,
25
+ watch: args.test ? false : args.watch,
25
26
  https: args.test ? false : args.https,
26
27
  serverOptions: args.serverOptions,
27
28
  httpRedirect: args.test ? undefined : args.httpsRedirect
@@ -22,6 +22,7 @@ export interface MiqroOptions {
22
22
  browser?: string | boolean;
23
23
  logFile?: string | boolean;
24
24
  hotreload?: boolean;
25
+ watch?: boolean;
25
26
  serverOptions?: ServerOptions<any, any>;
26
27
  https?: boolean;
27
28
  httpRedirect?: number;
@@ -400,7 +400,7 @@ export class Miqro {
400
400
  this.logger?.debug("\t\t==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
401
401
  }
402
402
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
403
- if (this.options.hotreload && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
403
+ if (this.options.watch && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
404
404
  this.watcher = await watchAndServer(this);
405
405
  }
406
406
  this.logger?.debug("\t\t==start done==");
package/build/lib.cjs CHANGED
@@ -16468,6 +16468,7 @@ async function watchAndServer(app) {
16468
16468
  }, 2e3);
16469
16469
  }
16470
16470
  function watchDir(toWatch) {
16471
+ clearTimeout(timeout);
16471
16472
  const files = (0, import_node_fs23.existsSync)(toWatch) ? (0, import_node_fs23.readdirSync)(toWatch) : [];
16472
16473
  for (const file of files) {
16473
16474
  const filePath = (0, import_node_path26.resolve)(toWatch, file);
@@ -16479,6 +16480,7 @@ async function watchAndServer(app) {
16479
16480
  }
16480
16481
  }
16481
16482
  function stopWatch() {
16483
+ clearTimeout(timeout);
16482
16484
  const toClose = watchers.splice(0, watchers.length);
16483
16485
  for (const watcher of toClose) {
16484
16486
  watcher.close();
@@ -16486,6 +16488,7 @@ async function watchAndServer(app) {
16486
16488
  }
16487
16489
  function reWatch() {
16488
16490
  stopWatch();
16491
+ clearTimeout(timeout);
16489
16492
  for (const service of app.options.services) {
16490
16493
  const toWatch = (0, import_node_path26.resolve)(process.cwd(), service);
16491
16494
  watchDir(toWatch);
@@ -17213,7 +17216,7 @@ var Miqro = class _Miqro {
17213
17216
  this.logger?.debug(" ==listening on [%s][%s]==", this.options.https ? "https" : "http", this.options.port);
17214
17217
  }
17215
17218
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
17216
- if (this.options.hotreload && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17219
+ if (this.options.watch && (import_node_cluster3.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
17217
17220
  this.watcher = await watchAndServer(this);
17218
17221
  }
17219
17222
  this.logger?.debug(" ==start done==");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "6.2.13",
3
+ "version": "6.3.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/esm/src/lib.js",
@@ -85,6 +85,7 @@ export interface Arguments {
85
85
  services: string[];
86
86
  editor: boolean;
87
87
  hotreload: boolean;
88
+ watch: boolean;
88
89
  https: boolean;
89
90
  serverOptions: ServerOptions;
90
91
  httpsRedirect?: number;
@@ -126,6 +127,7 @@ export function parseArguments(): Arguments {
126
127
  editor: boolean | null;
127
128
  inflateDir?: string | null;
128
129
  hotreload?: boolean | null;
130
+ watch?: boolean | null;
129
131
  } = {
130
132
  inflateParallel: null,
131
133
  httpsRedirect: null,
@@ -135,6 +137,7 @@ export function parseArguments(): Arguments {
135
137
  browser: null,
136
138
  logFile: null,
137
139
  hotreload: null,
140
+ watch: null,
138
141
  miqroJSONPath: null,
139
142
  installMiqroJSON: null,
140
143
  disableMiqroJSON: null,
@@ -211,6 +214,14 @@ export function parseArguments(): Arguments {
211
214
  flags.installTSConfig = true;
212
215
  continue;
213
216
  case "--watch":
217
+ if (flags.watch !== null) {
218
+ console.error("bad arguments.");
219
+ console.error(usage);
220
+ process.exit(EXIT_CODES.BAD_ARGUMENTS);
221
+ }
222
+ flags.watch = true;
223
+ continue;
224
+ case "--hot-reload":
214
225
  if (flags.hotreload !== null) {
215
226
  console.error("bad arguments.");
216
227
  console.error(usage);
@@ -659,22 +670,22 @@ export function parseArguments(): Arguments {
659
670
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
660
671
  }
661
672
 
662
- if (flags.test && (flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
673
+ if (flags.test && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.inflate)) {
663
674
  console.error("bad arguments. cannot use --editor with --test");
664
675
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
665
676
  }
666
677
 
667
- if (flags.migrateUp && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
678
+ if (flags.migrateUp && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateDown || flags.inflate)) {
668
679
  console.error("bad arguments. cannot use with --migrate-up");
669
680
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
670
681
  }
671
682
 
672
- if (flags.migrateDown && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
683
+ if (flags.migrateDown && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate)) {
673
684
  console.error("bad arguments. cannot use with --migrate-down");
674
685
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
675
686
  }
676
687
 
677
- if (flags.generateDoc && (flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
688
+ if (flags.generateDoc && (flags.watch || flags.hotreload || flags.editor || flags.compile || flags.test || flags.migrateUp || flags.inflate || flags.migrateDown)) {
678
689
  console.error("bad arguments. cannot use with --generate-doc");
679
690
  process.exit(EXIT_CODES.BAD_ARGUMENTS);
680
691
  }
@@ -708,6 +719,7 @@ export function parseArguments(): Arguments {
708
719
  logFile: flags.logFile !== null ? flags.logFile : undefined,
709
720
  generateDocAll: flags.generateDocAll ? true : false,
710
721
  hotreload: flags.hotreload ? true : false,
722
+ watch: flags.watch ? true : false,
711
723
  disableMiqroJSON: flags.disableMiqroJSON !== null ? flags.disableMiqroJSON : false,
712
724
  miqroJSONPath: miqroJSONPath ? miqroJSONPath : false,
713
725
  installTypes: flags.installTypes ? true : false,
@@ -18,7 +18,8 @@ export const help = `
18
18
 
19
19
  -v, --version\n\toutputs the version number
20
20
  -h, --help\n\toutputs this page.
21
- --watch\n\tuse to enable the hot-reload functionality.
21
+ --watch\n\tuse to auto reload the server when files change.
22
+ --hot-reload\n\tenables the hot-reload functionality use with --watch.
22
23
  --test\n\trun the tests for a service.
23
24
  --migrate-up\n\tmigrations up.
24
25
  --migrate-down\n\tmigrations down.
@@ -47,6 +47,7 @@ export async function watchAndServer(app: Miqro) {
47
47
  }
48
48
 
49
49
  function watchDir(toWatch: string) {
50
+ clearTimeout(timeout);
50
51
  const files = existsSync(toWatch) ? readdirSync(toWatch) : [];
51
52
  for (const file of files) {
52
53
  const filePath = resolve(toWatch, file);
@@ -60,6 +61,7 @@ export async function watchAndServer(app: Miqro) {
60
61
  }
61
62
 
62
63
  function stopWatch() {
64
+ clearTimeout(timeout);
63
65
  const toClose = watchers.splice(0, watchers.length);
64
66
  for (const watcher of toClose) {
65
67
  watcher.close();
@@ -69,6 +71,7 @@ export async function watchAndServer(app: Miqro) {
69
71
 
70
72
  function reWatch() {
71
73
  stopWatch();
74
+ clearTimeout(timeout);
72
75
  for (const service of app.options.services) {
73
76
  const toWatch = resolve(process.cwd(), service);
74
77
  watchDir(toWatch);
package/src/main.ts CHANGED
@@ -23,6 +23,7 @@ async function main(args: Arguments) {
23
23
  browser: args.browser,
24
24
  logFile: args.logFile,
25
25
  hotreload: args.test ? false : args.hotreload,
26
+ watch: args.test ? false : args.watch,
26
27
  https: args.test ? false : args.https,
27
28
  serverOptions: args.serverOptions,
28
29
  httpRedirect: args.test ? undefined : args.httpsRedirect
@@ -43,6 +43,7 @@ export interface MiqroOptions {
43
43
  browser?: string | boolean;
44
44
  logFile?: string | boolean;
45
45
  hotreload?: boolean;
46
+ watch?: boolean;
46
47
  serverOptions?: ServerOptions<any, any>;
47
48
  https?: boolean;
48
49
  httpRedirect?: number;
@@ -494,7 +495,7 @@ export class Miqro {
494
495
 
495
496
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, this.inflated.serverConfigMap, "start");
496
497
 
497
- if (this.options.hotreload && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
498
+ if (this.options.watch && (cluster.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0")) {
498
499
  this.watcher = await watchAndServer(this);
499
500
  }
500
501