miqro 1.6.9 → 1.7.4
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/README.md +1 -11
- package/dist/cli.js +2 -3
- package/dist/cmds/config-bash.js +0 -1
- package/dist/cmds/config-env.js +0 -1
- package/dist/cmds/config-init.js +0 -1
- package/dist/cmds/config.js +0 -1
- package/dist/cmds/db-console.js +0 -1
- package/dist/cmds/db-createmodel.js +0 -1
- package/dist/cmds/db-dump-data.js +0 -1
- package/dist/cmds/db-init.js +0 -1
- package/dist/cmds/db-makemigrations.js +0 -1
- package/dist/cmds/db-push-data.js +0 -1
- package/dist/cmds/db-sync-makemigrations.js +0 -1
- package/dist/cmds/doc-json.js +0 -1
- package/dist/cmds/doc-md.js +0 -1
- package/dist/cmds/handler-apiroute-new.js +0 -1
- package/dist/cmds/handler-main-new.js +0 -1
- package/dist/cmds/new.js +0 -1
- package/dist/cmds/start.js +0 -1
- package/dist/cmds/test.d.ts +1 -1
- package/dist/cmds/test.js +8 -29
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -13
- package/dist/utils/db/automigrations/index.js +14 -18
- package/dist/utils/db/automigrations/migrate.js +6 -10
- package/dist/utils/db/index.js +0 -1
- package/dist/utils/doc/index.d.ts +1 -1
- package/dist/utils/doc/index.js +1 -2
- package/dist/utils/index.d.ts +26 -2
- package/dist/utils/index.js +84 -7
- package/dist/utils/templates.js +0 -1
- package/package.json +9 -9
- package/dist/cli.js.map +0 -1
- package/dist/cmds/config-bash.js.map +0 -1
- package/dist/cmds/config-env.js.map +0 -1
- package/dist/cmds/config-init.js.map +0 -1
- package/dist/cmds/config.js.map +0 -1
- package/dist/cmds/db-console.js.map +0 -1
- package/dist/cmds/db-createmodel.js.map +0 -1
- package/dist/cmds/db-dump-data.js.map +0 -1
- package/dist/cmds/db-init.js.map +0 -1
- package/dist/cmds/db-makemigrations.js.map +0 -1
- package/dist/cmds/db-push-data.js.map +0 -1
- package/dist/cmds/db-sync-makemigrations.js.map +0 -1
- package/dist/cmds/doc-json.js.map +0 -1
- package/dist/cmds/doc-md.js.map +0 -1
- package/dist/cmds/handler-apiroute-new.js.map +0 -1
- package/dist/cmds/handler-main-new.js.map +0 -1
- package/dist/cmds/new.js.map +0 -1
- package/dist/cmds/start.js.map +0 -1
- package/dist/cmds/test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/test/common/app.d.ts +0 -5
- package/dist/test/common/app.js +0 -51
- package/dist/test/common/app.js.map +0 -1
- package/dist/test/common/common.d.ts +0 -6
- package/dist/test/common/common.js +0 -15
- package/dist/test/common/common.js.map +0 -1
- package/dist/test/common/index.d.ts +0 -3
- package/dist/test/common/index.js +0 -16
- package/dist/test/common/index.js.map +0 -1
- package/dist/test/common/runner.d.ts +0 -34
- package/dist/test/common/runner.js +0 -88
- package/dist/test/common/runner.js.map +0 -1
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -14
- package/dist/test/index.js.map +0 -1
- package/dist/utils/db/automigrations/deep-diff/index.d.ts +0 -24
- package/dist/utils/db/automigrations/deep-diff/index.js +0 -240
- package/dist/utils/db/automigrations/deep-diff/index.js.map +0 -1
- package/dist/utils/db/automigrations/index.js.map +0 -1
- package/dist/utils/db/automigrations/migrate.js.map +0 -1
- package/dist/utils/db/index.js.map +0 -1
- package/dist/utils/doc/index.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/templates.js.map +0 -1
- package/src/cli.ts +0 -62
- package/src/cmds/config-bash.ts +0 -18
- package/src/cmds/config-env.ts +0 -18
- package/src/cmds/config-init.ts +0 -35
- package/src/cmds/config.ts +0 -16
- package/src/cmds/db-console.ts +0 -35
- package/src/cmds/db-createmodel.ts +0 -44
- package/src/cmds/db-dump-data.ts +0 -44
- package/src/cmds/db-init.ts +0 -42
- package/src/cmds/db-makemigrations.ts +0 -12
- package/src/cmds/db-push-data.ts +0 -77
- package/src/cmds/db-sync-makemigrations.ts +0 -12
- package/src/cmds/doc-json.ts +0 -16
- package/src/cmds/doc-md.ts +0 -241
- package/src/cmds/handler-apiroute-new.ts +0 -67
- package/src/cmds/handler-main-new.ts +0 -85
- package/src/cmds/new.ts +0 -128
- package/src/cmds/start.ts +0 -16
- package/src/cmds/test.ts +0 -45
- package/src/index.ts +0 -1
- package/src/test/common/app.ts +0 -47
- package/src/test/common/common.ts +0 -17
- package/src/test/common/index.ts +0 -3
- package/src/test/common/runner.ts +0 -121
- package/src/test/index.ts +0 -1
- package/src/utils/db/automigrations/deep-diff/index.ts +0 -264
- package/src/utils/db/automigrations/index.ts +0 -151
- package/src/utils/db/automigrations/migrate.ts +0 -888
- package/src/utils/db/index.ts +0 -128
- package/src/utils/doc/index.ts +0 -36
- package/src/utils/index.ts +0 -9
- package/src/utils/templates.ts +0 -189
- package/tsconfig.json +0 -32
package/src/cmds/doc-md.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import { ConfigPathResolver, getLogger, GroupPolicy, loadConfig, Method, ParseOption, ParseOptionMap } from "@miqro/core";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { writeFileSync } from "fs";
|
|
4
|
-
|
|
5
|
-
import { getDOCJSON } from "../utils/doc";
|
|
6
|
-
|
|
7
|
-
export const main = (): void => {
|
|
8
|
-
|
|
9
|
-
if (process.argv.length !== 6) {
|
|
10
|
-
throw new Error(`arguments: <api_folder> <subPath> <out.md>`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const dirname = process.argv[3];
|
|
14
|
-
const subPath = process.argv[4];
|
|
15
|
-
const outPath = process.argv[5];
|
|
16
|
-
|
|
17
|
-
loadConfig();
|
|
18
|
-
|
|
19
|
-
const parseOptionMap2ParseOptionList = (map: ParseOptionMap): ParseOption[] => {
|
|
20
|
-
return Object.keys(map).map(name => {
|
|
21
|
-
const val = map[name];
|
|
22
|
-
return typeof val !== "object" ? {
|
|
23
|
-
name,
|
|
24
|
-
required: true,
|
|
25
|
-
type: val
|
|
26
|
-
} : val.required === undefined ? {
|
|
27
|
-
...val,
|
|
28
|
-
required: true,
|
|
29
|
-
name
|
|
30
|
-
} : {
|
|
31
|
-
...val,
|
|
32
|
-
name
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const docJSON = getDOCJSON({ dirname, subPath }, getLogger("miqro"));
|
|
38
|
-
|
|
39
|
-
const policyTable = (policy: GroupPolicy | undefined | false): string => {
|
|
40
|
-
if (policy) {
|
|
41
|
-
return `|policy|groups|\n|----|----|\n|${policy.groupPolicy}|${policy.groups.join(", ")}|`;
|
|
42
|
-
} else {
|
|
43
|
-
return "";
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const methodUrlTable = (options?: { path?: string | string[]; method?: Method | Method[] }): string => {
|
|
49
|
-
if (options && options.path) {
|
|
50
|
-
const rows: string[] = [];
|
|
51
|
-
const paths = (options.path as any) instanceof Array ? options.path : [options.path];
|
|
52
|
-
for (const p of paths) {
|
|
53
|
-
if (options.method instanceof Array) {
|
|
54
|
-
for (const m of options.method) {
|
|
55
|
-
rows.push(`|${m}|${p}|`);
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
rows.push(`|${options.method}|${p}|`);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return `|method|path|\n|----|----|\n${rows.join("\n")}`;
|
|
62
|
-
} else {
|
|
63
|
-
return "";
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const getRange = (o: ParseOption, t: string): string => {
|
|
68
|
-
let range = " ";
|
|
69
|
-
switch (t) {
|
|
70
|
-
case "string":
|
|
71
|
-
if (o.stringMinLength !== undefined || o.stringMaxLength !== undefined) {
|
|
72
|
-
range = "";
|
|
73
|
-
}
|
|
74
|
-
if (o.stringMinLength !== undefined) {
|
|
75
|
-
range = `${o.stringMinLength}:`;
|
|
76
|
-
}
|
|
77
|
-
if (o.stringMaxLength !== undefined) {
|
|
78
|
-
range += `:${o.stringMaxLength}`;
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
case "number":
|
|
82
|
-
if (o.numberMin !== undefined || o.numberMax !== undefined) {
|
|
83
|
-
range = "";
|
|
84
|
-
}
|
|
85
|
-
if (o.numberMin !== undefined) {
|
|
86
|
-
range = `${o.numberMin}:`;
|
|
87
|
-
}
|
|
88
|
-
if (o.numberMax !== undefined) {
|
|
89
|
-
range += `:${o.numberMax}`;
|
|
90
|
-
}
|
|
91
|
-
if (o.numberMinDecimals !== undefined) {
|
|
92
|
-
range = `${range ? " " : ""}decimal ${o.numberMinDecimals}:`;
|
|
93
|
-
}
|
|
94
|
-
if (o.numberMaxDecimals !== undefined) {
|
|
95
|
-
range += `${range ? " " : ""}${o.numberMinDecimals !== undefined ? "" : "decimal "}:${o.numberMaxDecimals}`;
|
|
96
|
-
}
|
|
97
|
-
break;
|
|
98
|
-
case "array":
|
|
99
|
-
if (o.arrayMinLength !== undefined || o.arrayMaxLength !== undefined) {
|
|
100
|
-
range = "";
|
|
101
|
-
}
|
|
102
|
-
if (o.arrayMinLength !== undefined) {
|
|
103
|
-
range = `${o.arrayMinLength}:`;
|
|
104
|
-
}
|
|
105
|
-
if (o.arrayMaxLength !== undefined) {
|
|
106
|
-
range += `:${o.arrayMaxLength}`;
|
|
107
|
-
}
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
|
-
return range;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const parseOptionTable = (options: { options: ParseOption[] | ParseOptionMap; } | false | undefined, subName = "", tableHeaders = 0): string => {
|
|
114
|
-
if (options) {
|
|
115
|
-
let padding = "";
|
|
116
|
-
for (let i = 0; i < tableHeaders; i++) {
|
|
117
|
-
padding += "| ";
|
|
118
|
-
}
|
|
119
|
-
const hl = "|----|----|----|----|----|----|----|----|----|----|";
|
|
120
|
-
const list: ParseOption[] = options.options instanceof Array ? options.options : parseOptionMap2ParseOptionList(options.options);
|
|
121
|
-
const headers = `|**name**|**description**|**type**|**arrayRange**|**arrayType**|**range**|**values**|**defaultValue**|**required**|**allowNull**|`;
|
|
122
|
-
return `${tableHeaders >= 0 ? `${padding}${headers}\n${tableHeaders === 0 ? `${padding}${hl}\n` : ""}` : ""}${list.map(o => {
|
|
123
|
-
const arrayRange = o.type === "array" ? getRange(o, o.type) : " ";
|
|
124
|
-
const range = o.type === "array" ? (o.arrayType ? getRange(o, o.arrayType) : " ") : getRange(o, o.type);
|
|
125
|
-
let out = `${padding}|${subName}${o.name}|${o.description ? o.description : " "}|${o.type}|${arrayRange}|${o.arrayType ? o.arrayType : " "}|` +
|
|
126
|
-
`${range}|` +
|
|
127
|
-
`${o.enumValues ? o.enumValues.join(", ") : " "}|${o.defaultValue !== undefined ? o.defaultValue : " "}|${o.required === undefined ? true : o.required}|${o.allowNull ? "true" : "false"}|`;
|
|
128
|
-
if (o.type === "multiple" || o.arrayType === "multiple") {
|
|
129
|
-
out += `\n${(o.multipleOptions ? o.multipleOptions : []).map(oM => {
|
|
130
|
-
return parseOptionTable({
|
|
131
|
-
options: [{
|
|
132
|
-
name: o.name,
|
|
133
|
-
...oM
|
|
134
|
-
}]
|
|
135
|
-
}, "", tableHeaders ? tableHeaders + 1 : 1)
|
|
136
|
-
})}`;
|
|
137
|
-
return out;
|
|
138
|
-
} else if (o.type === "nested" || o.arrayType === "nested") {
|
|
139
|
-
out += `\n${parseOptionTable({ options: o.nestedOptions ? o.nestedOptions.options : [] }, `${subName}${o.name}${o.type === "array" ? "[..]" : ""}.`, tableHeaders ? tableHeaders + 1 : 1)}`;
|
|
140
|
-
return out;
|
|
141
|
-
} else {
|
|
142
|
-
return out;
|
|
143
|
-
}
|
|
144
|
-
}).join("\n")}`;
|
|
145
|
-
} else if (options === false) {
|
|
146
|
-
return "";
|
|
147
|
-
} else {
|
|
148
|
-
return "";
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const FAKE_TAB = " ";
|
|
153
|
-
const FAKE_DOUBLE_TAB = `${FAKE_TAB}${FAKE_TAB}`;
|
|
154
|
-
|
|
155
|
-
const featureIndex = `${docJSON.map(doc => {
|
|
156
|
-
return `- [${doc.featureName}](#${doc.featureName.toLowerCase()})\n\n${doc.description ? `${FAKE_TAB}${doc.description}\n\n` : ""}${FAKE_DOUBLE_TAB}${doc.path}`;
|
|
157
|
-
}).join("\n\n")}`;
|
|
158
|
-
|
|
159
|
-
writeFileSync(resolve(ConfigPathResolver.getBaseDirname(), outPath), `${featureIndex}\n\n` + docJSON.map(doc => {
|
|
160
|
-
const param = doc.params instanceof Array ? doc.params : [doc.params];
|
|
161
|
-
const paramsTable = [];
|
|
162
|
-
for (const q of param) {
|
|
163
|
-
let paramTable = parseOptionTable(q);
|
|
164
|
-
// let paramsTable = parseOptionTable(doc.params);
|
|
165
|
-
if (paramTable.split("\n").length > 1) {
|
|
166
|
-
paramTable = `### params${q && q.description ? ` (${q.description})` : ""}\n\n${paramTable}`;
|
|
167
|
-
} else {
|
|
168
|
-
paramTable = paramTable === "" ? "" : `### params${q && q.description ? ` (${q.description})` : ""}: ${paramTable}`;
|
|
169
|
-
}
|
|
170
|
-
if (paramTable !== "") {
|
|
171
|
-
paramsTable.push(paramTable);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const query = doc.query instanceof Array ? doc.query : [doc.query];
|
|
176
|
-
const queryTables = [];
|
|
177
|
-
for (const q of query) {
|
|
178
|
-
let queryTable = parseOptionTable(q);
|
|
179
|
-
// let paramsTable = parseOptionTable(doc.params);
|
|
180
|
-
if (queryTable.split("\n").length > 1) {
|
|
181
|
-
queryTable = `### query${q && q.description ? ` (${q.description})` : ""}\n\n${queryTable}`;
|
|
182
|
-
} else {
|
|
183
|
-
queryTable = queryTable === "" ? "" : `### query${q && q.description ? ` (${q.description})` : ""}: ${queryTable}`;
|
|
184
|
-
}
|
|
185
|
-
if (queryTable !== "") {
|
|
186
|
-
queryTables.push(queryTable);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
/*if (paramsTable.split("\n").length > 1) {
|
|
190
|
-
paramsTable = `- params\n\n${paramsTable}`;
|
|
191
|
-
} else {
|
|
192
|
-
paramsTable = paramsTable === "" ? "" : `- params: ${paramsTable}`;
|
|
193
|
-
}*/
|
|
194
|
-
|
|
195
|
-
const body = doc.body instanceof Array ? doc.body : [doc.body];
|
|
196
|
-
const bodyTables = [];
|
|
197
|
-
for (const b of body) {
|
|
198
|
-
let bodyTable = parseOptionTable(b);
|
|
199
|
-
|
|
200
|
-
if (bodyTable.split("\n").length > 1) {
|
|
201
|
-
bodyTable = `### body${b && b.description ? ` (${b.description})` : ""}\n\n${bodyTable}`;
|
|
202
|
-
} else {
|
|
203
|
-
bodyTable = bodyTable === "" ? "" : `### body${b && b.description ? ` (${b.description})` : ""}: ${bodyTable}`;
|
|
204
|
-
}
|
|
205
|
-
if (bodyTable !== "") {
|
|
206
|
-
bodyTables.push(bodyTable);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const results = doc.result instanceof Array ? doc.result : [doc.result];
|
|
211
|
-
const resultTables = [];
|
|
212
|
-
for (const r of results) {
|
|
213
|
-
if (!r) {
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
let resultsTable = doc.result ? parseOptionTable(r) : "";
|
|
217
|
-
if (resultsTable.split("\n").length > 1) {
|
|
218
|
-
resultsTable = `### response${r.description ? ` (${r.description})` : ""}\n\n${resultsTable}`;
|
|
219
|
-
} else {
|
|
220
|
-
resultsTable = resultsTable === "" ? "" : `### response${r.description ? ` (${r.description})` : ""}: ${resultsTable}`;
|
|
221
|
-
}
|
|
222
|
-
if (resultsTable !== "") {
|
|
223
|
-
resultTables.push(resultsTable);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const pTable = policyTable(doc.policy);
|
|
228
|
-
|
|
229
|
-
return `## ${doc.featureName}\n\n` +
|
|
230
|
-
`${doc.description ? `${doc.description}\n\n` : ""}` +
|
|
231
|
-
`${pTable ? `${pTable}\n\n` : ""}` +
|
|
232
|
-
`### endpoint\n\n` +
|
|
233
|
-
`${methodUrlTable(doc)}\n\n` +
|
|
234
|
-
// `${paramsTable ? `${paramsTable}\n\n` : ""}` +
|
|
235
|
-
`${paramsTable.length > 0 ? `${paramsTable.join("\n\n")}\n\n` : ""}` +
|
|
236
|
-
`${queryTables.length > 0 ? `${queryTables.join("\n\n")}\n\n` : ""}` +
|
|
237
|
-
`${bodyTables.length > 0 ? `${bodyTables.join("\n\n")}\n\n` : ""}` +
|
|
238
|
-
`${resultTables.length > 0 ? `${resultTables.join("\n\n")}\n\n` : ""}`;
|
|
239
|
-
}).join("\n\n"));
|
|
240
|
-
|
|
241
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
-
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
|
|
5
|
-
const templates = {
|
|
6
|
-
ts: (path: string) =>
|
|
7
|
-
`import { APIRoute, Context } from "@miqro/core";
|
|
8
|
-
|
|
9
|
-
const route: APIRoute = {
|
|
10
|
-
path: "${path}",
|
|
11
|
-
method: "POST",
|
|
12
|
-
handler: async (ctx: Context) => {
|
|
13
|
-
return {
|
|
14
|
-
text: \`Hello \${ctx.body.name}!\`
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export default route;
|
|
20
|
-
`,
|
|
21
|
-
js: (path: string) =>
|
|
22
|
-
`module.exports = {
|
|
23
|
-
path: "${path}",
|
|
24
|
-
method: "POST",
|
|
25
|
-
handler: async (ctx) => {
|
|
26
|
-
return {
|
|
27
|
-
text: \`Hello \${ctx.body.name}!\`
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
`
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const main = (): void => {
|
|
35
|
-
|
|
36
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
37
|
-
throw new Error(`arguments: <identifier ex: SRC_API_V1_HEALTH>`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
41
|
-
|
|
42
|
-
const split = identifier.split("_");
|
|
43
|
-
|
|
44
|
-
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
45
|
-
if (dots.length > 0) {
|
|
46
|
-
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_API_V1_HEALTH>`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
loadConfig();
|
|
50
|
-
|
|
51
|
-
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
52
|
-
|
|
53
|
-
const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
54
|
-
|
|
55
|
-
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
56
|
-
if (existsSync(filePath)) {
|
|
57
|
-
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
console.log(`creating ${filePath}`);
|
|
61
|
-
|
|
62
|
-
mkdirSync(path, {
|
|
63
|
-
recursive: true
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
writeFileSync(filePath, templates[ext](`/${split[0]}`));
|
|
67
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { ConfigPathResolver, loadConfig } from "@miqro/core";
|
|
2
|
-
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
3
|
-
import { resolve } from "path";
|
|
4
|
-
|
|
5
|
-
const mainTemplates = {
|
|
6
|
-
ts: () =>
|
|
7
|
-
`import { APIRouter, App, checkEnvVariables, getLogger, middleware } from "@miqro/core";
|
|
8
|
-
import { resolve } from "path";
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
To be start as a main file
|
|
12
|
-
node file.js
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
const [PORT] = checkEnvVariables(["PORT"], ["8080"]);
|
|
16
|
-
|
|
17
|
-
const logger = getLogger("server");
|
|
18
|
-
|
|
19
|
-
const app = new App();
|
|
20
|
-
app.use(middleware());
|
|
21
|
-
app.use(APIRouter({
|
|
22
|
-
dirname: resolve(__dirname, "api")
|
|
23
|
-
}, logger));
|
|
24
|
-
app.listen(PORT, () => {
|
|
25
|
-
logger.info("listening on " + PORT);
|
|
26
|
-
});
|
|
27
|
-
`,
|
|
28
|
-
js: () =>
|
|
29
|
-
`const { APIRouter, App, checkEnvVariables, getLogger, middleware } = 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
|
-
const app = new App();
|
|
42
|
-
app.use(middleware());
|
|
43
|
-
app.use(APIRouter({
|
|
44
|
-
dirname: resolve(__dirname, "api")
|
|
45
|
-
}, logger));
|
|
46
|
-
app.listen(PORT, () => {
|
|
47
|
-
logger.info("listening on " + PORT);
|
|
48
|
-
});
|
|
49
|
-
`
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const main = (): void => {
|
|
53
|
-
|
|
54
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
55
|
-
throw new Error(`arguments: <identifier ex: SRC_MAIN>`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
59
|
-
|
|
60
|
-
const split = identifier.split("_");
|
|
61
|
-
|
|
62
|
-
const dots = split.filter(s => s.indexOf(".") !== -1);
|
|
63
|
-
if (dots.length > 0) {
|
|
64
|
-
throw new Error(`identifier cannot contain dots\narguments: <identifier ex: SRC_MAIN>`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
loadConfig();
|
|
68
|
-
|
|
69
|
-
const path = resolve(ConfigPathResolver.getBaseDirname(), ...split.splice(0, split.length - 1));
|
|
70
|
-
|
|
71
|
-
const ext = existsSync(resolve(ConfigPathResolver.getBaseDirname(), "tsconfig.json")) ? "ts" : "js";
|
|
72
|
-
|
|
73
|
-
const filePath = resolve(path, `${split[0]}.${ext}`);
|
|
74
|
-
if (existsSync(filePath)) {
|
|
75
|
-
throw new Error(`file ${filePath} already exists! doing nothing`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
console.log(`creating ${filePath}`);
|
|
79
|
-
|
|
80
|
-
mkdirSync(path, {
|
|
81
|
-
recursive: true
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
writeFileSync(filePath, mainTemplates[ext]());
|
|
85
|
-
}
|
package/src/cmds/new.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { execSync } from "../utils";
|
|
4
|
-
|
|
5
|
-
const packageTemplate = {
|
|
6
|
-
ts: (name: string) =>
|
|
7
|
-
`{
|
|
8
|
-
"name": "${name}",
|
|
9
|
-
"version": "1.0.0",
|
|
10
|
-
"description": "",
|
|
11
|
-
"private": true,
|
|
12
|
-
"main": "dist/main.js",
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
15
|
-
"start": "node dist/main.js"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
},
|
|
21
|
-
"author": "",
|
|
22
|
-
"license": "ISC"
|
|
23
|
-
}`,
|
|
24
|
-
js: (name: string) =>
|
|
25
|
-
`{
|
|
26
|
-
"name": "${name}",
|
|
27
|
-
"version": "1.0.0",
|
|
28
|
-
"description": "",
|
|
29
|
-
"private": true,
|
|
30
|
-
"main": "src/main.js",
|
|
31
|
-
"scripts": {
|
|
32
|
-
"start": "node src/main.js"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
},
|
|
36
|
-
"dependencies": {
|
|
37
|
-
},
|
|
38
|
-
"author": "",
|
|
39
|
-
"license": "ISC"
|
|
40
|
-
}`
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const mainJS = (typescript = false): void => {
|
|
44
|
-
if (process.argv.length !== 4 || process.argv[3].length < 1) {
|
|
45
|
-
throw new Error(`arguments: <name ex: NEW_APP>`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const identifier = process.argv[3].toLocaleLowerCase();
|
|
49
|
-
|
|
50
|
-
const appFolder = resolve(process.cwd(), identifier);
|
|
51
|
-
|
|
52
|
-
if (existsSync(appFolder)) {
|
|
53
|
-
throw new Error(`${appFolder} already exists!`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log(`creating ${appFolder}`);
|
|
57
|
-
|
|
58
|
-
mkdirSync(appFolder, {
|
|
59
|
-
recursive: true
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
writeFileSync(resolve(appFolder, "package.json"), packageTemplate[typescript ? "ts" : "js"](identifier));
|
|
63
|
-
|
|
64
|
-
execSync(
|
|
65
|
-
`npm install miqro --save-dev`,
|
|
66
|
-
{
|
|
67
|
-
cwd: appFolder
|
|
68
|
-
}
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
execSync(
|
|
72
|
-
`npm install @miqro/core --save`,
|
|
73
|
-
{
|
|
74
|
-
cwd: appFolder
|
|
75
|
-
}
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
if (typescript) {
|
|
79
|
-
writeFileSync(resolve(appFolder, "tsconfig.json"), `{
|
|
80
|
-
"compileOnSave": true,
|
|
81
|
-
"compilerOptions": {
|
|
82
|
-
"strict": false,
|
|
83
|
-
"outDir": "./dist/",
|
|
84
|
-
"removeComments": true,
|
|
85
|
-
"noImplicitAny": false,
|
|
86
|
-
"preserveConstEnums": true,
|
|
87
|
-
"sourceMap": true,
|
|
88
|
-
"esModuleInterop": true,
|
|
89
|
-
"declaration": true,
|
|
90
|
-
"moduleResolution": "node",
|
|
91
|
-
"module": "commonjs",
|
|
92
|
-
"target": "es2017",
|
|
93
|
-
"lib": [
|
|
94
|
-
"es2017"
|
|
95
|
-
]
|
|
96
|
-
},
|
|
97
|
-
"exclude": [
|
|
98
|
-
"node_modules",
|
|
99
|
-
"test"
|
|
100
|
-
],
|
|
101
|
-
"include": [
|
|
102
|
-
"src"
|
|
103
|
-
]
|
|
104
|
-
}`);
|
|
105
|
-
/*execSync(`npm install typescript --save-dev`, {
|
|
106
|
-
cwd: appFolder
|
|
107
|
-
});
|
|
108
|
-
execSync(`npm install @types/node --save-dev`, {
|
|
109
|
-
cwd: appFolder
|
|
110
|
-
});*/
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
execSync(
|
|
114
|
-
`npx miqro new:main src_main`,
|
|
115
|
-
{
|
|
116
|
-
cwd: appFolder
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
execSync(
|
|
121
|
-
`npx miqro new:route src_api_health`,
|
|
122
|
-
{
|
|
123
|
-
cwd: appFolder
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export const mainTS = (): void => mainJS(true);
|
package/src/cmds/start.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { execSync } from "../utils";
|
|
2
|
-
import { mainPath } from "@miqro/runner";
|
|
3
|
-
import { loadConfig } from "@miqro/core";
|
|
4
|
-
|
|
5
|
-
export const main = (): void => {
|
|
6
|
-
|
|
7
|
-
if (process.argv.length <= 3) {
|
|
8
|
-
throw new Error(`invalid number of args\nusage: CLUSTER_COUNT=1 [DISABLE_RESTART=true|false] npx miqro start <script> [...args]`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
loadConfig();
|
|
12
|
-
|
|
13
|
-
//execSync(`npx @miqro/runner ${process.argv.slice(3).join(" ")}`);
|
|
14
|
-
execSync(`${process.argv[0]} ${mainPath()} ${process.argv.slice(3).join(" ")}`)
|
|
15
|
-
}
|
|
16
|
-
|
package/src/cmds/test.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { CLIUtil } from "@miqro/core";
|
|
3
|
-
import { runTestModules } from "../test";
|
|
4
|
-
|
|
5
|
-
export const main = async (): Promise<void> => {
|
|
6
|
-
|
|
7
|
-
if (process.argv.length < 4) {
|
|
8
|
-
throw new Error(`bad arguments`);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const startMS = Date.now();
|
|
12
|
-
|
|
13
|
-
const args = CLIUtil.extractFlags(process.argv.slice(3));
|
|
14
|
-
|
|
15
|
-
const modules = args.cmds.map(m => resolve(process.cwd(), m));
|
|
16
|
-
|
|
17
|
-
const name = args.flags.n ? args.flags.n : "all";
|
|
18
|
-
|
|
19
|
-
const logger = console;
|
|
20
|
-
|
|
21
|
-
const ret = await runTestModules(modules, typeof name === "string" && name.toLowerCase() === "all" ? undefined : name, console);
|
|
22
|
-
|
|
23
|
-
const took = Date.now() - startMS;
|
|
24
|
-
|
|
25
|
-
ret.failed.forEach(e => {
|
|
26
|
-
logger.log("");
|
|
27
|
-
logger.log("");
|
|
28
|
-
logger.error("\x1b[31m%s\x1b[0m", e.fullName);
|
|
29
|
-
logger.error(e.error);
|
|
30
|
-
logger.log("");
|
|
31
|
-
logger.log("");
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
logger.log("");
|
|
35
|
-
logger.log("");
|
|
36
|
-
logger.log(ret.passed + " tests pased");
|
|
37
|
-
logger.log(ret.failed.length + " failed");
|
|
38
|
-
logger.log("took " + took + "ms");
|
|
39
|
-
logger.log("");
|
|
40
|
-
logger.log("");
|
|
41
|
-
|
|
42
|
-
process.exit(ret.failed.length > 0 ? 1 : 0);
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./test";
|
package/src/test/common/app.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { request, RequestOptions, RequestResponse } from "@miqro/core";
|
|
2
|
-
|
|
3
|
-
import { existsSync, unlinkSync } from "fs";
|
|
4
|
-
import { createServer, RequestListener } from "http";
|
|
5
|
-
|
|
6
|
-
export const TestHelper = async (app: {
|
|
7
|
-
listener: RequestListener;
|
|
8
|
-
}, options: RequestOptions, cb?: (response: RequestResponse) => void): Promise<RequestResponse> => {
|
|
9
|
-
const unixSocket = `/tmp/socket.test.helper${Date.now()}`;
|
|
10
|
-
if (existsSync(unixSocket)) {
|
|
11
|
-
unlinkSync(unixSocket);
|
|
12
|
-
}
|
|
13
|
-
const server = createServer(app.listener);
|
|
14
|
-
return new Promise<RequestResponse>((resolve, reject) => {
|
|
15
|
-
server.listen(unixSocket, () => {
|
|
16
|
-
request({
|
|
17
|
-
disableThrow: true,
|
|
18
|
-
...options,
|
|
19
|
-
socketPath: unixSocket
|
|
20
|
-
}).then((response) => {
|
|
21
|
-
server.close(() => {
|
|
22
|
-
if (cb) {
|
|
23
|
-
try {
|
|
24
|
-
cb(response);
|
|
25
|
-
} catch (ee) {
|
|
26
|
-
reject(ee);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
resolve(response);
|
|
30
|
-
});
|
|
31
|
-
}).catch((e: any) => {
|
|
32
|
-
server.close(() => {
|
|
33
|
-
if (cb) {
|
|
34
|
-
try {
|
|
35
|
-
cb(e as any);
|
|
36
|
-
} catch (ee) {
|
|
37
|
-
reject(ee);
|
|
38
|
-
}
|
|
39
|
-
resolve(undefined as any);
|
|
40
|
-
} else {
|
|
41
|
-
reject(e);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type Callback<T = any> = (...args: any[]) => T;
|
|
2
|
-
|
|
3
|
-
export interface FakeCallback<T = any> extends Callback<T> {
|
|
4
|
-
callCount: number;
|
|
5
|
-
callArgs: T[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const fake = (cb: Callback): FakeCallback => {
|
|
9
|
-
const ret = (...args: any[]) => {
|
|
10
|
-
ret.callCount++;
|
|
11
|
-
ret.callArgs.push(args);
|
|
12
|
-
return cb(...args);
|
|
13
|
-
};
|
|
14
|
-
ret.callCount = 0;
|
|
15
|
-
ret.callArgs = [] as any;
|
|
16
|
-
return ret;
|
|
17
|
-
}
|
package/src/test/common/index.ts
DELETED