miqro 3.0.1 → 4.0.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.
- package/build/cli.js +3 -5
- package/build/cmd-map.d.ts +2 -2
- package/build/cmd-map.js +33 -36
- package/build/cmds/config-bash.js +5 -9
- package/build/cmds/config-env.js +5 -9
- package/build/cmds/config-init.js +16 -20
- package/build/cmds/config.js +5 -9
- package/build/cmds/doc-json.js +7 -11
- package/build/cmds/doc-md.js +7 -11
- package/build/cmds/handler-apiroute-new.js +14 -18
- package/build/cmds/handler-main-new.js +13 -17
- package/build/cmds/help.js +4 -8
- package/build/cmds/new-test.js +12 -16
- package/build/cmds/new.js +21 -25
- package/build/cmds/serve.js +23 -27
- package/build/cmds/start.d.ts +1 -1
- package/build/cmds/start.js +8 -12
- package/build/cmds/watch.js +8 -12
- package/build/cmds/wc-new.js +20 -24
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -1
- package/build/utils/doc/json.d.ts +1 -1
- package/build/utils/doc/json.js +5 -9
- package/build/utils/doc/md.d.ts +5 -6
- package/build/utils/doc/md.js +48 -20
- package/build/utils/index.d.ts +1 -1
- package/build/utils/index.js +6 -13
- package/build/utils/templates.js +9 -12
- package/package.json +5 -5
package/build/cli.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
(0, utils_1.mainCMD)(cmd_map_1.CMDS, cmd_map_1.usage, console);
|
|
2
|
+
import { CMD_MAP, usage } from "./cmd-map.js";
|
|
3
|
+
import { mainCMD } from "./utils/index.js";
|
|
4
|
+
mainCMD(CMD_MAP, usage, console);
|
package/build/cmd-map.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { main as help } from "./cmds/help";
|
|
1
|
+
import { main as help } from "./cmds/help.js";
|
|
2
2
|
export declare const usage = "npx miqro <command> [args]";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const CMD_MAP: {
|
|
4
4
|
"new:api": {
|
|
5
5
|
cb: () => void;
|
|
6
6
|
tabs: number;
|
package/build/cmd-map.js
CHANGED
|
@@ -1,60 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const handler_main_new_1 = require("./cmds/handler-main-new");
|
|
18
|
-
exports.usage = "npx miqro <command> [args]";
|
|
19
|
-
exports.CMDS = {
|
|
1
|
+
import { main as start } from "./cmds/start.js";
|
|
2
|
+
import { main as watch } from "./cmds/watch.js";
|
|
3
|
+
import { mainTS as newTS } from "./cmds/new.js";
|
|
4
|
+
import { main as apiDocJSON } from "./cmds/doc-json.js";
|
|
5
|
+
import { main as apiDocMD } from "./cmds/doc-md.js";
|
|
6
|
+
import { main as configInit } from "./cmds/config-init.js";
|
|
7
|
+
import { main as config } from "./cmds/config.js";
|
|
8
|
+
import { main as configBash } from "./cmds/config-bash.js";
|
|
9
|
+
import { main as configEnv } from "./cmds/config-env.js";
|
|
10
|
+
import { main as newRoute } from "./cmds/handler-apiroute-new.js";
|
|
11
|
+
import { main as newTest } from "./cmds/new-test.js";
|
|
12
|
+
import { main as serve } from "./cmds/serve.js";
|
|
13
|
+
import { main as help } from "./cmds/help.js";
|
|
14
|
+
import { main as newMain } from "./cmds/handler-main-new.js";
|
|
15
|
+
export const usage = "npx miqro <command> [args]";
|
|
16
|
+
export const CMD_MAP = {
|
|
20
17
|
["new:api"]: {
|
|
21
18
|
//section: "api development",
|
|
22
|
-
cb:
|
|
19
|
+
cb: newTS, tabs: 4, description: `create a new project.`
|
|
23
20
|
},
|
|
24
21
|
//["new:typescript"]: {cb: newTS, tabs: 4, description: `create a new typescript project.`},
|
|
25
22
|
["new:api:main"]: {
|
|
26
|
-
//section: "http
|
|
27
|
-
cb:
|
|
23
|
+
//section: "http scaffolding",
|
|
24
|
+
cb: newMain,
|
|
28
25
|
tabs: 3,
|
|
29
26
|
description: `creates a new main file.`
|
|
30
27
|
},
|
|
31
|
-
["new:api:route"]: { cb:
|
|
32
|
-
["new:api:route:test"]: { cb:
|
|
28
|
+
["new:api:route"]: { cb: newRoute, tabs: 3, description: `creates a new route.` },
|
|
29
|
+
["new:api:route:test"]: { cb: newTest, tabs: 2, description: `create new test.js file for an APIRouter.` },
|
|
33
30
|
["config"]: {
|
|
34
|
-
//section: "config
|
|
35
|
-
cb:
|
|
31
|
+
//section: "config management",
|
|
32
|
+
cb: config,
|
|
36
33
|
tabs: 4,
|
|
37
34
|
description: `print config as a json.`
|
|
38
35
|
},
|
|
39
36
|
["config:bash"]: {
|
|
40
|
-
cb:
|
|
37
|
+
cb: configBash,
|
|
41
38
|
tabs: 3,
|
|
42
39
|
description: `print config as a bash script.`
|
|
43
40
|
},
|
|
44
41
|
["config:env"]: {
|
|
45
|
-
cb:
|
|
42
|
+
cb: configEnv,
|
|
46
43
|
tabs: 3,
|
|
47
44
|
description: `print config as a env file.`
|
|
48
45
|
},
|
|
49
|
-
["config:init"]: { cb:
|
|
46
|
+
["config:init"]: { cb: configInit, tabs: 3, description: `inits your config folder.` },
|
|
50
47
|
["doc"]: {
|
|
51
48
|
//section: "api documentation",
|
|
52
49
|
tabs: 4,
|
|
53
|
-
cb:
|
|
50
|
+
cb: apiDocJSON,
|
|
54
51
|
description: `api folder auto doc as a json.`
|
|
55
52
|
},
|
|
56
53
|
["doc:md"]: {
|
|
57
|
-
cb:
|
|
54
|
+
cb: apiDocMD,
|
|
58
55
|
tabs: 4,
|
|
59
56
|
description: `api folder auto doc as a markdown.`
|
|
60
57
|
},
|
|
@@ -67,28 +64,28 @@ exports.CMDS = {
|
|
|
67
64
|
["start"]: {
|
|
68
65
|
//section: "start helpers",
|
|
69
66
|
tabs: 4,
|
|
70
|
-
cb:
|
|
67
|
+
cb: start,
|
|
71
68
|
description: `start script in cluster mode.`
|
|
72
69
|
},
|
|
73
70
|
["cluster"]: {
|
|
74
71
|
tabs: 4,
|
|
75
|
-
cb:
|
|
72
|
+
cb: start,
|
|
76
73
|
description: `alias for start command.`
|
|
77
74
|
},
|
|
78
75
|
["watch"]: {
|
|
79
76
|
//section: "watch",
|
|
80
|
-
cb:
|
|
77
|
+
cb: watch,
|
|
81
78
|
tabs: 4,
|
|
82
79
|
description: `watch folder for changes.`
|
|
83
80
|
},
|
|
84
81
|
["serve"]: {
|
|
85
82
|
//section: "serve static files",
|
|
86
83
|
tabs: 4,
|
|
87
|
-
cb:
|
|
84
|
+
cb: serve, description: `serve static files.`
|
|
88
85
|
},
|
|
89
86
|
["help"]: {
|
|
90
87
|
//section: "help",
|
|
91
|
-
cb:
|
|
88
|
+
cb: help,
|
|
92
89
|
tabs: 4, description: "prints this page"
|
|
93
90
|
}
|
|
94
91
|
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
exports.usage = "usage: [NODE_ENV=development] npx miqro config:bash";
|
|
6
|
-
const main = () => {
|
|
1
|
+
import { loadConfig } from "@miqro/core";
|
|
2
|
+
export const usage = "usage: [NODE_ENV=development] npx miqro config:bash";
|
|
3
|
+
export const main = () => {
|
|
7
4
|
const logger = console;
|
|
8
5
|
if (process.argv.length !== 3) {
|
|
9
|
-
throw new Error(`invalid number of args. ${
|
|
6
|
+
throw new Error(`invalid number of args. ${usage}`);
|
|
10
7
|
}
|
|
11
|
-
const configOut =
|
|
8
|
+
const configOut = loadConfig();
|
|
12
9
|
const config = configOut.combined;
|
|
13
10
|
const keys = Object.keys(config);
|
|
14
11
|
for (const key of keys) {
|
|
15
12
|
logger.info(`export ${key}=${config[key]}`);
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
exports.main = main;
|
package/build/cmds/config-env.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
exports.usage = "usage: [NODE_ENV=development] npx miqro config:env";
|
|
6
|
-
const main = () => {
|
|
1
|
+
import { loadConfig } from "@miqro/core";
|
|
2
|
+
export const usage = "usage: [NODE_ENV=development] npx miqro config:env";
|
|
3
|
+
export const main = () => {
|
|
7
4
|
const logger = console;
|
|
8
5
|
if (process.argv.length !== 3) {
|
|
9
|
-
throw new Error(`invalid number of args. ${
|
|
6
|
+
throw new Error(`invalid number of args. ${usage}`);
|
|
10
7
|
}
|
|
11
|
-
const configOut =
|
|
8
|
+
const configOut = loadConfig();
|
|
12
9
|
const config = configOut.combined;
|
|
13
10
|
const keys = Object.keys(config);
|
|
14
11
|
for (const key of keys) {
|
|
15
12
|
logger.info(`${key}=${config[key]}`);
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
exports.main = main;
|
|
@@ -1,35 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const templates_1 = require("../utils/templates");
|
|
8
|
-
exports.usage = "usage: [NODE_ENV=development] npx miqro config:init";
|
|
9
|
-
const main = () => {
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
4
|
+
import { templates } from "../utils/templates.js";
|
|
5
|
+
export const usage = "usage: [NODE_ENV=development] npx miqro config:init";
|
|
6
|
+
export const main = () => {
|
|
10
7
|
const logger = console;
|
|
11
8
|
if (process.argv.length !== 3) {
|
|
12
|
-
throw new Error(`invalid number of args. ${
|
|
9
|
+
throw new Error(`invalid number of args. ${usage}`);
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
const configPath =
|
|
11
|
+
loadConfig();
|
|
12
|
+
const configPath = ConfigPathResolver.getConfigDirname();
|
|
16
13
|
const initEnvFile = (path, template) => {
|
|
17
|
-
if (!
|
|
14
|
+
if (!existsSync(path)) {
|
|
18
15
|
logger.warn(`creating ${path} env file`);
|
|
19
|
-
|
|
16
|
+
writeFileSync(path, template);
|
|
20
17
|
}
|
|
21
18
|
else {
|
|
22
19
|
logger.warn(`${path} already exists!. init will not create it.`);
|
|
23
20
|
}
|
|
24
21
|
};
|
|
25
|
-
if (!
|
|
22
|
+
if (!existsSync(configPath)) {
|
|
26
23
|
logger.warn(`[${configPath}] doesnt exists!`);
|
|
27
|
-
|
|
24
|
+
mkdirSync(configPath, {
|
|
28
25
|
recursive: true
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
|
-
initEnvFile(
|
|
32
|
-
initEnvFile(
|
|
33
|
-
initEnvFile(
|
|
28
|
+
initEnvFile(resolve(configPath, `log.env`), templates.logEnvFile);
|
|
29
|
+
initEnvFile(resolve(configPath, `auth.env`), templates.authEnvFile);
|
|
30
|
+
initEnvFile(resolve(configPath, `features.env`), templates.featuresEnvFile);
|
|
34
31
|
};
|
|
35
|
-
exports.main = main;
|
package/build/cmds/config.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
exports.usage = "usage: [NODE_ENV=development] npx miqro config";
|
|
6
|
-
const main = () => {
|
|
1
|
+
import { loadConfig } from "@miqro/core";
|
|
2
|
+
export const usage = "usage: [NODE_ENV=development] npx miqro config";
|
|
3
|
+
export const main = () => {
|
|
7
4
|
const logger = console;
|
|
8
5
|
if (process.argv.length !== 3) {
|
|
9
|
-
throw new Error(`invalid number of args. ${
|
|
6
|
+
throw new Error(`invalid number of args. ${usage}`);
|
|
10
7
|
}
|
|
11
|
-
const configOut =
|
|
8
|
+
const configOut = loadConfig();
|
|
12
9
|
const config = configOut.combined;
|
|
13
10
|
logger.info(JSON.stringify(config, undefined, 2));
|
|
14
11
|
};
|
|
15
|
-
exports.main = main;
|
package/build/cmds/doc-json.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const json_1 = require("../utils/doc/json");
|
|
6
|
-
exports.usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
|
|
7
|
-
const main = async () => {
|
|
1
|
+
import { loadConfig } from "@miqro/core";
|
|
2
|
+
import { getDOCJSON } from "../utils/doc/json.js";
|
|
3
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
|
|
4
|
+
export const main = async () => {
|
|
8
5
|
if (process.argv.length < 5 || process.argv.length > 6) {
|
|
9
|
-
throw new Error(
|
|
6
|
+
throw new Error(usage);
|
|
10
7
|
}
|
|
11
8
|
const dirname = process.argv[3];
|
|
12
9
|
const subPath = process.argv[4];
|
|
13
10
|
const apiName = process.argv[5];
|
|
14
|
-
|
|
15
|
-
console.log(JSON.stringify(await
|
|
11
|
+
loadConfig();
|
|
12
|
+
console.log(JSON.stringify(await getDOCJSON({ dirname, subPath, apiName }), undefined, 2));
|
|
16
13
|
};
|
|
17
|
-
exports.main = main;
|
package/build/cmds/doc-md.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const md_1 = require("../utils/doc/md");
|
|
6
|
-
exports.usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
|
|
7
|
-
const main = async () => {
|
|
1
|
+
import { loadConfig } from "@miqro/core";
|
|
2
|
+
import { getMDDoc } from "../utils/doc/md.js";
|
|
3
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro doc <api_folder> <subPath> [apiName]`;
|
|
4
|
+
export const main = async () => {
|
|
8
5
|
if (process.argv.length < 5 || process.argv.length > 6) {
|
|
9
|
-
throw new Error(
|
|
6
|
+
throw new Error(usage);
|
|
10
7
|
}
|
|
11
8
|
const dirname = process.argv[3];
|
|
12
9
|
const subPath = process.argv[4];
|
|
13
10
|
const apiName = process.argv[5];
|
|
14
|
-
|
|
15
|
-
console.log(await
|
|
11
|
+
loadConfig();
|
|
12
|
+
console.log(await getMDDoc({ dirname, subPath, apiName }));
|
|
16
13
|
};
|
|
17
|
-
exports.main = main;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
1
|
+
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
7
4
|
const templates = {
|
|
8
5
|
ts: (noMethod = false) => noMethod ? `import { APIRoute } from "@miqro/core";
|
|
9
6
|
|
|
@@ -42,29 +39,28 @@ export default {
|
|
|
42
39
|
};
|
|
43
40
|
`
|
|
44
41
|
};
|
|
45
|
-
|
|
46
|
-
const main = () => {
|
|
42
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro new:api:route <identifier ex: SRC_API_V1_HEALTH>`;
|
|
43
|
+
export const main = () => {
|
|
47
44
|
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
48
|
-
throw new Error(
|
|
45
|
+
throw new Error(usage);
|
|
49
46
|
}
|
|
50
47
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
51
48
|
const split = identifier.split("_").map(s => s.trim()).filter(s => s);
|
|
52
49
|
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
53
50
|
if (dots.length > 0) {
|
|
54
|
-
throw new Error(`identifier cannot contain dots\n${
|
|
51
|
+
throw new Error(`identifier cannot contain dots\n${usage}`);
|
|
55
52
|
}
|
|
56
|
-
|
|
57
|
-
const path =
|
|
58
|
-
const ext =
|
|
53
|
+
loadConfig();
|
|
54
|
+
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
55
|
+
const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
59
56
|
const noMethod = ["post", "get", "put", "delete", "patch", "options"].indexOf(split[0].toLocaleLowerCase()) === -1;
|
|
60
|
-
const filePath =
|
|
61
|
-
if (
|
|
57
|
+
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
58
|
+
if (existsSync(filePath)) {
|
|
62
59
|
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
63
60
|
}
|
|
64
61
|
console.log(`creating ${filePath}`);
|
|
65
|
-
|
|
62
|
+
mkdirSync(path, {
|
|
66
63
|
recursive: true
|
|
67
64
|
});
|
|
68
|
-
|
|
65
|
+
writeFileSync(filePath, templates[ext](noMethod));
|
|
69
66
|
};
|
|
70
|
-
exports.main = main;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
1
|
+
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
7
4
|
const mainTemplates = {
|
|
8
5
|
ts: () => `import { APIRouter, Server, checkEnvVariables, getLogger, middleware } from "@miqro/core";
|
|
9
6
|
import { resolve } from "path";
|
|
@@ -56,10 +53,10 @@ async function main() {
|
|
|
56
53
|
main().catch(e => logger.error(e));
|
|
57
54
|
`
|
|
58
55
|
};
|
|
59
|
-
|
|
60
|
-
const main = () => {
|
|
56
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro new:api:main <identifier ex: NEW_APP>`;
|
|
57
|
+
export const main = () => {
|
|
61
58
|
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
62
|
-
throw new Error(
|
|
59
|
+
throw new Error(usage);
|
|
63
60
|
}
|
|
64
61
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
65
62
|
const split = identifier.split("_");
|
|
@@ -67,18 +64,17 @@ const main = () => {
|
|
|
67
64
|
if (dots.length > 0) {
|
|
68
65
|
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_MAIN>`);
|
|
69
66
|
}
|
|
70
|
-
|
|
71
|
-
const path =
|
|
72
|
-
const ext =
|
|
73
|
-
const filePath =
|
|
74
|
-
if (
|
|
67
|
+
loadConfig();
|
|
68
|
+
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
69
|
+
const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
70
|
+
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
71
|
+
if (existsSync(filePath)) {
|
|
75
72
|
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
76
73
|
}
|
|
77
74
|
console.log(`creating ${filePath}`);
|
|
78
|
-
|
|
75
|
+
mkdirSync(path, {
|
|
79
76
|
recursive: true
|
|
80
77
|
});
|
|
81
|
-
|
|
78
|
+
writeFileSync(filePath, mainTemplates[ext]());
|
|
82
79
|
console.log(`file ${filePath} created`);
|
|
83
80
|
};
|
|
84
|
-
exports.main = main;
|
package/build/cmds/help.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
function main() {
|
|
7
|
-
console.log((0, utils_1.getUsage)(cmd_map_1.CMDS, cmd_map_1.usage));
|
|
1
|
+
import { CMD_MAP, usage } from "../cmd-map.js";
|
|
2
|
+
import { getUsage } from "../utils/index.js";
|
|
3
|
+
export function main() {
|
|
4
|
+
console.log(getUsage(CMD_MAP, usage));
|
|
8
5
|
}
|
|
9
|
-
exports.main = main;
|
package/build/cmds/new-test.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
exports.usage = `usage: [NODE_ENV=development] npx miqro new:test <identifier ex: TEST_SOMEFILE>`;
|
|
1
|
+
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro new:test <identifier ex: TEST_SOMEFILE>`;
|
|
8
5
|
const testTemplates = {
|
|
9
6
|
js: (category) => `import { it } from "node:test";
|
|
10
7
|
import { TestHelper } from "@miqro/test-http";
|
|
@@ -22,9 +19,9 @@ it("happy path health", async () => {
|
|
|
22
19
|
});
|
|
23
20
|
`
|
|
24
21
|
};
|
|
25
|
-
const main = () => {
|
|
22
|
+
export const main = () => {
|
|
26
23
|
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
27
|
-
throw new Error(
|
|
24
|
+
throw new Error(usage);
|
|
28
25
|
}
|
|
29
26
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
30
27
|
const split = identifier.split("_");
|
|
@@ -32,17 +29,16 @@ const main = () => {
|
|
|
32
29
|
if (dots.length > 0) {
|
|
33
30
|
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: TEST_SOMETEST>`);
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
const path =
|
|
37
|
-
const filePath =
|
|
38
|
-
if (
|
|
32
|
+
loadConfig();
|
|
33
|
+
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
34
|
+
const filePath = resolve(path, `${split[0]}.test.js`);
|
|
35
|
+
if (existsSync(filePath)) {
|
|
39
36
|
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
40
37
|
}
|
|
41
38
|
console.log(`creating ${filePath}`);
|
|
42
|
-
|
|
39
|
+
mkdirSync(path, {
|
|
43
40
|
recursive: true
|
|
44
41
|
});
|
|
45
|
-
|
|
42
|
+
writeFileSync(filePath, testTemplates.js(split[0]));
|
|
46
43
|
console.log(`file ${filePath} created`);
|
|
47
44
|
};
|
|
48
|
-
exports.main = main;
|
package/build/cmds/new.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { execSync } from "../utils/index.js";
|
|
7
4
|
const gitignoreTemplate = {
|
|
8
5
|
ts: () => `node_modules/
|
|
9
6
|
dist/
|
|
@@ -52,28 +49,28 @@ const packageTemplate = {
|
|
|
52
49
|
"author": ""
|
|
53
50
|
}`
|
|
54
51
|
};
|
|
55
|
-
|
|
56
|
-
const mainTS = () => {
|
|
52
|
+
export const usageTS = `usage: npx miqro new:api <identifier ex: NEW_APP>`;
|
|
53
|
+
export const mainTS = () => {
|
|
57
54
|
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
58
|
-
throw new Error(
|
|
55
|
+
throw new Error(usageTS);
|
|
59
56
|
}
|
|
60
57
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
61
|
-
const appFolder =
|
|
62
|
-
if (
|
|
58
|
+
const appFolder = resolve(process.cwd(), identifier);
|
|
59
|
+
if (existsSync(appFolder)) {
|
|
63
60
|
throw new Error(`${appFolder} already exists!`);
|
|
64
61
|
}
|
|
65
62
|
console.log(`creating ${appFolder}`);
|
|
66
|
-
|
|
63
|
+
mkdirSync(appFolder, {
|
|
67
64
|
recursive: true
|
|
68
65
|
});
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
|
|
67
|
+
execSync(`npm install miqro --save-dev`, {
|
|
71
68
|
cwd: appFolder
|
|
72
69
|
});
|
|
73
|
-
|
|
70
|
+
execSync(`npm install @miqro/core --save`, {
|
|
74
71
|
cwd: appFolder
|
|
75
72
|
});
|
|
76
|
-
|
|
73
|
+
writeFileSync(resolve(appFolder, "tsconfig.json"), `{
|
|
77
74
|
"compileOnSave": true,
|
|
78
75
|
"compilerOptions": {
|
|
79
76
|
"lib": ["es2021"],
|
|
@@ -97,26 +94,26 @@ const mainTS = () => {
|
|
|
97
94
|
"src"
|
|
98
95
|
]
|
|
99
96
|
}`);
|
|
100
|
-
|
|
97
|
+
execSync(`npm install typescript --save-dev`, {
|
|
101
98
|
cwd: appFolder
|
|
102
99
|
});
|
|
103
|
-
|
|
100
|
+
execSync(`npm install @types/node --save-dev`, {
|
|
104
101
|
cwd: appFolder
|
|
105
102
|
});
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
|
|
104
|
+
execSync(`npm install @miqro/test-http --save-dev`, {
|
|
108
105
|
cwd: appFolder
|
|
109
106
|
});
|
|
110
|
-
|
|
107
|
+
execSync(`npx miqro new:api:main src_main`, {
|
|
111
108
|
cwd: appFolder
|
|
112
109
|
});
|
|
113
|
-
|
|
110
|
+
execSync(`npx miqro new:api:route src_api_health`, {
|
|
114
111
|
cwd: appFolder
|
|
115
112
|
});
|
|
116
|
-
|
|
113
|
+
mkdirSync(resolve(appFolder, "test"), {
|
|
117
114
|
recursive: true
|
|
118
115
|
});
|
|
119
|
-
|
|
116
|
+
execSync(`npx miqro new:api:route:test test_api_health`, {
|
|
120
117
|
cwd: appFolder
|
|
121
118
|
});
|
|
122
119
|
console.log("");
|
|
@@ -126,4 +123,3 @@ const mainTS = () => {
|
|
|
126
123
|
console.log(`npm run start`);
|
|
127
124
|
console.log("");
|
|
128
125
|
};
|
|
129
|
-
exports.mainTS = mainTS;
|
package/build/cmds/serve.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
exports.usage = `usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]`;
|
|
9
|
-
const main = async () => {
|
|
10
|
-
const flags = (0, utils_1.extractFlags)(process.argv.slice(3), {
|
|
1
|
+
import { App, loadConfig, LoggerHandler, normalizePath, Proxy, ReadBuffer, Static } from "@miqro/core";
|
|
2
|
+
import { extractFlags } from "../utils/index.js";
|
|
3
|
+
import { URL } from "url";
|
|
4
|
+
import { existsSync, statSync } from "fs";
|
|
5
|
+
export const usage = `usage: [NODE_ENV=development] npx miqro serve [directory=./] [path=/] [--index404 ./index.html] [--proxy-cert-ignore] [--port 8080] [--proxy /api=https://host/api]`;
|
|
6
|
+
export const main = async () => {
|
|
7
|
+
const flags = extractFlags(process.argv.slice(3), {
|
|
11
8
|
flags: {
|
|
12
9
|
"help": {
|
|
13
10
|
description: "get help page", hasValue: false
|
|
@@ -27,31 +24,31 @@ const main = async () => {
|
|
|
27
24
|
}
|
|
28
25
|
});
|
|
29
26
|
if (flags.flags.help !== undefined) {
|
|
30
|
-
console.log(
|
|
27
|
+
console.log(usage);
|
|
31
28
|
process.exit(102);
|
|
32
29
|
}
|
|
33
30
|
if (flags.files.length > 2) {
|
|
34
|
-
throw new Error(`invalid arguments.\n${
|
|
31
|
+
throw new Error(`invalid arguments.\n${usage}`);
|
|
35
32
|
}
|
|
36
33
|
if (flags.flags.index404 instanceof Array) {
|
|
37
|
-
throw new Error(`invalid index404!.\n${
|
|
34
|
+
throw new Error(`invalid index404!.\n${usage}`);
|
|
38
35
|
}
|
|
39
36
|
if (flags.flags.port instanceof Array) {
|
|
40
|
-
throw new Error(`invalid port!.\n${
|
|
37
|
+
throw new Error(`invalid port!.\n${usage}`);
|
|
41
38
|
}
|
|
42
39
|
let [directory, path] = flags.files;
|
|
43
40
|
path = path ? path : "/";
|
|
44
41
|
directory = directory ? directory : process.cwd();
|
|
45
|
-
|
|
42
|
+
loadConfig();
|
|
46
43
|
const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
|
|
47
44
|
if (PORT === undefined) {
|
|
48
|
-
throw new Error(`invalid port!.\n${
|
|
45
|
+
throw new Error(`invalid port!.\n${usage}`);
|
|
49
46
|
}
|
|
50
|
-
if (!
|
|
51
|
-
throw new Error(`${directory} directory not found!\n${
|
|
47
|
+
if (!existsSync(directory) || !statSync(directory).isDirectory()) {
|
|
48
|
+
throw new Error(`${directory} directory not found!\n${usage}`);
|
|
52
49
|
}
|
|
53
|
-
const app = new
|
|
54
|
-
app.use(
|
|
50
|
+
const app = new App();
|
|
51
|
+
app.use(LoggerHandler());
|
|
55
52
|
const proxyList = flags.flags.proxy instanceof Array ? flags.flags.proxy : [flags.flags.proxy];
|
|
56
53
|
for (const proxy of proxyList) {
|
|
57
54
|
if (proxy) {
|
|
@@ -59,18 +56,18 @@ const main = async () => {
|
|
|
59
56
|
if (proxySplit.length !== 2) {
|
|
60
57
|
throw new Error("proxy must be in the form. /path=proxy");
|
|
61
58
|
}
|
|
62
|
-
const proxyPath =
|
|
63
|
-
const proxyURL = new
|
|
64
|
-
proxyURL.pathname =
|
|
65
|
-
const proxyRouter =
|
|
59
|
+
const proxyPath = normalizePath(proxySplit[0]);
|
|
60
|
+
const proxyURL = new URL(proxySplit[1]);
|
|
61
|
+
proxyURL.pathname = normalizePath(proxyURL.pathname);
|
|
62
|
+
const proxyRouter = Proxy({
|
|
66
63
|
url: proxyURL.toString(), rejectUnauthorized: flags.flags["proxy-cert-ignore"] ? true : false
|
|
67
64
|
});
|
|
68
65
|
console.log("setting up proxy to %s on %s", proxyURL.toString(), proxyPath);
|
|
69
|
-
proxyRouter.use(
|
|
66
|
+
proxyRouter.use(ReadBuffer());
|
|
70
67
|
app.use(proxyRouter, proxyPath);
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
|
-
app.use(
|
|
70
|
+
app.use(Static({
|
|
74
71
|
directory,
|
|
75
72
|
list: true,
|
|
76
73
|
index404: flags.flags.index404 ? flags.flags.index404 : undefined,
|
|
@@ -79,4 +76,3 @@ const main = async () => {
|
|
|
79
76
|
await app.listen(PORT);
|
|
80
77
|
console.log("serving " + directory + " on http://localhost:%s%s", PORT, path);
|
|
81
78
|
};
|
|
82
|
-
exports.main = main;
|
package/build/cmds/start.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const usage = "usage:
|
|
1
|
+
export declare const usage = "usage: CLUSTER_COUNT=os.cpus().length [CLUSTER_AUTO_BROADCAST=true|false] [CLUSTER_DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
|
|
2
2
|
export declare const main: () => void;
|
package/build/cmds/start.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const core_1 = require("@miqro/core");
|
|
7
|
-
exports.usage = "usage: [NODE_ENV=development] CLUSTER_COUNT=os.cpus().length [DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
|
|
8
|
-
const main = () => {
|
|
1
|
+
import { execSync } from "../utils/index.js";
|
|
2
|
+
import { mainPath } from "@miqro/runner";
|
|
3
|
+
import { loadConfig } from "@miqro/core";
|
|
4
|
+
export const usage = "usage: CLUSTER_COUNT=os.cpus().length [CLUSTER_AUTO_BROADCAST=true|false] [CLUSTER_DISABLE_RESTART=true|false] npx miqro start <script> [...args]";
|
|
5
|
+
export const main = () => {
|
|
9
6
|
if (process.argv.length <= 3) {
|
|
10
|
-
throw new Error(`invalid number of args\n${
|
|
7
|
+
throw new Error(`invalid number of args\n${usage}`);
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
loadConfig();
|
|
10
|
+
execSync(`${process.argv[0]} ${mainPath()} ${process.argv.slice(3).join(" ")}`);
|
|
14
11
|
};
|
|
15
|
-
exports.main = main;
|
package/build/cmds/watch.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.main = exports.usage = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { existsSync, statSync, watch, watchFile } from "fs";
|
|
2
|
+
import { execSync } from "../utils/index.js";
|
|
6
3
|
const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro watch <directory> <cmd>`;
|
|
7
|
-
|
|
4
|
+
export const usage = usageMessage();
|
|
8
5
|
function setupWatch(directory, cmd, timeout = 1000) {
|
|
9
|
-
|
|
6
|
+
watchFile(directory, () => {
|
|
10
7
|
queueRunCMD(cmd, timeout);
|
|
11
8
|
});
|
|
12
|
-
|
|
9
|
+
watch(directory, {
|
|
13
10
|
recursive: true
|
|
14
11
|
}, () => {
|
|
15
12
|
queueRunCMD(cmd, timeout);
|
|
@@ -27,7 +24,7 @@ function queueRunCMD(cmd, timeout) {
|
|
|
27
24
|
cmdTimeout = setTimeout(() => {
|
|
28
25
|
running = true;
|
|
29
26
|
try {
|
|
30
|
-
|
|
27
|
+
execSync(cmd, {
|
|
31
28
|
cwd: process.cwd(),
|
|
32
29
|
env: process.env
|
|
33
30
|
});
|
|
@@ -38,17 +35,16 @@ function queueRunCMD(cmd, timeout) {
|
|
|
38
35
|
running = false;
|
|
39
36
|
}, timeout);
|
|
40
37
|
}
|
|
41
|
-
const main = () => {
|
|
38
|
+
export const main = () => {
|
|
42
39
|
if (process.argv.length < 5) {
|
|
43
40
|
throw new Error(usageMessage("invalid number of args"));
|
|
44
41
|
}
|
|
45
42
|
const directory = process.argv[3];
|
|
46
43
|
const cmd = process.argv.slice(4).join(" ");
|
|
47
44
|
const timeout = process.env.WATCH_TIMEOUT ? parseInt(process.env.WATCH_TIMEOUT, 10) : undefined;
|
|
48
|
-
if (!
|
|
45
|
+
if (!existsSync(directory) || !statSync(directory).isDirectory()) {
|
|
49
46
|
throw new Error(usageMessage("directory not found!"));
|
|
50
47
|
}
|
|
51
48
|
console.log(`setting up watch on ${directory} with cmd ${cmd}`);
|
|
52
49
|
setupWatch(directory, cmd, timeout);
|
|
53
50
|
};
|
|
54
|
-
exports.main = main;
|
package/build/cmds/wc-new.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const utils_1 = require("../utils");
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { execSync } from "../utils/index.js";
|
|
7
4
|
const indexHTML = {
|
|
8
5
|
js: () => `<html>` +
|
|
9
6
|
`<script type="text/javascript" src="app.bundle.min.js"></script>` +
|
|
@@ -58,22 +55,22 @@ const packageTemplate = {
|
|
|
58
55
|
"license": "ISC"
|
|
59
56
|
}`
|
|
60
57
|
};
|
|
61
|
-
|
|
62
|
-
const mainTS = () => {
|
|
58
|
+
export const usageTS = `usage: npx miqro new:front <identifier ex: NEW_APP>`;
|
|
59
|
+
export const mainTS = () => {
|
|
63
60
|
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
64
|
-
throw new Error(
|
|
61
|
+
throw new Error(usageTS);
|
|
65
62
|
}
|
|
66
63
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
67
|
-
const appFolder =
|
|
68
|
-
if (
|
|
64
|
+
const appFolder = resolve(process.cwd(), identifier);
|
|
65
|
+
if (existsSync(appFolder)) {
|
|
69
66
|
throw new Error(`${appFolder} already exists!`);
|
|
70
67
|
}
|
|
71
68
|
console.log(`creating ${appFolder}`);
|
|
72
|
-
|
|
69
|
+
mkdirSync(appFolder, {
|
|
73
70
|
recursive: true
|
|
74
71
|
});
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
|
|
73
|
+
execSync(`npm install miqro --save-dev`, {
|
|
77
74
|
cwd: appFolder
|
|
78
75
|
});
|
|
79
76
|
/*execSync(
|
|
@@ -82,7 +79,7 @@ const mainTS = () => {
|
|
|
82
79
|
cwd: appFolder
|
|
83
80
|
}
|
|
84
81
|
);*/
|
|
85
|
-
|
|
82
|
+
writeFileSync(resolve(appFolder, "tsconfig.json"), `{
|
|
86
83
|
"compileOnSave": true,
|
|
87
84
|
"compilerOptions": {
|
|
88
85
|
"lib": ["es2021", "dom"],
|
|
@@ -103,20 +100,19 @@ const mainTS = () => {
|
|
|
103
100
|
"src"
|
|
104
101
|
]
|
|
105
102
|
}`);
|
|
106
|
-
|
|
103
|
+
execSync(`npm install typescript --save-dev`, {
|
|
107
104
|
cwd: appFolder
|
|
108
105
|
});
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
|
|
107
|
+
execSync(`npm install webpack-cli --save-dev`, {
|
|
111
108
|
cwd: appFolder
|
|
112
109
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
writeFileSync(resolve(appFolder, "webpack.config.js"), webpackconfig.ts());
|
|
111
|
+
mkdirSync(resolve(appFolder, "src"));
|
|
112
|
+
mkdirSync(resolve(appFolder, "public"));
|
|
113
|
+
writeFileSync(resolve(appFolder, "public", "index.html"), indexHTML.js());
|
|
114
|
+
writeFileSync(resolve(appFolder, "src", "index" + (".tsx")), indexComponent.ts());
|
|
118
115
|
console.log(`new project created on ${appFolder}`);
|
|
119
116
|
console.log(`cd ${identifier}`);
|
|
120
117
|
console.log(`npm run start`);
|
|
121
118
|
};
|
|
122
|
-
exports.mainTS = mainTS;
|
package/build/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/index.js
CHANGED
package/build/utils/doc/json.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@miqro/core");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const getDOCJSON = async ({ dirname, subPath, apiName }, logger) => {
|
|
1
|
+
import { APIRouter, ConfigPathResolver } from "@miqro/core";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
export const getDOCJSON = async ({ dirname, subPath, apiName }, logger) => {
|
|
7
4
|
//const apiTraverse = traverseAPIRouteDir(basename(dirname).toUpperCase(), resolve(ConfigPathResolver.getBaseDirname(), dirname), subPath, undefined, logger);
|
|
8
|
-
const router = await
|
|
5
|
+
const router = await APIRouter({
|
|
9
6
|
apiName,
|
|
10
|
-
dirname:
|
|
7
|
+
dirname: resolve(ConfigPathResolver.getBaseDirname(), dirname),
|
|
11
8
|
path: subPath
|
|
12
9
|
}, logger);
|
|
13
10
|
return router.getJSONDoc();
|
|
14
11
|
};
|
|
15
|
-
exports.getDOCJSON = getDOCJSON;
|
package/build/utils/doc/md.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Logger } from "@miqro/core";
|
|
2
|
-
import { ParserArgs, ParserMode } from "@miqro/parser";
|
|
1
|
+
import { Logger, ParserMode, SchemaProperties } from "@miqro/core";
|
|
3
2
|
export declare function getMDDoc(args: {
|
|
4
3
|
showFilePath?: boolean;
|
|
5
4
|
apiName?: string;
|
|
@@ -7,12 +6,12 @@ export declare function getMDDoc(args: {
|
|
|
7
6
|
subPath: string;
|
|
8
7
|
}, logger?: Logger): Promise<string>;
|
|
9
8
|
export declare function parserToString(parser: {
|
|
10
|
-
headers?:
|
|
9
|
+
headers?: string | SchemaProperties | SchemaProperties[];
|
|
11
10
|
headersMode?: ParserMode;
|
|
12
|
-
query?:
|
|
11
|
+
query?: string | SchemaProperties | boolean | SchemaProperties[];
|
|
13
12
|
queryMode?: ParserMode;
|
|
14
|
-
params?:
|
|
13
|
+
params?: string | SchemaProperties | boolean | SchemaProperties[];
|
|
15
14
|
paramsMode?: ParserMode;
|
|
16
|
-
body?:
|
|
15
|
+
body?: string | SchemaProperties | boolean | SchemaProperties[];
|
|
17
16
|
bodyMode?: ParserMode;
|
|
18
17
|
}): string;
|
package/build/utils/doc/md.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { getDOCJSON } from "./json.js";
|
|
2
|
+
/*interface SchemaProperties {
|
|
3
|
+
[key: string]: Schema | string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
type ParserMode = "add_extra" | "no_extra" | "remove_extra"*/
|
|
7
|
+
export async function getMDDoc(args, logger) {
|
|
8
|
+
const jsonDOC = await getDOCJSON(args, logger);
|
|
7
9
|
const pathList = Object.keys(jsonDOC);
|
|
8
10
|
let outMD = "";
|
|
9
11
|
for (const path of pathList) {
|
|
@@ -35,14 +37,13 @@ async function getMDDoc(args, logger) {
|
|
|
35
37
|
}
|
|
36
38
|
return outMD;
|
|
37
39
|
}
|
|
38
|
-
exports.getMDDoc = getMDDoc;
|
|
39
40
|
function policyToString(policy) {
|
|
40
41
|
let outMD = "| groups | policy |\n";
|
|
41
42
|
outMD += "|--------|--------|\n";
|
|
42
43
|
outMD += `| ${(policy.groups instanceof Array ? policy.groups : [policy.groups]).join(",")} | ${policy.groupPolicy} |\n\n`;
|
|
43
44
|
return outMD;
|
|
44
45
|
}
|
|
45
|
-
function parserToString(parser) {
|
|
46
|
+
export function parserToString(parser) {
|
|
46
47
|
let outMD = "";
|
|
47
48
|
if (parser.params && typeof parser.params !== "boolean") {
|
|
48
49
|
outMD += `#### path params\n\n`;
|
|
@@ -62,21 +63,20 @@ function parserToString(parser) {
|
|
|
62
63
|
}
|
|
63
64
|
return outMD;
|
|
64
65
|
}
|
|
65
|
-
exports.parserToString = parserToString;
|
|
66
66
|
function parserPartToString(arg, mode) {
|
|
67
67
|
if (arg === false) {
|
|
68
68
|
return "not allowed";
|
|
69
69
|
}
|
|
70
70
|
let outMD = "";
|
|
71
71
|
let maxTabulation = 1;
|
|
72
|
-
const parsers = arg instanceof Array ? arg : [arg];
|
|
72
|
+
const parsers = arg instanceof Array ? arg : typeof arg === "string" ? [arg] : [arg];
|
|
73
73
|
for (const parser of parsers) {
|
|
74
74
|
const ret = internalParserToString(parser);
|
|
75
75
|
if (ret.maxTabulation > maxTabulation) {
|
|
76
76
|
maxTabulation = ret.maxTabulation;
|
|
77
77
|
}
|
|
78
|
-
outMD += `| | ${getTabulation(ret.maxTabulation * 2)}\n`;
|
|
79
|
-
outMD +=
|
|
78
|
+
outMD += `| name | type | description | ${getTabulation(ret.maxTabulation * 2)}\n`;
|
|
79
|
+
outMD += `|--------|-------|-------|${getTabulation(ret.maxTabulation * 2, true)}\n`;
|
|
80
80
|
outMD += `${ret.out}\n\n`;
|
|
81
81
|
}
|
|
82
82
|
return outMD;
|
|
@@ -91,22 +91,50 @@ function internalParserToString(parser, tabulation = 1) {
|
|
|
91
91
|
const attrNames = Object.keys(parser);
|
|
92
92
|
for (const name of attrNames) {
|
|
93
93
|
const p = parser[name];
|
|
94
|
+
const description = typeof p === "string" ? "" : p.description ? p.description : "";
|
|
94
95
|
if (typeof p === "string") {
|
|
95
96
|
outMD += `${getTabulation(tabulation)}${name} | ${p}|\n`;
|
|
96
97
|
}
|
|
97
|
-
else if (p.type === "
|
|
98
|
-
outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
|
|
99
|
-
const ret =
|
|
98
|
+
else if (p.type === "object") {
|
|
99
|
+
outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
|
|
100
|
+
const ret = parserBaseObjectTypeToString(p, tabulation + 1);
|
|
100
101
|
if (maxTabulation < ret.maxTabulation) {
|
|
101
102
|
maxTabulation = ret.maxTabulation;
|
|
102
103
|
}
|
|
103
104
|
outMD += `${ret.out}`;
|
|
104
105
|
}
|
|
106
|
+
else if (p.type === "dict") {
|
|
107
|
+
outMD += `${getTabulation(tabulation)}${name} | Dict\\<${p.dictType}\\>| ${description}|\n`;
|
|
108
|
+
if (p.dictType === "object") {
|
|
109
|
+
const ret = parserBaseObjectTypeToString(p, tabulation + 1);
|
|
110
|
+
if (maxTabulation < ret.maxTabulation) {
|
|
111
|
+
maxTabulation = ret.maxTabulation;
|
|
112
|
+
}
|
|
113
|
+
outMD += `${ret.out}`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (p.type === "array") {
|
|
117
|
+
outMD += `${getTabulation(tabulation)}${name} | Array\\<${p.arrayType}\\>| ${description}|\n`;
|
|
118
|
+
if (p.arrayType === "object") {
|
|
119
|
+
const ret = parserBaseObjectTypeToString(p, tabulation + 1);
|
|
120
|
+
if (maxTabulation < ret.maxTabulation) {
|
|
121
|
+
maxTabulation = ret.maxTabulation;
|
|
122
|
+
}
|
|
123
|
+
outMD += `${ret.out}`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
105
126
|
else if (p.type === "regex") {
|
|
106
|
-
outMD += `${getTabulation(tabulation)}${name} | ${p.regex}|\n`;
|
|
127
|
+
outMD += `${getTabulation(tabulation)}${name} | ${p.regex}| ${description}|\n`;
|
|
128
|
+
}
|
|
129
|
+
else if (p.type === "enum") {
|
|
130
|
+
outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
|
|
131
|
+
outMD += `${getTabulation(tabulation + 1)}| ${p.enumValues?.join(",")}|\n`;
|
|
132
|
+
if (maxTabulation < tabulation + 1) {
|
|
133
|
+
maxTabulation = tabulation + 1;
|
|
134
|
+
}
|
|
107
135
|
}
|
|
108
136
|
else {
|
|
109
|
-
outMD += `${getTabulation(tabulation)}${name} | ${p.type}|\n`;
|
|
137
|
+
outMD += `${getTabulation(tabulation)}${name} | ${p.type}| ${description}|\n`;
|
|
110
138
|
}
|
|
111
139
|
}
|
|
112
140
|
}
|
|
@@ -115,10 +143,10 @@ function internalParserToString(parser, tabulation = 1) {
|
|
|
115
143
|
maxTabulation
|
|
116
144
|
};
|
|
117
145
|
}
|
|
118
|
-
function
|
|
119
|
-
const options = arg.
|
|
146
|
+
function parserBaseObjectTypeToString(arg, tabulation) {
|
|
147
|
+
const options = arg.properties ? arg.properties : {};
|
|
120
148
|
//const outMD = `${getTabulation(tabulation)}name | type |\n${getTabulation(tabulation)}--------|--------|\n`;
|
|
121
|
-
return internalParserToString(options, tabulation);
|
|
149
|
+
return internalParserToString(options, tabulation + 1);
|
|
122
150
|
}
|
|
123
151
|
function getTabulation(n, header = false) {
|
|
124
152
|
let out = "";
|
package/build/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { ExecSyncOptionsWithBufferEncoding } from "child_process";
|
|
3
3
|
export declare const execSync: (cmd: string, options?: ExecSyncOptionsWithBufferEncoding) => void;
|
|
4
4
|
export type Callback<T = any> = (...args: any[]) => T;
|
package/build/utils/index.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.mainCMD = exports.getUsage = exports.extractFlags = exports.execSync = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const execSync = (cmd, options) => {
|
|
1
|
+
import { execSync as cpExec } from "child_process";
|
|
2
|
+
export const execSync = (cmd, options) => {
|
|
6
3
|
console.log(cmd);
|
|
7
|
-
(
|
|
4
|
+
cpExec(cmd, options ? { stdio: 'inherit', ...options } : { stdio: 'inherit' });
|
|
8
5
|
};
|
|
9
|
-
exports.execSync = execSync;
|
|
10
6
|
// noinspection SpellCheckingInspection
|
|
11
7
|
const routeCMDModule = async (cmdArg, cmds, logger, exit = true) => {
|
|
12
8
|
if (!cmdArg) {
|
|
@@ -31,7 +27,7 @@ const routeCMDModule = async (cmdArg, cmds, logger, exit = true) => {
|
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
};
|
|
34
|
-
const extractFlags = (args, options) => {
|
|
30
|
+
export const extractFlags = (args, options) => {
|
|
35
31
|
const flags = Object.create(null);
|
|
36
32
|
const files = [];
|
|
37
33
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -60,7 +56,6 @@ const extractFlags = (args, options) => {
|
|
|
60
56
|
}
|
|
61
57
|
return { flags, files };
|
|
62
58
|
};
|
|
63
|
-
exports.extractFlags = extractFlags;
|
|
64
59
|
const getTabs = (n) => {
|
|
65
60
|
n = n ? n : 1;
|
|
66
61
|
let ret = "";
|
|
@@ -69,7 +64,7 @@ const getTabs = (n) => {
|
|
|
69
64
|
}
|
|
70
65
|
return ret;
|
|
71
66
|
};
|
|
72
|
-
function getUsage(cmds, usage) {
|
|
67
|
+
export function getUsage(cmds, usage) {
|
|
73
68
|
let out = "";
|
|
74
69
|
out += `${usage}`;
|
|
75
70
|
out += `Available commands:\n\n`;
|
|
@@ -86,8 +81,7 @@ function getUsage(cmds, usage) {
|
|
|
86
81
|
out += "\n";
|
|
87
82
|
return out;
|
|
88
83
|
}
|
|
89
|
-
|
|
90
|
-
const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
|
|
84
|
+
export const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) => {
|
|
91
85
|
const flow = async () => {
|
|
92
86
|
try {
|
|
93
87
|
await routeCMDModule(cmdArg, cmds, logger, exit);
|
|
@@ -106,4 +100,3 @@ const mainCMD = (cmds, usage, logger, cmdArg = process.argv[2], exit = true) =>
|
|
|
106
100
|
logger.error(e);
|
|
107
101
|
});
|
|
108
102
|
};
|
|
109
|
-
exports.mainCMD = mainCMD;
|
package/build/utils/templates.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// noinspection SpellCheckingInspection
|
|
3
|
-
|
|
4
|
-
exports.templates = exports.authEnvFile = exports.dbEnvFile = exports.featuresEnvFile = exports.logEnvFile = void 0;
|
|
5
|
-
exports.logEnvFile = `####################
|
|
2
|
+
export const logEnvFile = `####################
|
|
6
3
|
## logging
|
|
7
4
|
LOG_LEVEL=info
|
|
8
5
|
LOG_LEVEL_Database=error
|
|
9
6
|
#LOG_FILE=./logs/dev.log
|
|
10
7
|
`;
|
|
11
|
-
|
|
8
|
+
export const featuresEnvFile = `####################
|
|
12
9
|
## features
|
|
13
10
|
#MY_CUSTOM_FEATURE=false
|
|
14
11
|
`;
|
|
15
|
-
|
|
12
|
+
export const dbEnvFile = `####################
|
|
16
13
|
## db
|
|
17
14
|
DB_URI=sqlite://user:password@localhost:3306/devdb
|
|
18
15
|
DB_POOL=false
|
|
@@ -23,7 +20,7 @@ DB_POOL_ACQUIRE=30000
|
|
|
23
20
|
DB_POOL_IDLE=10000
|
|
24
21
|
DB_STORAGE=./dev.sqlite3
|
|
25
22
|
`;
|
|
26
|
-
|
|
23
|
+
export const authEnvFile = `####################
|
|
27
24
|
## Auth
|
|
28
25
|
TOKEN_LOCATION=header
|
|
29
26
|
#TOKEN_LOCATION=query
|
|
@@ -140,13 +137,13 @@ const exampleModel = (modelName) => {
|
|
|
140
137
|
};`;
|
|
141
138
|
};
|
|
142
139
|
// noinspection SpellCheckingInspection
|
|
143
|
-
|
|
140
|
+
export const templates = {
|
|
144
141
|
modelsIndex,
|
|
145
142
|
dbConfig,
|
|
146
143
|
sequelizerc,
|
|
147
144
|
exampleModel,
|
|
148
|
-
logEnvFile
|
|
149
|
-
authEnvFile
|
|
150
|
-
dbEnvFile
|
|
151
|
-
featuresEnvFile
|
|
145
|
+
logEnvFile,
|
|
146
|
+
authEnvFile,
|
|
147
|
+
dbEnvFile,
|
|
148
|
+
featuresEnvFile
|
|
152
149
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miqro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"bin": {
|
|
8
9
|
"miqro": "build/cli.js"
|
|
9
10
|
},
|
|
@@ -18,12 +19,11 @@
|
|
|
18
19
|
"author": "claukers",
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@miqro/core": "^
|
|
22
|
-
"@miqro/parser": "^
|
|
23
|
-
"@miqro/runner": "^
|
|
22
|
+
"@miqro/core": "^4.0.1",
|
|
23
|
+
"@miqro/parser": "^2.0.1",
|
|
24
|
+
"@miqro/runner": "^2.0.1"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"@miqro/test": "^0.2.9",
|
|
27
27
|
"@types/cookie": "0.4.1",
|
|
28
28
|
"@types/node": "^20.4.5",
|
|
29
29
|
"typescript": "5.0.4"
|