miqro 4.0.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.js +1 -1
- package/build/cmd-map.d.ts +5 -4
- package/build/cmd-map.js +338 -34
- package/build/utils/doc/md.js +1 -1
- package/build/utils/{index.d.ts → exec.d.ts} +1 -0
- package/build/utils/templates.d.ts +19 -0
- package/build/utils/templates.js +153 -0
- package/build/utils/watch.d.ts +1 -0
- package/build/utils/watch.js +35 -0
- package/package.json +8 -8
- package/build/cmds/config-bash.d.ts +0 -2
- package/build/cmds/config-bash.js +0 -14
- package/build/cmds/config-env.d.ts +0 -2
- package/build/cmds/config-env.js +0 -14
- package/build/cmds/config-init.d.ts +0 -2
- package/build/cmds/config-init.js +0 -31
- package/build/cmds/config.d.ts +0 -2
- package/build/cmds/config.js +0 -11
- package/build/cmds/doc-json.d.ts +0 -2
- package/build/cmds/doc-json.js +0 -13
- package/build/cmds/doc-md.d.ts +0 -2
- package/build/cmds/doc-md.js +0 -13
- package/build/cmds/handler-apiroute-new.d.ts +0 -2
- package/build/cmds/handler-apiroute-new.js +0 -66
- package/build/cmds/handler-main-new.d.ts +0 -2
- package/build/cmds/handler-main-new.js +0 -78
- package/build/cmds/help.d.ts +0 -1
- package/build/cmds/help.js +0 -5
- package/build/cmds/new-test.d.ts +0 -2
- package/build/cmds/new-test.js +0 -44
- package/build/cmds/new.d.ts +0 -2
- package/build/cmds/new.js +0 -125
- package/build/cmds/serve.d.ts +0 -2
- package/build/cmds/serve.js +0 -78
- package/build/cmds/start.d.ts +0 -2
- package/build/cmds/start.js +0 -11
- package/build/cmds/watch.d.ts +0 -2
- package/build/cmds/watch.js +0 -50
- package/build/cmds/wc-new.d.ts +0 -2
- package/build/cmds/wc-new.js +0 -118
- /package/build/utils/{index.js → exec.js} +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { watch, watchFile } from "fs";
|
|
3
|
+
export function setupWatch(directory, cmd, timeout = 1000) {
|
|
4
|
+
watchFile(directory, () => {
|
|
5
|
+
queueRunCMD(cmd, timeout);
|
|
6
|
+
});
|
|
7
|
+
watch(directory, {
|
|
8
|
+
recursive: true
|
|
9
|
+
}, () => {
|
|
10
|
+
queueRunCMD(cmd, timeout);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
let cmdTimeout = null;
|
|
14
|
+
let running = false;
|
|
15
|
+
function queueRunCMD(cmd, timeout) {
|
|
16
|
+
if (running) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (cmdTimeout) {
|
|
20
|
+
clearTimeout(cmdTimeout);
|
|
21
|
+
}
|
|
22
|
+
cmdTimeout = setTimeout(() => {
|
|
23
|
+
running = true;
|
|
24
|
+
try {
|
|
25
|
+
execSync(cmd, {
|
|
26
|
+
cwd: process.cwd(),
|
|
27
|
+
env: process.env
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
console.error(e);
|
|
32
|
+
}
|
|
33
|
+
running = false;
|
|
34
|
+
}, timeout);
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miqro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -9,24 +9,24 @@
|
|
|
9
9
|
"miqro": "build/cli.js"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
12
|
+
"prepare": "npm run build",
|
|
13
13
|
"prebuild": "rm -Rf build;",
|
|
14
14
|
"build": "tsc",
|
|
15
15
|
"pretest": "npm run build",
|
|
16
|
-
"test": "node --enable-source-maps --test test
|
|
17
|
-
"coverage": "node --enable-source-maps --experimental-test-coverage --test test
|
|
16
|
+
"test": "node --enable-source-maps --test test/**.test.js",
|
|
17
|
+
"coverage": "node --enable-source-maps --experimental-test-coverage --test test/**.test.js"
|
|
18
18
|
},
|
|
19
19
|
"author": "claukers",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@miqro/core": "^
|
|
23
|
-
"@miqro/parser": "^2.0.
|
|
22
|
+
"@miqro/core": "^5.0.2",
|
|
23
|
+
"@miqro/parser": "^2.0.2",
|
|
24
24
|
"@miqro/runner": "^2.0.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/cookie": "0.
|
|
27
|
+
"@types/cookie": "0.6.0",
|
|
28
28
|
"@types/node": "^20.4.5",
|
|
29
|
-
"typescript": "5.
|
|
29
|
+
"typescript": "5.3.3"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=18.0.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "@miqro/core";
|
|
2
|
-
export const usage = "usage: [NODE_ENV=development] npx miqro config:bash";
|
|
3
|
-
export const main = () => {
|
|
4
|
-
const logger = console;
|
|
5
|
-
if (process.argv.length !== 3) {
|
|
6
|
-
throw new Error(`invalid number of args. ${usage}`);
|
|
7
|
-
}
|
|
8
|
-
const configOut = loadConfig();
|
|
9
|
-
const config = configOut.combined;
|
|
10
|
-
const keys = Object.keys(config);
|
|
11
|
-
for (const key of keys) {
|
|
12
|
-
logger.info(`export ${key}=${config[key]}`);
|
|
13
|
-
}
|
|
14
|
-
};
|
package/build/cmds/config-env.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "@miqro/core";
|
|
2
|
-
export const usage = "usage: [NODE_ENV=development] npx miqro config:env";
|
|
3
|
-
export const main = () => {
|
|
4
|
-
const logger = console;
|
|
5
|
-
if (process.argv.length !== 3) {
|
|
6
|
-
throw new Error(`invalid number of args. ${usage}`);
|
|
7
|
-
}
|
|
8
|
-
const configOut = loadConfig();
|
|
9
|
-
const config = configOut.combined;
|
|
10
|
-
const keys = Object.keys(config);
|
|
11
|
-
for (const key of keys) {
|
|
12
|
-
logger.info(`${key}=${config[key]}`);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
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 = () => {
|
|
7
|
-
const logger = console;
|
|
8
|
-
if (process.argv.length !== 3) {
|
|
9
|
-
throw new Error(`invalid number of args. ${usage}`);
|
|
10
|
-
}
|
|
11
|
-
loadConfig();
|
|
12
|
-
const configPath = ConfigPathResolver.getConfigDirname();
|
|
13
|
-
const initEnvFile = (path, template) => {
|
|
14
|
-
if (!existsSync(path)) {
|
|
15
|
-
logger.warn(`creating ${path} env file`);
|
|
16
|
-
writeFileSync(path, template);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
logger.warn(`${path} already exists!. init will not create it.`);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
if (!existsSync(configPath)) {
|
|
23
|
-
logger.warn(`[${configPath}] doesnt exists!`);
|
|
24
|
-
mkdirSync(configPath, {
|
|
25
|
-
recursive: true
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
initEnvFile(resolve(configPath, `log.env`), templates.logEnvFile);
|
|
29
|
-
initEnvFile(resolve(configPath, `auth.env`), templates.authEnvFile);
|
|
30
|
-
initEnvFile(resolve(configPath, `features.env`), templates.featuresEnvFile);
|
|
31
|
-
};
|
package/build/cmds/config.d.ts
DELETED
package/build/cmds/config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { loadConfig } from "@miqro/core";
|
|
2
|
-
export const usage = "usage: [NODE_ENV=development] npx miqro config";
|
|
3
|
-
export const main = () => {
|
|
4
|
-
const logger = console;
|
|
5
|
-
if (process.argv.length !== 3) {
|
|
6
|
-
throw new Error(`invalid number of args. ${usage}`);
|
|
7
|
-
}
|
|
8
|
-
const configOut = loadConfig();
|
|
9
|
-
const config = configOut.combined;
|
|
10
|
-
logger.info(JSON.stringify(config, undefined, 2));
|
|
11
|
-
};
|
package/build/cmds/doc-json.d.ts
DELETED
package/build/cmds/doc-json.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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 () => {
|
|
5
|
-
if (process.argv.length < 5 || process.argv.length > 6) {
|
|
6
|
-
throw new Error(usage);
|
|
7
|
-
}
|
|
8
|
-
const dirname = process.argv[3];
|
|
9
|
-
const subPath = process.argv[4];
|
|
10
|
-
const apiName = process.argv[5];
|
|
11
|
-
loadConfig();
|
|
12
|
-
console.log(JSON.stringify(await getDOCJSON({ dirname, subPath, apiName }), undefined, 2));
|
|
13
|
-
};
|
package/build/cmds/doc-md.d.ts
DELETED
package/build/cmds/doc-md.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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 () => {
|
|
5
|
-
if (process.argv.length < 5 || process.argv.length > 6) {
|
|
6
|
-
throw new Error(usage);
|
|
7
|
-
}
|
|
8
|
-
const dirname = process.argv[3];
|
|
9
|
-
const subPath = process.argv[4];
|
|
10
|
-
const apiName = process.argv[5];
|
|
11
|
-
loadConfig();
|
|
12
|
-
console.log(await getMDDoc({ dirname, subPath, apiName }));
|
|
13
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
const templates = {
|
|
5
|
-
ts: (noMethod = false) => noMethod ? `import { APIRoute } from "@miqro/core";
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
method: "GET",
|
|
9
|
-
handler: async (ctx) => {
|
|
10
|
-
return {
|
|
11
|
-
text: \`Hello\`
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
} as APIRoute;
|
|
15
|
-
` : `import { APIRoute } from "@miqro/core";
|
|
16
|
-
|
|
17
|
-
export default {
|
|
18
|
-
handler: async (ctx) => {
|
|
19
|
-
return {
|
|
20
|
-
text: \`Hello\`
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
} as APIRoute;
|
|
24
|
-
`,
|
|
25
|
-
js: (noMethod = false) => noMethod ? `module.exports = {
|
|
26
|
-
method: "GET
|
|
27
|
-
handler: async (ctx) => {
|
|
28
|
-
return {
|
|
29
|
-
text: \`Hello\`
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
` : `module.exports = {
|
|
34
|
-
handler: async (ctx) => {
|
|
35
|
-
return {
|
|
36
|
-
text: \`Hello\`
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
`
|
|
41
|
-
};
|
|
42
|
-
export const usage = `usage: [NODE_ENV=development] npx miqro new:api:route <identifier ex: SRC_API_V1_HEALTH>`;
|
|
43
|
-
export const main = () => {
|
|
44
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
45
|
-
throw new Error(usage);
|
|
46
|
-
}
|
|
47
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
48
|
-
const split = identifier.split("_").map(s => s.trim()).filter(s => s);
|
|
49
|
-
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
50
|
-
if (dots.length > 0) {
|
|
51
|
-
throw new Error(`identifier cannot contain dots\n${usage}`);
|
|
52
|
-
}
|
|
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";
|
|
56
|
-
const noMethod = ["post", "get", "put", "delete", "patch", "options"].indexOf(split[0].toLocaleLowerCase()) === -1;
|
|
57
|
-
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
58
|
-
if (existsSync(filePath)) {
|
|
59
|
-
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
60
|
-
}
|
|
61
|
-
console.log(`creating ${filePath}`);
|
|
62
|
-
mkdirSync(path, {
|
|
63
|
-
recursive: true
|
|
64
|
-
});
|
|
65
|
-
writeFileSync(filePath, templates[ext](noMethod));
|
|
66
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
const mainTemplates = {
|
|
5
|
-
ts: () => `import { APIRouter, Server, checkEnvVariables, getLogger } from "@miqro/core";
|
|
6
|
-
import { resolve } from "path";
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
To be start as a main file
|
|
10
|
-
node file.js
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const [PORT] = checkEnvVariables(["PORT"], ["8080"]);
|
|
14
|
-
|
|
15
|
-
const logger = getLogger("server");
|
|
16
|
-
|
|
17
|
-
async function main() {
|
|
18
|
-
const server = new Server();
|
|
19
|
-
server.use(await APIRouter({
|
|
20
|
-
dirname: resolve("./build/api")
|
|
21
|
-
}), "/api");
|
|
22
|
-
await server.listen(PORT);
|
|
23
|
-
server.logPaths(logger);
|
|
24
|
-
logger.info("listening on " + PORT);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
main().catch(e => logger.error(e));
|
|
28
|
-
`,
|
|
29
|
-
js: () => `const { APIRouter, App, checkEnvVariables, getLogger } = require("@miqro/core");
|
|
30
|
-
const { resolve } = require("path");
|
|
31
|
-
|
|
32
|
-
/*
|
|
33
|
-
To be start as a main file
|
|
34
|
-
node file.js
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
const [PORT] = checkEnvVariables(["PORT"], ["8080"]);
|
|
38
|
-
|
|
39
|
-
const logger = getLogger("server");
|
|
40
|
-
|
|
41
|
-
async function main() {
|
|
42
|
-
const server = new App();
|
|
43
|
-
server.use(await APIRouter({
|
|
44
|
-
dirname: resolve(__dirname, "api")
|
|
45
|
-
}), "/api");
|
|
46
|
-
await server.listen(PORT);
|
|
47
|
-
server.logPaths(logger);
|
|
48
|
-
logger.info("listening on " + PORT);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
main().catch(e => logger.error(e));
|
|
52
|
-
`
|
|
53
|
-
};
|
|
54
|
-
export const usage = `usage: [NODE_ENV=development] npx miqro new:api:main <identifier ex: NEW_APP>`;
|
|
55
|
-
export const main = () => {
|
|
56
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
57
|
-
throw new Error(usage);
|
|
58
|
-
}
|
|
59
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
60
|
-
const split = identifier.split("_");
|
|
61
|
-
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
62
|
-
if (dots.length > 0) {
|
|
63
|
-
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_MAIN>`);
|
|
64
|
-
}
|
|
65
|
-
loadConfig();
|
|
66
|
-
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
67
|
-
const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
68
|
-
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
69
|
-
if (existsSync(filePath)) {
|
|
70
|
-
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
71
|
-
}
|
|
72
|
-
console.log(`creating ${filePath}`);
|
|
73
|
-
mkdirSync(path, {
|
|
74
|
-
recursive: true
|
|
75
|
-
});
|
|
76
|
-
writeFileSync(filePath, mainTemplates[ext]());
|
|
77
|
-
console.log(`file ${filePath} created`);
|
|
78
|
-
};
|
package/build/cmds/help.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function main(): void;
|
package/build/cmds/help.js
DELETED
package/build/cmds/new-test.d.ts
DELETED
package/build/cmds/new-test.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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>`;
|
|
5
|
-
const testTemplates = {
|
|
6
|
-
js: (category) => `import { it } from "node:test";
|
|
7
|
-
import { TestHelper } from "@miqro/test-http";
|
|
8
|
-
import { Server, APIRouter } from "@miqro/core";
|
|
9
|
-
import { resolve } from "path";
|
|
10
|
-
import { strictEqual } from "assert";
|
|
11
|
-
|
|
12
|
-
it("happy path health", async () => {
|
|
13
|
-
const response = await TestHelper(new Server().use(await APIRouter({
|
|
14
|
-
dirname: resolve("./build/api")
|
|
15
|
-
})), {
|
|
16
|
-
url: "/health"
|
|
17
|
-
});
|
|
18
|
-
strictEqual(response.status, 200);
|
|
19
|
-
});
|
|
20
|
-
`
|
|
21
|
-
};
|
|
22
|
-
export const main = () => {
|
|
23
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
24
|
-
throw new Error(usage);
|
|
25
|
-
}
|
|
26
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
27
|
-
const split = identifier.split("_");
|
|
28
|
-
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
29
|
-
if (dots.length > 0) {
|
|
30
|
-
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: TEST_SOMETEST>`);
|
|
31
|
-
}
|
|
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)) {
|
|
36
|
-
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
37
|
-
}
|
|
38
|
-
console.log(`creating ${filePath}`);
|
|
39
|
-
mkdirSync(path, {
|
|
40
|
-
recursive: true
|
|
41
|
-
});
|
|
42
|
-
writeFileSync(filePath, testTemplates.js(split[0]));
|
|
43
|
-
console.log(`file ${filePath} created`);
|
|
44
|
-
};
|
package/build/cmds/new.d.ts
DELETED
package/build/cmds/new.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { execSync } from "../utils/index.js";
|
|
4
|
-
const gitignoreTemplate = {
|
|
5
|
-
ts: () => `node_modules/
|
|
6
|
-
dist/
|
|
7
|
-
`,
|
|
8
|
-
js: () => `node_modules/`
|
|
9
|
-
};
|
|
10
|
-
const packageTemplate = {
|
|
11
|
-
ts: (name) => `{
|
|
12
|
-
"name": "${name}",
|
|
13
|
-
"type": "module",
|
|
14
|
-
"version": "1.0.0",
|
|
15
|
-
"description": "",
|
|
16
|
-
"private": true,
|
|
17
|
-
"scripts": {
|
|
18
|
-
"prebuild": "rm -Rf build/;",
|
|
19
|
-
"build": "tsc",
|
|
20
|
-
"prestart": "npm run build",
|
|
21
|
-
"start": "node --enable-source-maps build/main.js",
|
|
22
|
-
"cluster": "NODE_OPTIONS=--enable-source-maps miqro cluster build/main.js",
|
|
23
|
-
"pretest": "npm run build",
|
|
24
|
-
"test": "node --enable-source-maps --test test/",
|
|
25
|
-
"coverage": "node --enable-source-maps --experimental-test-coverage --test test/"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
},
|
|
31
|
-
"author": ""
|
|
32
|
-
}`,
|
|
33
|
-
js: (name) => `{
|
|
34
|
-
"name": "${name}",
|
|
35
|
-
"type": "module",
|
|
36
|
-
"version": "1.0.0",
|
|
37
|
-
"description": "",
|
|
38
|
-
"private": true,
|
|
39
|
-
"scripts": {
|
|
40
|
-
"start": "node src/main.js",
|
|
41
|
-
"cluster": "miqro cluster src/main.js",
|
|
42
|
-
"test": "node --test test/",
|
|
43
|
-
"coverage": "node --experimental-test-coverage --test test/"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
},
|
|
47
|
-
"dependencies": {
|
|
48
|
-
},
|
|
49
|
-
"author": ""
|
|
50
|
-
}`
|
|
51
|
-
};
|
|
52
|
-
export const usageTS = `usage: npx miqro new:api <identifier ex: NEW_APP>`;
|
|
53
|
-
export const mainTS = () => {
|
|
54
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
55
|
-
throw new Error(usageTS);
|
|
56
|
-
}
|
|
57
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
58
|
-
const appFolder = resolve(process.cwd(), identifier);
|
|
59
|
-
if (existsSync(appFolder)) {
|
|
60
|
-
throw new Error(`${appFolder} already exists!`);
|
|
61
|
-
}
|
|
62
|
-
console.log(`creating ${appFolder}`);
|
|
63
|
-
mkdirSync(appFolder, {
|
|
64
|
-
recursive: true
|
|
65
|
-
});
|
|
66
|
-
writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
|
|
67
|
-
execSync(`npm install miqro --save-dev`, {
|
|
68
|
-
cwd: appFolder
|
|
69
|
-
});
|
|
70
|
-
execSync(`npm install @miqro/core --save`, {
|
|
71
|
-
cwd: appFolder
|
|
72
|
-
});
|
|
73
|
-
writeFileSync(resolve(appFolder, "tsconfig.json"), `{
|
|
74
|
-
"compileOnSave": true,
|
|
75
|
-
"compilerOptions": {
|
|
76
|
-
"lib": ["es2021"],
|
|
77
|
-
"module": "Node16",
|
|
78
|
-
"moduleResolution": "Node16",
|
|
79
|
-
"target": "es2021",
|
|
80
|
-
"strict": false,
|
|
81
|
-
"outDir": "./build/",
|
|
82
|
-
"removeComments": true,
|
|
83
|
-
"noImplicitAny": false,
|
|
84
|
-
"preserveConstEnums": true,
|
|
85
|
-
"sourceMap": true,
|
|
86
|
-
"esModuleInterop": true,
|
|
87
|
-
"declaration": true
|
|
88
|
-
},
|
|
89
|
-
"exclude": [
|
|
90
|
-
"node_modules",
|
|
91
|
-
"test"
|
|
92
|
-
],
|
|
93
|
-
"include": [
|
|
94
|
-
"src"
|
|
95
|
-
]
|
|
96
|
-
}`);
|
|
97
|
-
execSync(`npm install typescript --save-dev`, {
|
|
98
|
-
cwd: appFolder
|
|
99
|
-
});
|
|
100
|
-
execSync(`npm install @types/node --save-dev`, {
|
|
101
|
-
cwd: appFolder
|
|
102
|
-
});
|
|
103
|
-
writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
|
|
104
|
-
execSync(`npm install @miqro/test-http --save-dev`, {
|
|
105
|
-
cwd: appFolder
|
|
106
|
-
});
|
|
107
|
-
execSync(`npx miqro new:api:main src_main`, {
|
|
108
|
-
cwd: appFolder
|
|
109
|
-
});
|
|
110
|
-
execSync(`npx miqro new:api:route src_api_health`, {
|
|
111
|
-
cwd: appFolder
|
|
112
|
-
});
|
|
113
|
-
mkdirSync(resolve(appFolder, "test"), {
|
|
114
|
-
recursive: true
|
|
115
|
-
});
|
|
116
|
-
execSync(`npx miqro new:api:route:test test_api_health`, {
|
|
117
|
-
cwd: appFolder
|
|
118
|
-
});
|
|
119
|
-
console.log("");
|
|
120
|
-
console.log("");
|
|
121
|
-
console.log(`new project created on ${appFolder}`);
|
|
122
|
-
console.log(`cd ${identifier}`);
|
|
123
|
-
console.log(`npm run start`);
|
|
124
|
-
console.log("");
|
|
125
|
-
};
|
package/build/cmds/serve.d.ts
DELETED
package/build/cmds/serve.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
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), {
|
|
8
|
-
flags: {
|
|
9
|
-
"help": {
|
|
10
|
-
description: "get help page", hasValue: false
|
|
11
|
-
},
|
|
12
|
-
"index404Status": {
|
|
13
|
-
description: "status to handle index404 status", hasValue: true
|
|
14
|
-
},
|
|
15
|
-
"index404": {
|
|
16
|
-
description: "file to handle 404", hasValue: true
|
|
17
|
-
}, "proxy": {
|
|
18
|
-
description: "proxy", hasValue: true
|
|
19
|
-
}, "proxy-cert-ignore": {
|
|
20
|
-
description: "proxy ignore certs", hasValue: false
|
|
21
|
-
}, "port": {
|
|
22
|
-
description: "port", hasValue: true
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
if (flags.flags.help !== undefined) {
|
|
27
|
-
console.log(usage);
|
|
28
|
-
process.exit(102);
|
|
29
|
-
}
|
|
30
|
-
if (flags.files.length > 2) {
|
|
31
|
-
throw new Error(`invalid arguments.\n${usage}`);
|
|
32
|
-
}
|
|
33
|
-
if (flags.flags.index404 instanceof Array) {
|
|
34
|
-
throw new Error(`invalid index404!.\n${usage}`);
|
|
35
|
-
}
|
|
36
|
-
if (flags.flags.port instanceof Array) {
|
|
37
|
-
throw new Error(`invalid port!.\n${usage}`);
|
|
38
|
-
}
|
|
39
|
-
let [directory, path] = flags.files;
|
|
40
|
-
path = path ? path : "/";
|
|
41
|
-
directory = directory ? directory : process.cwd();
|
|
42
|
-
loadConfig();
|
|
43
|
-
const PORT = flags.flags.port ? flags.flags.port : (process.env.PORT ? process.env.PORT : 8080);
|
|
44
|
-
if (PORT === undefined) {
|
|
45
|
-
throw new Error(`invalid port!.\n${usage}`);
|
|
46
|
-
}
|
|
47
|
-
if (!existsSync(directory) || !statSync(directory).isDirectory()) {
|
|
48
|
-
throw new Error(`${directory} directory not found!\n${usage}`);
|
|
49
|
-
}
|
|
50
|
-
const app = new App();
|
|
51
|
-
app.use(LoggerHandler());
|
|
52
|
-
const proxyList = flags.flags.proxy instanceof Array ? flags.flags.proxy : [flags.flags.proxy];
|
|
53
|
-
for (const proxy of proxyList) {
|
|
54
|
-
if (proxy) {
|
|
55
|
-
const proxySplit = proxy.split("=");
|
|
56
|
-
if (proxySplit.length !== 2) {
|
|
57
|
-
throw new Error("proxy must be in the form. /path=proxy");
|
|
58
|
-
}
|
|
59
|
-
const proxyPath = normalizePath(proxySplit[0]);
|
|
60
|
-
const proxyURL = new URL(proxySplit[1]);
|
|
61
|
-
proxyURL.pathname = normalizePath(proxyURL.pathname);
|
|
62
|
-
const proxyRouter = Proxy({
|
|
63
|
-
url: proxyURL.toString(), rejectUnauthorized: flags.flags["proxy-cert-ignore"] ? true : false
|
|
64
|
-
});
|
|
65
|
-
console.log("setting up proxy to %s on %s", proxyURL.toString(), proxyPath);
|
|
66
|
-
proxyRouter.use(ReadBuffer());
|
|
67
|
-
app.use(proxyRouter, proxyPath);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
app.use(Static({
|
|
71
|
-
directory,
|
|
72
|
-
list: true,
|
|
73
|
-
index404: flags.flags.index404 ? flags.flags.index404 : undefined,
|
|
74
|
-
index404Status: flags.flags.index404Status ? parseInt(flags.flags.index404Status, 10) : undefined
|
|
75
|
-
}), path);
|
|
76
|
-
await app.listen(PORT);
|
|
77
|
-
console.log("serving " + directory + " on http://localhost:%s%s", PORT, path);
|
|
78
|
-
};
|
package/build/cmds/start.d.ts
DELETED
package/build/cmds/start.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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 = () => {
|
|
6
|
-
if (process.argv.length <= 3) {
|
|
7
|
-
throw new Error(`invalid number of args\n${usage}`);
|
|
8
|
-
}
|
|
9
|
-
loadConfig();
|
|
10
|
-
execSync(`${process.argv[0]} ${mainPath()} ${process.argv.slice(3).join(" ")}`);
|
|
11
|
-
};
|
package/build/cmds/watch.d.ts
DELETED