miqro 4.0.1 → 5.0.2
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 +340 -34
- package/build/utils/doc/json.d.ts +2 -1
- package/build/utils/doc/json.js +3 -2
- package/build/utils/doc/md.d.ts +1 -0
- 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 +7 -7
- 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
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
package/build/cmds/watch.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { existsSync, statSync, watch, watchFile } from "fs";
|
|
2
|
-
import { execSync } from "../utils/index.js";
|
|
3
|
-
const usageMessage = (message) => `${message ? `${message}.\n` : ""}usage: npx miqro watch <directory> <cmd>`;
|
|
4
|
-
export const usage = usageMessage();
|
|
5
|
-
function setupWatch(directory, cmd, timeout = 1000) {
|
|
6
|
-
watchFile(directory, () => {
|
|
7
|
-
queueRunCMD(cmd, timeout);
|
|
8
|
-
});
|
|
9
|
-
watch(directory, {
|
|
10
|
-
recursive: true
|
|
11
|
-
}, () => {
|
|
12
|
-
queueRunCMD(cmd, timeout);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
let cmdTimeout = null;
|
|
16
|
-
let running = false;
|
|
17
|
-
function queueRunCMD(cmd, timeout) {
|
|
18
|
-
if (running) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (cmdTimeout) {
|
|
22
|
-
clearTimeout(cmdTimeout);
|
|
23
|
-
}
|
|
24
|
-
cmdTimeout = setTimeout(() => {
|
|
25
|
-
running = true;
|
|
26
|
-
try {
|
|
27
|
-
execSync(cmd, {
|
|
28
|
-
cwd: process.cwd(),
|
|
29
|
-
env: process.env
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
console.error(e);
|
|
34
|
-
}
|
|
35
|
-
running = false;
|
|
36
|
-
}, timeout);
|
|
37
|
-
}
|
|
38
|
-
export const main = () => {
|
|
39
|
-
if (process.argv.length < 5) {
|
|
40
|
-
throw new Error(usageMessage("invalid number of args"));
|
|
41
|
-
}
|
|
42
|
-
const directory = process.argv[3];
|
|
43
|
-
const cmd = process.argv.slice(4).join(" ");
|
|
44
|
-
const timeout = process.env.WATCH_TIMEOUT ? parseInt(process.env.WATCH_TIMEOUT, 10) : undefined;
|
|
45
|
-
if (!existsSync(directory) || !statSync(directory).isDirectory()) {
|
|
46
|
-
throw new Error(usageMessage("directory not found!"));
|
|
47
|
-
}
|
|
48
|
-
console.log(`setting up watch on ${directory} with cmd ${cmd}`);
|
|
49
|
-
setupWatch(directory, cmd, timeout);
|
|
50
|
-
};
|
package/build/cmds/wc-new.d.ts
DELETED
package/build/cmds/wc-new.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { execSync } from "../utils/index.js";
|
|
4
|
-
const indexHTML = {
|
|
5
|
-
js: () => `<html>` +
|
|
6
|
-
`<script type="text/javascript" src="app.bundle.min.js"></script>` +
|
|
7
|
-
`<body>` +
|
|
8
|
-
`<app-component></app-component>` +
|
|
9
|
-
`</body>` +
|
|
10
|
-
`</html>`
|
|
11
|
-
};
|
|
12
|
-
const indexComponent = {
|
|
13
|
-
ts: () => `import WebComponents, {JSX, define, RenderFunctionThis} from "@miqro/web-components"\n` +
|
|
14
|
-
`\n` +
|
|
15
|
-
`define("app-component", function(this: RenderFunctionThis): JSX.Element {\n` +
|
|
16
|
-
` return (<p>Hello World!</p>);\n` +
|
|
17
|
-
`});\n`
|
|
18
|
-
};
|
|
19
|
-
const webpackconfig = {
|
|
20
|
-
ts: () => `const mode = process.env.NODE_ENV ? process.env.NODE_ENV : "development";
|
|
21
|
-
console.log("webpack mode [%s]", mode);
|
|
22
|
-
module.exports = {` +
|
|
23
|
-
` mode: "production",` +
|
|
24
|
-
` entry: "./dist/index.js",` +
|
|
25
|
-
` output: {` +
|
|
26
|
-
` path: require("path").resolve(__dirname, 'build'),` +
|
|
27
|
-
` filename: "app.bundle.min.js"` +
|
|
28
|
-
` }` +
|
|
29
|
-
`};`,
|
|
30
|
-
};
|
|
31
|
-
const gitignoreTemplate = {
|
|
32
|
-
ts: () => `node_modules/
|
|
33
|
-
dist/
|
|
34
|
-
`
|
|
35
|
-
};
|
|
36
|
-
const packageTemplate = {
|
|
37
|
-
ts: (name) => `{
|
|
38
|
-
"name": "${name}",
|
|
39
|
-
"version": "1.0.0",
|
|
40
|
-
"description": "",
|
|
41
|
-
"private": true,
|
|
42
|
-
"main": "dist/main.js",
|
|
43
|
-
"scripts": {
|
|
44
|
-
"prebuild": "rm -Rf build/; rm -Rf dist/; mkdir build && cp -R public/ build/",
|
|
45
|
-
"build": "tsc && NODE_ENV=production webpack",
|
|
46
|
-
"build:dev": "tsc && webpack",
|
|
47
|
-
"prestart": "npm run build:dev",
|
|
48
|
-
"start": "miqro serve build/ / --port 3000 & miqro watch src/ \\"npm run build:dev\\""
|
|
49
|
-
},
|
|
50
|
-
"devDependencies": {
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
},
|
|
54
|
-
"author": "",
|
|
55
|
-
"license": "ISC"
|
|
56
|
-
}`
|
|
57
|
-
};
|
|
58
|
-
export const usageTS = `usage: npx miqro new:front <identifier ex: NEW_APP>`;
|
|
59
|
-
export const mainTS = () => {
|
|
60
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
61
|
-
throw new Error(usageTS);
|
|
62
|
-
}
|
|
63
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
64
|
-
const appFolder = resolve(process.cwd(), identifier);
|
|
65
|
-
if (existsSync(appFolder)) {
|
|
66
|
-
throw new Error(`${appFolder} already exists!`);
|
|
67
|
-
}
|
|
68
|
-
console.log(`creating ${appFolder}`);
|
|
69
|
-
mkdirSync(appFolder, {
|
|
70
|
-
recursive: true
|
|
71
|
-
});
|
|
72
|
-
writeFileSync(resolve(appFolder, "package.json"), packageTemplate["ts"](identifier));
|
|
73
|
-
execSync(`npm install miqro --save-dev`, {
|
|
74
|
-
cwd: appFolder
|
|
75
|
-
});
|
|
76
|
-
/*execSync(
|
|
77
|
-
`npm install @miqro/web-components --save`,
|
|
78
|
-
{
|
|
79
|
-
cwd: appFolder
|
|
80
|
-
}
|
|
81
|
-
);*/
|
|
82
|
-
writeFileSync(resolve(appFolder, "tsconfig.json"), `{
|
|
83
|
-
"compileOnSave": true,
|
|
84
|
-
"compilerOptions": {
|
|
85
|
-
"lib": ["es2021", "dom"],
|
|
86
|
-
"module": "commonjs",
|
|
87
|
-
"moduleResolution": "node",
|
|
88
|
-
"target": "es2021",
|
|
89
|
-
"strict": false,
|
|
90
|
-
"outDir": "./dist/",
|
|
91
|
-
"jsx": "react",
|
|
92
|
-
"jsxFactory": "WebComponents.jsxFactory",
|
|
93
|
-
"jsxFragmentFactory": "WebComponents.jsxFragmentFactory"
|
|
94
|
-
},
|
|
95
|
-
"exclude": [
|
|
96
|
-
"node_modules",
|
|
97
|
-
"test"
|
|
98
|
-
],
|
|
99
|
-
"include": [
|
|
100
|
-
"src"
|
|
101
|
-
]
|
|
102
|
-
}`);
|
|
103
|
-
execSync(`npm install typescript --save-dev`, {
|
|
104
|
-
cwd: appFolder
|
|
105
|
-
});
|
|
106
|
-
writeFileSync(resolve(appFolder, ".gitignore"), gitignoreTemplate.ts());
|
|
107
|
-
execSync(`npm install webpack-cli --save-dev`, {
|
|
108
|
-
cwd: appFolder
|
|
109
|
-
});
|
|
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());
|
|
115
|
-
console.log(`new project created on ${appFolder}`);
|
|
116
|
-
console.log(`cd ${identifier}`);
|
|
117
|
-
console.log(`npm run start`);
|
|
118
|
-
};
|
|
File without changes
|