miqro 1.7.10 → 1.7.11

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.
Files changed (44) hide show
  1. package/dist/cli.js +72 -22
  2. package/dist/cmds/config-bash.d.ts +1 -0
  3. package/dist/cmds/config-bash.js +3 -2
  4. package/dist/cmds/config-env.d.ts +1 -0
  5. package/dist/cmds/config-env.js +3 -2
  6. package/dist/cmds/config-init.d.ts +1 -0
  7. package/dist/cmds/config-init.js +3 -2
  8. package/dist/cmds/config.d.ts +1 -0
  9. package/dist/cmds/config.js +3 -2
  10. package/dist/cmds/db-console.d.ts +1 -0
  11. package/dist/cmds/db-console.js +3 -2
  12. package/dist/cmds/db-createmodel.d.ts +1 -0
  13. package/dist/cmds/db-createmodel.js +3 -2
  14. package/dist/cmds/db-dump-data.d.ts +1 -0
  15. package/dist/cmds/db-dump-data.js +3 -2
  16. package/dist/cmds/db-init.d.ts +1 -0
  17. package/dist/cmds/db-init.js +3 -2
  18. package/dist/cmds/db-makemigrations.d.ts +1 -0
  19. package/dist/cmds/db-makemigrations.js +3 -2
  20. package/dist/cmds/db-push-data.d.ts +1 -0
  21. package/dist/cmds/db-push-data.js +3 -2
  22. package/dist/cmds/db-sync-makemigrations.d.ts +1 -0
  23. package/dist/cmds/db-sync-makemigrations.js +2 -1
  24. package/dist/cmds/doc-json.d.ts +1 -0
  25. package/dist/cmds/doc-json.js +3 -2
  26. package/dist/cmds/doc-md.d.ts +1 -0
  27. package/dist/cmds/doc-md.js +3 -2
  28. package/dist/cmds/handler-apiroute-new.d.ts +1 -0
  29. package/dist/cmds/handler-apiroute-new.js +4 -3
  30. package/dist/cmds/handler-main-new.d.ts +1 -0
  31. package/dist/cmds/handler-main-new.js +3 -2
  32. package/dist/cmds/new-test.d.ts +1 -0
  33. package/dist/cmds/new-test.js +3 -2
  34. package/dist/cmds/new.d.ts +2 -0
  35. package/dist/cmds/new.js +4 -2
  36. package/dist/cmds/serve.d.ts +1 -0
  37. package/dist/cmds/serve.js +27 -22
  38. package/dist/cmds/start.d.ts +1 -0
  39. package/dist/cmds/start.js +3 -3
  40. package/dist/cmds/watch.d.ts +2 -0
  41. package/dist/cmds/watch.js +47 -0
  42. package/dist/utils/index.d.ts +1 -0
  43. package/dist/utils/index.js +16 -5
  44. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  //@miqro/core
5
5
  const utils_1 = require("./utils");
6
6
  const start_1 = require("./cmds/start");
7
+ const watch_1 = require("./cmds/watch");
7
8
  const new_1 = require("./cmds/new");
8
- const new_2 = require("./cmds/new");
9
9
  const doc_json_1 = require("./cmds/doc-json");
10
10
  const doc_md_1 = require("./cmds/doc-md");
11
11
  const config_init_1 = require("./cmds/config-init");
@@ -26,33 +26,83 @@ const db_push_data_1 = require("./cmds/db-push-data");
26
26
  const db_dump_data_1 = require("./cmds/db-dump-data");
27
27
  // noinspection SpellCheckingInspection
