miqro 1.7.5 → 1.7.6
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/dist/cli.js +2 -2
- package/dist/cmds/handler-apiroute-new.js +27 -14
- package/dist/cmds/handler-main-new.js +1 -0
- package/dist/cmds/{test.d.ts → new-test.d.ts} +0 -0
- package/dist/cmds/new-test.js +48 -0
- package/dist/cmds/new.js +29 -14
- package/dist/utils/index.js +1 -0
- package/package.json +5 -5
- package/dist/cmds/test.js +0 -15
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,6 @@ const utils_1 = require("./utils");
|
|
|
6
6
|
const start_1 = require("./cmds/start");
|
|
7
7
|
const new_1 = require("./cmds/new");
|
|
8
8
|
const new_2 = require("./cmds/new");
|
|
9
|
-
const test_1 = require("./cmds/test");
|
|
10
9
|
const doc_json_1 = require("./cmds/doc-json");
|
|
11
10
|
const doc_md_1 = require("./cmds/doc-md");
|
|
12
11
|
const config_init_1 = require("./cmds/config-init");
|
|
@@ -14,6 +13,7 @@ const config_1 = require("./cmds/config");
|
|
|
14
13
|
const config_bash_1 = require("./cmds/config-bash");
|
|
15
14
|
const config_env_1 = require("./cmds/config-env");
|
|
16
15
|
const handler_apiroute_new_1 = require("./cmds/handler-apiroute-new");
|
|
16
|
+
const new_test_1 = require("./cmds/new-test");
|
|
17
17
|
const handler_main_new_1 = require("./cmds/handler-main-new");
|
|
18
18
|
//@miqro/database
|
|
19
19
|
const db_init_1 = require("./cmds/db-init");
|
|
@@ -39,7 +39,7 @@ const db_dump_data_1 = require("./cmds/db-dump-data");
|
|
|
39
39
|
["start"]: { section: "cluster start", cb: start_1.main, description: "\t\t\t\tstart a nodejs script in cluster mode and restart if crash." },
|
|
40
40
|
["doc"]: { section: "api documentation", cb: doc_json_1.main, description: "\t\t\t\toutputs to stdout an api folder auto doc as a json" },
|
|
41
41
|
["doc:md"]: { cb: doc_md_1.main, description: "\t\t\t\toutputs to a file an api folder auto doc as a markdown" },
|
|
42
|
-
["test"]: { cb:
|
|
42
|
+
["test:new"]: { section: "testing", cb: new_test_1.main, description: "\t\t\tcreate new test.js file." },
|
|
43
43
|
["db:console"]: { section: "sequelize helpers", cb: db_console_1.main, description: "\t\t\truns a readline interface that send the input as a query" },
|
|
44
44
|
["db:dump:data"]: { cb: db_dump_data_1.main, description: "\t\t\tdump the data of the database (only defined models)" },
|
|
45
45
|
["db:push:data"]: { cb: db_push_data_1.main, description: "\t\t\tpush a dump to the database" },
|
|
@@ -5,26 +5,38 @@ const core_1 = require("@miqro/core");
|
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const templates = {
|
|
8
|
-
ts: (
|
|
8
|
+
ts: (noMethod = false) => noMethod ? `import { APIRoute } from "@miqro/core";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
handler: async (ctx: Context) => {
|
|
10
|
+
export default {
|
|
11
|
+
method: "GET",
|
|
12
|
+
handler: async (ctx) => {
|
|
14
13
|
return {
|
|
15
|
-
text: \`Hello
|
|
14
|
+
text: \`Hello\`
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
};
|
|
17
|
+
} as APIRoute;
|
|
18
|
+
` : `import { APIRoute } from "@miqro/core";
|
|
19
19
|
|
|
20
|
-
export default
|
|
20
|
+
export default {
|
|
21
|
+
handler: async (ctx) => {
|
|
22
|
+
return {
|
|
23
|
+
text: \`Hello\`
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} as APIRoute;
|
|
21
27
|
`,
|
|
22
|
-
js: (
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
js: (noMethod = false) => noMethod ? `module.exports = {
|
|
29
|
+
method: "GET
|
|
30
|
+
handler: async (ctx) => {
|
|
31
|
+
return {
|
|
32
|
+
text: \`Hello\`
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
` : `module.exports = {
|
|
25
37
|
handler: async (ctx) => {
|
|
26
38
|
return {
|
|
27
|
-
text: \`Hello
|
|
39
|
+
text: \`Hello\`
|
|
28
40
|
}
|
|
29
41
|
}
|
|
30
42
|
};
|
|
@@ -35,7 +47,7 @@ const main = () => {
|
|
|
35
47
|
throw new Error(`arguments: <identifier ex: SRC_API_V1_HEALTH>`);
|
|
36
48
|
}
|
|
37
49
|
const identifier = process.argv[3].toLocaleLowerCase();
|
|
38
|
-
const split = identifier.split("_");
|
|
50
|
+
const split = identifier.split("_").map(s => s.trim()).filter(s => s);
|
|
39
51
|
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
40
52
|
if (dots.length > 0) {
|
|
41
53
|
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_API_V1_HEALTH>`);
|
|
@@ -43,6 +55,7 @@ const main = () => {
|
|
|
43
55
|
(0, core_1.loadConfig)();
|
|
44
56
|
const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
45
57
|
const ext = (0, fs_1.existsSync)((0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
58
|
+
const noMethod = ["post", "get", "put", "delete", "patch", "options"].indexOf(split[0].toLocaleLowerCase()) === -1;
|
|
46
59
|
const filePath = (0, path_1.resolve)(path, `${split[0]}.${ext}`);
|
|
47
60
|
if ((0, fs_1.existsSync)(filePath)) {
|
|
48
61
|
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
@@ -51,6 +64,6 @@ const main = () => {
|
|
|
51
64
|
(0, fs_1.mkdirSync)(path, {
|
|
52
65
|
recursive: true
|
|
53
66
|
});
|
|
54
|
-
(0, fs_1.writeFileSync)(filePath, templates[ext](
|
|
67
|
+
(0, fs_1.writeFileSync)(filePath, templates[ext](noMethod));
|
|
55
68
|
};
|
|
56
69
|
exports.main = main;
|
|
File without changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.main = void 0;
|
|
4
|
+
const core_1 = require("@miqro/core");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const testTemplates = {
|
|
8
|
+
js: (category) => `const { it, requireMock, fake } = require("@miqro/test");
|
|
9
|
+
|
|
10
|
+
const options = {
|
|
11
|
+
category: "${category}",
|
|
12
|
+
before: async () => {
|
|
13
|
+
|
|
14
|
+
},
|
|
15
|
+
after: async () => {
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
it("happy path", async () => {
|
|
21
|
+
|
|
22
|
+
}, options)
|
|
23
|
+
`
|
|
24
|
+
};
|
|
25
|
+
const main = () => {
|
|
26
|
+
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
27
|
+
throw new Error(`arguments: <identifier ex: SRC_MAIN>`);
|
|
28
|
+
}
|
|
29
|
+
const identifier = process.argv[3].toLocaleLowerCase();
|
|
30
|
+
const split = identifier.split("_");
|
|
31
|
+
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
32
|
+
if (dots.length > 0) {
|
|
33
|
+
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: TEST_SOMETEST>`);
|
|
34
|
+
}
|
|
35
|
+
(0, core_1.loadConfig)();
|
|
36
|
+
const path = (0, path_1.resolve)(core_1.ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
37
|
+
const filePath = (0, path_1.resolve)(path, `${split[0]}.test.js`);
|
|
38
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
39
|
+
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
40
|
+
}
|
|
41
|
+
console.log(`creating ${filePath}`);
|
|
42
|
+
(0, fs_1.mkdirSync)(path, {
|
|
43
|
+
recursive: true
|
|
44
|
+
});
|
|
45
|
+
(0, fs_1.writeFileSync)(filePath, testTemplates.js(split[0]));
|
|
46
|
+
console.log(`file ${filePath} created`);
|
|
47
|
+
};
|
|
48
|
+
exports.main = main;
|
package/dist/cmds/new.js
CHANGED
|
@@ -12,8 +12,12 @@ const packageTemplate = {
|
|
|
12
12
|
"private": true,
|
|
13
13
|
"main": "dist/main.js",
|
|
14
14
|
"scripts": {
|
|
15
|
+
"prebuild": "rm -Rf dist/;",
|
|
15
16
|
"build": "tsc",
|
|
16
|
-
"
|
|
17
|
+
"prestart": "npm run build",
|
|
18
|
+
"start": "node dist/main.js",
|
|
19
|
+
"pretest": "npm run build",
|
|
20
|
+
"test": "miqro-test -r test/ -n"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
},
|
|
@@ -29,7 +33,8 @@ const packageTemplate = {
|
|
|
29
33
|
"private": true,
|
|
30
34
|
"main": "src/main.js",
|
|
31
35
|
"scripts": {
|
|
32
|
-
"start": "node src/main.js"
|
|
36
|
+
"start": "node src/main.js",
|
|
37
|
+
"test": "miqro-test -r test/ -n"
|
|
33
38
|
},
|
|
34
39
|
"devDependencies": {
|
|
35
40
|
},
|
|
@@ -63,6 +68,10 @@ const mainJS = (typescript = false) => {
|
|
|
63
68
|
(0, fs_1.writeFileSync)((0, path_1.resolve)(appFolder, "tsconfig.json"), `{
|
|
64
69
|
"compileOnSave": true,
|
|
65
70
|
"compilerOptions": {
|
|
71
|
+
"lib": ["es2021"],
|
|
72
|
+
"module": "commonjs",
|
|
73
|
+
"moduleResolution": "node",
|
|
74
|
+
"target": "es2021",
|
|
66
75
|
"strict": false,
|
|
67
76
|
"outDir": "./dist/",
|
|
68
77
|
"removeComments": true,
|
|
@@ -70,13 +79,7 @@ const mainJS = (typescript = false) => {
|
|
|
70
79
|
"preserveConstEnums": true,
|
|
71
80
|
"sourceMap": true,
|
|
72
81
|
"esModuleInterop": true,
|
|
73
|
-
"declaration": true
|
|
74
|
-
"moduleResolution": "node",
|
|
75
|
-
"module": "commonjs",
|
|
76
|
-
"target": "es2017",
|
|
77
|
-
"lib": [
|
|
78
|
-
"es2017"
|
|
79
|
-
]
|
|
82
|
+
"declaration": true
|
|
80
83
|
},
|
|
81
84
|
"exclude": [
|
|
82
85
|
"node_modules",
|
|
@@ -86,19 +89,31 @@ const mainJS = (typescript = false) => {
|
|
|
86
89
|
"src"
|
|
87
90
|
]
|
|
88
91
|
}`);
|
|
89
|
-
|
|
90
|
-
|
|
92
|
+
(0, utils_1.execSync)(`npm install typescript --save-dev`, {
|
|
93
|
+
cwd: appFolder
|
|
94
|
+
});
|
|
95
|
+
(0, utils_1.execSync)(`npm install @types/node --save-dev`, {
|
|
96
|
+
cwd: appFolder
|
|
91
97
|
});
|
|
92
|
-
execSync(`npm install @types/node --save-dev`, {
|
|
93
|
-
cwd: appFolder
|
|
94
|
-
});*/
|
|
95
98
|
}
|
|
99
|
+
(0, utils_1.execSync)(`npm install @miqro/test --save-dev`, {
|
|
100
|
+
cwd: appFolder
|
|
101
|
+
});
|
|
96
102
|
(0, utils_1.execSync)(`npx miqro new:main src_main`, {
|
|
97
103
|
cwd: appFolder
|
|
98
104
|
});
|
|
99
105
|
(0, utils_1.execSync)(`npx miqro new:route src_api_health`, {
|
|
100
106
|
cwd: appFolder
|
|
101
107
|
});
|
|
108
|
+
(0, fs_1.mkdirSync)((0, path_1.resolve)(appFolder, "test"), {
|
|
109
|
+
recursive: true
|
|
110
|
+
});
|
|
111
|
+
(0, utils_1.execSync)(`npx miqro test:new test_api_health`, {
|
|
112
|
+
cwd: appFolder
|
|
113
|
+
});
|
|
114
|
+
console.log(`new project created on ${appFolder}`);
|
|
115
|
+
console.log(`cd ${identifier}`);
|
|
116
|
+
console.log(`npm run start`);
|
|
102
117
|
};
|
|
103
118
|
exports.mainJS = mainJS;
|
|
104
119
|
const mainTS = () => (0, exports.mainJS)(true);
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "miqro",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"author": "claukers",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@miqro/core": "^1.5.
|
|
21
|
-
"@miqro/runner": "^1.2.
|
|
22
|
-
"@miqro/test": "^0.0.
|
|
20
|
+
"@miqro/core": "^1.5.3",
|
|
21
|
+
"@miqro/runner": "^1.2.4",
|
|
22
|
+
"@miqro/test": "^0.0.7",
|
|
23
23
|
"deep-diff": "1.0.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/cookie": "^0.4.1",
|
|
27
27
|
"@types/deep-diff": "1.0.1",
|
|
28
28
|
"@types/node": "^16.7.10",
|
|
29
|
-
"typescript": "^4.
|
|
29
|
+
"typescript": "^4.5.4"
|
|
30
30
|
},
|
|
31
31
|
"engines": {
|
|
32
32
|
"node": ">=14.0.0",
|
package/dist/cmds/test.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.main = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const test_1 = require("@miqro/test");
|
|
6
|
-
const core_1 = require("@miqro/core");
|
|
7
|
-
const main = () => {
|
|
8
|
-
if (process.argv.length <= 3) {
|
|
9
|
-
throw new Error(`invalid number of args\nusage: npx miqro test <test/*.test.js> [...args]`);
|
|
10
|
-
}
|
|
11
|
-
(0, core_1.loadConfig)();
|
|
12
|
-
//execSync(`npx @miqro/test ${process.argv.slice(3).join(" ")}`);
|
|
13
|
-
(0, utils_1.execSync)(`${process.argv[0]} ${(0, test_1.mainPath)()} ${process.argv.slice(3).join(" ")}`);
|
|
14
|
-
};
|
|
15
|
-
exports.main = main;
|