28
28
  (0, utils_1.mainCMD)({
29
- ["new"]: { section: "quick start", cb: new_1.mainJS, description: "\t\t\t\tcreate a new project" },
30
- ["new:typescript"]: { cb: new_2.mainTS, description: "\t\t\tcreate a new typescript project" },
31
- ["new:main"]: { section: "http scafolding", cb: handler_main_new_1.main, description: "\t\t\tcreates a new main file" },
32
- ["new:route"]: { cb: handler_apiroute_new_1.main, description: "\t\t\tcreates a new route" },
33
- ["config"]: { section: "config managment", cb: config_1.main, description: "\t\t\t\toutputs to stdout the config as a json" },
29
+ ["new"]: { section: "quick start", cb: new_1.mainJS, tabs: 5, description: `create a new project. ${new_1.usageJS}` },
30
+ ["new:typescript"]: { cb: new_1.mainTS, tabs: 4, description: `create a new typescript project. ${new_1.usageTS}` },
31
+ ["new:main"]: {
32
+ section: "http scafolding",
33
+ cb: handler_main_new_1.main,
34
+ tabs: 4,
35
+ description: `creates a new main file. ${handler_main_new_1.usage}`
36
+ },
37
+ ["new:route"]: { cb: handler_apiroute_new_1.main, tabs: 4, description: `creates a new route. ${handler_apiroute_new_1.usage}` },
38
+ ["config"]: {
39
+ section: "config managment",
40
+ cb: config_1.main,
41
+ tabs: 5,
42
+ description: `outputs to stdout the config as a json. ${config_1.usage}`
43
+ },
34
44
  ["config:bash"]: {
35
45
  cb: config_bash_1.main,
36
- description: "\t\t\toutputs to stdout the config as a bash script"
37
- },
38
- ["config:env"]: { cb: config_env_1.main, description: "\t\t\toutputs to stdout the config as a env file" },
39
- ["config:init"]: { cb: config_init_1.main, description: "\t\t\tinits your config folder" },
40
- ["start"]: { section: "cluster start", cb: start_1.main, description: "\t\t\t\tstart a nodejs script in cluster mode and restart if crash." },
41
- ["serve"]: { section: "serve static files", cb: serve_1.main, description: "\t\t\t\tserve static files." },
42
- ["doc"]: { section: "api documentation", cb: doc_json_1.main, description: "\t\t\t\toutputs to stdout an api folder auto doc as a json" },
43
- ["doc:md"]: { cb: doc_md_1.main, description: "\t\t\t\toutputs to a file an api folder auto doc as a markdown" },
44
- ["test:new"]: { section: "testing", cb: new_test_1.main, description: "\t\t\tcreate new test.js file." },
45
- ["db:console"]: { section: "sequelize helpers", cb: db_console_1.main, description: "\t\t\truns a readline interface that send the input as a query" },
46
- ["db:dump:data"]: { cb: db_dump_data_1.main, description: "\t\t\tdump the data of the database (only defined models)" },
47
- ["db:push:data"]: { cb: db_push_data_1.main, description: "\t\t\tpush a dump to the database" },
46
+ tabs: 4,
47
+ description: `outputs to stdout the config as a bash script. ${config_bash_1.usage}`
48
+ },
49
+ ["config:env"]: {
50
+ cb: config_env_1.main,
51
+ tabs: 4,
52
+ description: `outputs to stdout the config as a env file. ${config_env_1.usage}`
53
+ },
54
+ ["config:init"]: { cb: config_init_1.main, tabs: 4, description: `inits your config folder. ${config_init_1.usage}` },
55
+ ["start"]: {
56
+ section: "start helpers",
57
+ tabs: 5,
58
+ cb: start_1.main,
59
+ description: `start a nodejs script in cluster mode and restart if crash. ${start_1.usage}`
60
+ },
61
+ ["watch"]: {
62
+ //section: "watch",
63
+ cb: watch_1.main,
64
+ tabs: 5,
65
+ description: `watch a folder for changes and runs a command if a change occours. ${watch_1.usage}`
66
+ },
67
+ ["serve"]: {
68
+ //section: "serve static files",
69
+ tabs: 6,
70
+ cb: serve_1.main, description: `serve static files. ${serve_1.usage}`
71
+ },
72
+ ["doc"]: {
73
+ section: "api documentation",
74
+ tabs: 5,
75
+ cb: doc_json_1.main,
76
+ description: `outputs to stdout an api folder auto doc as a json. ${doc_json_1.usage}`
77
+ },
78
+ ["doc:md"]: {
79
+ cb: doc_md_1.main,
80
+ tabs: 5,
81
+ description: `outputs to a file an api folder auto doc as a markdown. ${doc_md_1.usage}`
82
+ },
83
+ ["new:test"]: { section: "testing", cb: new_test_1.main, tabs: 4, description: `create new test.js file. ${new_test_1.usage}` },
84
+ ["db:console"]: {
85
+ section: "sequelize helpers",
86
+ cb: db_console_1.main,
87
+ tabs: 4,
88
+ description: `runs a readline interface that send the input as a query. ${db_console_1.usage}`
89
+ },
90
+ ["db:dump:data"]: {
91
+ cb: db_dump_data_1.main,
92
+ tabs: 4,
93
+ description: `dump the data of the database (only defined models). ${db_dump_data_1.usage}`
94
+ },
95
+ ["db:push:data"]: { cb: db_push_data_1.main, tabs: 4, description: `push a dump to the database. ${db_push_data_1.usage}` },
48
96
  ["db:make:migration"]: {
49
97
  cb: db_makemigrations_1.main,
50
- description: "\t\tseeks changes in your models and creates migrations"
98
+ tabs: 2,
99
+ description: `seeks changes in your models and creates migrations. ${db_makemigrations_1.usage}`
51
100
  },
52
101
  ["db:make:migration:force:clean:state"]: {
53
102
  cb: db_sync_makemigrations_1.main,
54
- description: "regenerate _current.json in the migrations folder to force the 'local' migration state to be the same as the current models."
103
+ tabs: 1,
104
+ description: `regenerate _current.json in the migrations folder to force the 'local' migration state to be the same as the current models. ${db_sync_makemigrations_1.usage}`
55
105
  },
56
- ["db:init"]: { cb: db_init_1.main, description: "\t\t\t\tinit sequelize configuration." },
57
- ["db:create:model"]: { cb: db_createmodel_1.main, description: "\t\t\tcreates an example model" }
106
+ ["db:init"]: { cb: db_init_1.main, tabs: 5, description: `init sequelize configuration. ${db_init_1.usage}` },
107
+ ["db:create:model"]: { cb: db_createmodel_1.main, tabs: 4, description: `creates an example model. ${db_createmodel_1.usage}` }
58
108
  }, "npx miqro <command> [args]", console);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro config:bash";
1
2
  export declare const main: () => void;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
+ exports.usage = "usage: [NODE_ENV=development] npx miqro config:bash";
5
6
  const main = () => {
6
7
  const logger = console;
7
8
  if (process.argv.length !== 3) {
8
- throw new Error(`invalid number of args`);
9
+ throw new Error(`invalid number of args. ${exports.usage}`);
9
10
  }
10
11
  const configOut = (0, core_1.loadConfig)();
11
12
  const config = configOut.combined;
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro config:env";
1
2
  export declare const main: () => void;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
+ exports.usage = "usage: [NODE_ENV=development] npx miqro config:env";
5
6
  const main = () => {
6
7
  const logger = console;
7
8
  if (process.argv.length !== 3) {
8
- throw new Error(`invalid number of args`);
9
+ throw new Error(`invalid number of args. ${exports.usage}`);
9
10
  }
10
11
  const configOut = (0, core_1.loadConfig)();
11
12
  const config = configOut.combined;
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro config:init";
1
2
  export declare const main: () => void;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const core_1 = require("@miqro/core");
7
7
  const templates_1 = require("../utils/templates");
8
+ exports.usage = "usage: [NODE_ENV=development] npx miqro config:init";
8
9
  const main = () => {
9
10
  const logger = console;
10
11
  if (process.argv.length !== 3) {
11
- throw new Error(`invalid number of args`);
12
+ throw new Error(`invalid number of args. ${exports.usage}`);
12
13
  }
13
14
  (0, core_1.loadConfig)();
14
15
  const configPath = core_1.ConfigPathResolver.getConfigDirname();
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro config";
1
2
  export declare const main: () => void;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
+ exports.usage = "usage: [NODE_ENV=development] npx miqro config";
5
6
  const main = () => {
6
7
  const logger = console;
7
8
  if (process.argv.length !== 3) {
8
- throw new Error(`invalid number of args`);
9
+ throw new Error(`invalid number of args. ${exports.usage}`);
9
10
  }
10
11
  const configOut = (0, core_1.loadConfig)();
11
12
  const config = configOut.combined;
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro db:console";
1
2
  export declare const main: () => void;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const readline_1 = require("readline");
6
6
  const db_1 = require("../utils/db");
7
+ exports.usage = "usage: [NODE_ENV=development] npx miqro db:console";
7
8
  const main = () => {
8
9
  if (process.argv.length !== 3) {
9
- throw new Error(`invalid number of args`);
10
+ throw new Error(`invalid number of args. ${exports.usage}`);
10
11
  }
11
12
  (0, core_1.loadConfig)();
12
13
  const logger = (0, core_1.getLogger)("db:console");
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro db:create:model <modelname>";
1
2
  export declare const main: () => void;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const templates_1 = require("../utils/templates");
7
7
  const core_1 = require("@miqro/core");
8
8
  const db_1 = require("../utils/db");
9
+ exports.usage = "usage: [NODE_ENV=development] npx miqro db:create:model <modelname>";
9
10
  const main = () => {
10
11
  const logger = console;
11
12
  const modelname = process.argv[3];
12
13
  if (process.argv.length !== 4) {
13
- throw new Error(`arguments: <modelname>`);
14
+ throw new Error(exports.usage);
14
15
  }
15
16
  if (typeof modelname !== "string") {
16
17
  throw new Error(`<modelname> must be a string!`);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] [LIMIT_COUNT=100] npx miqro db:dump:data <outfile>";
1
2
  export declare const main: () => Promise<void>;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const path_1 = require("path");
6
6
  const fs_1 = require("fs");
7
7
  const db_1 = require("../utils/db");
8
+ exports.usage = "usage: [NODE_ENV=development] [LIMIT_COUNT=100] npx miqro db:dump:data <outfile>";
8
9
  const main = async () => {
9
10
  const logger = console;
10
11
  const outfile = process.argv[3];
11
12
  if (process.argv.length !== 4) {
12
- throw new Error(`[LIMIT_COUNT=100] arguments: <outfile>`);
13
+ throw new Error(`invalid number of args. ${exports.usage}`);
13
14
  }
14
15
  if (typeof outfile !== "string") {
15
16
  throw new Error(`<outfile> must be a string!`);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro db:init";
1
2
  export declare const main: () => void;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
7
  const utils_1 = require("../utils");
8
8
  const db_1 = require("../utils/db");
9
9
  const templates_1 = require("../utils/templates");
10
+ exports.usage = "usage: [NODE_ENV=development] npx miqro db:init";
10
11
  const main = () => {
11
12
  const logger = console;
12
13
  if (process.argv.length !== 3) {
13
- throw new Error(`invalid number of args`);
14
+ throw new Error(`invalid number of args. ${exports.usage}`);
14
15
  }
15
16
  const initEnvFile = (path, template) => {
16
17
  if (!(0, fs_1.existsSync)(path)) {
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro db:make:migration";
1
2
  export declare const main: () => void;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const db_1 = require("../utils/db");
5
5
  const core_1 = require("@miqro/core");
6
+ exports.usage = "usage: [NODE_ENV=development] npx miqro db:make:migration";
6
7
  const main = () => {
7
8
  if (process.argv.length !== 3) {
8
- throw new Error(`invalid number of args`);
9
+ throw new Error(`invalid number of args. ${exports.usage}`);
9
10
  }
10
11
  (0, core_1.loadConfig)();
11
12
  (0, db_1.makemigrations)();
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] [BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] npx miqro db:push:data <outfile> <modelA,..>";
1
2
  export declare const main: () => Promise<void>;
@@ -1,15 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const path_1 = require("path");
6
6
  const fs_1 = require("fs");
7
7
  const db_1 = require("../utils/db");
8
+ exports.usage = "usage: [NODE_ENV=development] [BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] npx miqro db:push:data <outfile> <modelA,..>";
8
9
  const main = async () => {
9
10
  const outfile = process.argv[3];
10
11
  const models = process.argv[4];
11
12
  if (process.argv.length !== 5) {
12
- throw new Error(`[BULK_CREATE_COUNT=10] [BULK_CREATE_IGNORE_ERROR=true] arguments: <outfile> <modelA,..>`);
13
+ throw new Error(exports.usage);
13
14
  }
14
15
  if (typeof outfile !== "string") {
15
16
  throw new Error(`<outfile> must be a string!`);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro db:make:migration:force:clean:state";
1
2
  export declare const main: () => void;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const db_1 = require("../utils/db");
5
5
  const core_1 = require("@miqro/core");
6
+ exports.usage = "usage: [NODE_ENV=development] npx miqro db:make:migration:force:clean:state";
6
7
  const main = () => {
7
8
  if (process.argv.length !== 3) {
8
9
  throw new Error(`invalid number of args`);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath>";
1
2
  export declare const main: () => void;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const doc_1 = require("../utils/doc");
6
+ exports.usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath>`;
6
7
  const main = () => {
7
8
  if (process.argv.length !== 5) {
8
- throw new Error(`arguments: <api_folder> <subPath>`);
9
+ throw new Error(exports.usage);
9
10
  }
10
11
  const dirname = process.argv[3];
11
12
  const subPath = process.argv[4];
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro doc:md <api_folder> <subPath> <out.md>";
1
2
  export declare const main: () => void;
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const path_1 = require("path");
6
6
  const fs_1 = require("fs");
7
7
  const doc_1 = require("../utils/doc");
8
+ exports.usage = `usage: [NODE_ENV=development] npx miqro doc:md <api_folder> <subPath> <out.md>`;
8
9
  const main = () => {
9
10
  if (process.argv.length !== 6) {
10
- throw new Error(`arguments: <api_folder> <subPath> <out.md>`);
11
+ throw new Error(exports.usage);
11
12
  }
12
13
  const dirname = process.argv[3];
13
14
  const subPath = process.argv[4];
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro new:route <identifier ex: SRC_API_V1_HEALTH>";
1
2
  export declare const main: () => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
@@ -42,15 +42,16 @@ export default {
42
42
  };
43
43
  `
44
44
  };
45
+ exports.usage = `usage: [NODE_ENV=development] npx miqro new:route <identifier ex: SRC_API_V1_HEALTH>`;
45
46
  const main = () => {
46
47
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
47
- throw new Error(`arguments: <identifier ex: SRC_API_V1_HEALTH>`);
48
+ throw new Error(exports.usage);
48
49
  }
49
50
  const identifier = process.argv[3].toLocaleLowerCase();
50
51
  const split = identifier.split("_").map(s => s.trim()).filter(s => s);
51
52
  const dots = split.filter(s => s.indexOf(".") !== -1);
52
53
  if (dots.length > 0) {
53
- throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_API_V1_HEALTH>`);
54
+ throw new Error(`identifier cannot contain dots\n${exports.usage}`);
54
55
  }
55
56
  (0, core_1.loadConfig)();
56
57
  const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro new:main <identifier ex: NEW_APP>";
1
2
  export declare const main: () => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
@@ -48,9 +48,10 @@ app.listen(PORT, () => {
48
48
  });
49
49
  `
50
50
  };
51
+ exports.usage = `usage: [NODE_ENV=development] npx miqro new:main <identifier ex: NEW_APP>`;
51
52
  const main = () => {
52
53
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
53
- throw new Error(`arguments: <identifier ex: SRC_MAIN>`);
54
+ throw new Error(exports.usage);
54
55
  }
55
56
  const identifier = process.argv[3].toLocaleLowerCase();
56
57
  const split = identifier.split("_");
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro new:test <identifier ex: SRC_MAIN>";
1
2
  export declare const main: () => void;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = require("path");
7
+ exports.usage = `usage: [NODE_ENV=development] npx miqro new:test <identifier ex: SRC_MAIN>`;
7
8
  const testTemplates = {
8
9
  js: (category) => `const options = {
9
10
  category: "${category}",
@@ -22,7 +23,7 @@ it("happy path", async () => {
22
23
  };
23
24
  const main = () => {
24
25
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
25
- throw new Error(`arguments: <identifier ex: SRC_MAIN>`);
26
+ throw new Error(exports.usage);
26
27
  }
27
28
  const identifier = process.argv[3].toLocaleLowerCase();
28
29
  const split = identifier.split("_");
@@ -1,2 +1,4 @@
1
+ export declare const usageJS = "usage: npx miqro new <identifier ex: NEW_APP>";
2
+ export declare const usageTS = "usage: npx miqro new:typescript <identifier ex: NEW_APP>";
1
3
  export declare const mainJS: (typescript?: boolean) => void;
2
4
  export declare const mainTS: () => void;
package/dist/cmds/new.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mainTS = exports.mainJS = void 0;
3
+ exports.mainTS = exports.mainJS = exports.usageTS = exports.usageJS = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const utils_1 = require("../utils");
@@ -50,9 +50,11 @@ const packageTemplate = {
50
50
  "license": "ISC"
51
51
  }`
52
52
  };
53
+ exports.usageJS = `usage: npx miqro new <identifier ex: NEW_APP>`;
54
+ exports.usageTS = `usage: npx miqro new:typescript <identifier ex: NEW_APP>`;
53
55
  const mainJS = (typescript = false) => {
54
56
  if (process.argv.length !== 4 || process.argv[3].length < 1) {
55
- throw new Error(`arguments: <name ex: NEW_APP>`);
57
+ throw new Error(typescript ? exports.usageTS : exports.usageJS);
56
58
  }
57
59
  const identifier = process.argv[3].toLocaleLowerCase();
58
60
  const appFolder = (0, path_1.resolve)(process.cwd(), identifier);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]";
1
2
  export declare const main: () => void;
@@ -1,32 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const core_1 = require("@miqro/core");
5
5
  const utils_1 = require("../utils");
6
6
  const url_1 = require("url");
7
7
  const tokenize_match_1 = require("@miqro/core/dist/common/tokenize-match");
8
+ const fs_1 = require("fs");
9
+ exports.usage = `usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]`;
8
10
  const main = () => {
9
11
  const flags = (0, utils_1.extractFlags)(process.argv.slice(3), {
10
12
  flags: {
11
- "proxy": {
12
- description: "proxy",
13
- hasValue: true
14
- },
15
- "proxy-cert-ignore": {
16
- description: "proxy ignore certs",
17
- hasValue: false
18
- },
19
- "port": {
20
- description: "port",
21
- hasValue: true
13
+ "index404": {
14
+ description: "file to handle 404", hasValue: true
15
+ }, "proxy": {
16
+ description: "proxy", hasValue: true
17
+ }, "proxy-cert-ignore": {
18
+ description: "proxy ignore certs", hasValue: false
19
+ }, "port": {
20
+ description: "port", hasValue: true
22
21
  }
23
22
  }
24
23
  });
25
24
  if (flags.files.length > 2) {
26
- throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/]`);
25
+ throw new Error(`invalid arguments.\n${exports.usage}`);
26
+ }
27
+ if (flags.flags.index404 instanceof Array) {
28
+ throw new Error(`invalid index404!.\n${exports.usage}`);
27
29
  }
28
30
  if (flags.flags.port instanceof Array) {
29
- throw new Error(`invalid number of args\nusage: [PORT=8080] npx miqro serve [directory=./] [path=/] [--port 8080] [--proxy /api=https://host/api]`);
31
+ throw new Error(`invalid port!.\n${exports.usage}`);
30
32
  }
31
33
  let [directory, path] = flags.files;
32
34
  path = path ? path : "/";
@@ -34,7 +36,10 @@ const main = () => {
34
36
  (0, core_1.loadConfig)();
35
37
  const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
36
38
  if (PORT === undefined) {
37
- throw new Error("port not defined");
39
+ throw new Error(`invalid port!.\n${exports.usage}`);
40
+ }
41
+ if (!(0, fs_1.existsSync)(directory) || !(0, fs_1.statSync)(directory).isDirectory()) {
42
+ throw new Error(`${directory} directory not found!\n${exports.usage}`);
38
43
  }
39
44
  const app = new core_1.App();
40
45
  app.use((0, core_1.LoggerHandler)());
@@ -48,16 +53,16 @@ const main = () => {
48
53
  const proxyPath = (0, tokenize_match_1.normalizePath)(proxySplit[0]);
49
54
  const proxyURL = new url_1.URL(proxySplit[1]);
50
55
  proxyURL.pathname = (0, tokenize_match_1.normalizePath)(proxyURL.pathname);
51
- app.use((0, core_1.ReadBuffer)());
52
- app.use((0, core_1.Proxy)({
53
- url: proxyURL.toString(),
54
- rejectUnauthorized: !flags.flags.hasOwnProperty("proxy-cert-ignore")
55
- }), proxyPath);
56
+ const proxyRouter = (0, core_1.Proxy)({
57
+ url: proxyURL.toString(), rejectUnauthorized: !flags.flags.hasOwnProperty("proxy-cert-ignore")
58
+ });
59
+ console.log("setting up proxy to %s on %s", proxyURL.toString(), proxyPath);
60
+ proxyRouter.use((0, core_1.ReadBuffer)());
61
+ app.use(proxyRouter, proxyPath);
56
62
  }
57
63
  }
58
64
  app.use((0, core_1.Static)({
59
- directory,
60
- list: true
65
+ directory, list: true, index404: flags.flags.index404 ? flags.flags.index404 : undefined
61
66
  }), path);
62
67
  app.listen(PORT, () => {
63
68
  console.log("serving " + directory + " on " + path + " on port " + PORT);
@@ -1 +1,2 @@
1
+ export declare const usage = "usage: [NODE_ENV=development] CLUSTER_COUNT=1 [DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
1
2
  export declare const main: () => void;
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.main = void 0;
3
+ exports.main = exports.usage = void 0;
4
4
  const utils_1 = require("../utils");
5
5
  const runner_1 = require("@miqro/runner");
6
6
  const core_1 = require("@miqro/core");
7
+ exports.usage = "usage: [NODE_ENV=development] CLUSTER_COUNT=1 [DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
7
8
  const main = () => {
8
9
  if (process.argv.length <= 3) {
9
- throw new Error(`invalid number of args\nusage: CLUSTER_COUNT=1 [DISABLE_RESTART=true|false] npx miqro start <script> [...args]`);
10
+ throw new Error(`invalid number of args\n${exports.usage}`);
10
11
  }
11
12
  (0, core_1.loadConfig)();
12
- //execSync(`npx @miqro/runner ${process.argv.slice(3).join(" ")}`);
13
13
  (0, utils_1.execSync)(`${process.argv[0]} ${(0, runner_1.mainPath)()} ${process.argv.slice(3).join(" ")}`);
14
14
  };
15
15
  exports.main = main;
@@ -0,0 +1,2 @@
1
+ export declare const usage: string;
2
+ export declare const main: () => void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.main = exports.usage = void 0;
4
+ const fs_1 = require("fs");
5
+ const utils_1 = require("../utils");
6
+ const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro watch <directory> <cmd>`;
7
+ exports.usage = usageMessage();
8
+ function setupWatch(directory, cmd, timeout = 1000) {
9
+ (0, fs_1.watchFile)(directory, () => {
10
+ queueRunCMD(cmd, timeout);
11
+ });
12
+ (0, fs_1.watch)(directory, () => {
13
+ queueRunCMD(cmd, timeout);
14
+ });
15
+ }
16
+ let cmdTimeout = null;
17
+ let running = false;
18
+ function queueRunCMD(cmd, timeout) {
19
+ if (running) {
20
+ return;
21
+ }
22
+ if (cmdTimeout) {
23
+ clearTimeout(cmdTimeout);
24
+ }
25
+ cmdTimeout = setTimeout(() => {
26
+ running = true;
27
+ (0, utils_1.execSync)(cmd, {
28
+ cwd: process.cwd(),
29
+ env: process.env
30
+ });
31
+ running = false;
32
+ }, timeout);
33
+ }
34
+ const main = () => {
35
+ if (process.argv.length < 5) {
36
+ throw new Error(usageMessage("invalid number of args"));
37
+ }
38
+ const directory = process.argv[3];
39
+ const cmd = process.argv.slice(4).join(" ");
40
+ const timeout = process.env.WATCH_TIMEOUT ? parseInt(process.env.WATCH_TIMEOUT, 10) : undefined;
41
+ if (!(0, fs_1.existsSync)(directory) || !(0, fs_1.statSync)(directory).isDirectory()) {
42
+ throw new Error(usageMessage("directory not found!"));
43
+ }
44
+ console.log(`setting up watch on ${directory} with cmd ${cmd}`);
45
+ setupWatch(directory, cmd, timeout);
46
+ };
47
+ exports.main = main;
@@ -20,6 +20,7 @@ export declare const mainCMD: (cmds: {
20
20
  cb: Callback<void> | Callback<Promise<void>>;
21
21
  description: string;
22
22
  section?: string | undefined;
23
+ tabs?: number | undefined;
23
24
  };
24
25
  }, usage: string, logger: Console | {
25
26
  error: (...args: any[]) => void;
@@ -61,6 +61,14 @@ const extractFlags = (args, options) => {
61
61
  return { flags, files };
62
62
  };
63
63
  exports.extractFlags = extractFlags;
64
+ const getTabs = (n) => {
65
+ n = n ? n : 1;
66
+ let ret = "";
67
+ for (let i = 0; i < n; i++) {
68
+ ret += "\t";
69
+ }
70
+ return ret;
71
+ };
64
72
  const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
65
73
  const flow = async () => {
66
74
  try {
@@ -71,12 +79,15 @@ const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) =>
71
79
  logger.error(e.message);
72
80
  }
73
81
  logger.info(`${usage}`);
74
- logger.info(`Available commands:`);
82
+ logger.info(`Available commands:\n`);
75
83
  for (const cmd of Object.keys(cmds)) {
76
- if (cmds[cmd].section) {
77
- logger.info(`\n${cmds[cmd].section}\n`);
78
- }
79
- logger.info(`\t${cmd}\t${cmds[cmd].description}`);
84
+ /*if (cmds[cmd].section) {
85
+ logger.info(`\n${cmds[cmd].section}\n`);
86
+ }*/
87
+ //const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/2)}${s}`).join("\n");
88
+ const description = cmds[cmd].description.split("\n").map(s => `${getTabs(/*cmds[cmd].tabs*/ 1)}${s}`).join("\n");
89
+ //logger.info(`\t${cmd}\n${description}`);
90
+ logger.info(`${cmd}\n${description}`);
80
91
  }
81
92
  logger.info("");
82
93
  if (exit) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miqro",
3
- "version": "1.7.10",
3
+ "version": "1.7.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,10 +17,10 @@
17
17
  "author": "claukers",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@miqro/core": "^1.5.8",
21
- "@miqro/parser": "^0.0.3",
20
+ "@miqro/core": "^1.5.10",
21
+ "@miqro/parser": "^0.0.4",
22
22
  "@miqro/runner": "^1.2.5",
23
- "@miqro/test": "^0.0.10",
23
+ "@miqro/test": "^0.0.11",
24
24
  "deep-diff": "1.0.2"
25
25
  },
26
26
  "devDependencies": {