@sealcode/sealgen 0.10.2 → 0.10.3
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/@types/templates/long-running-process.d.ts +1 -0
- package/@types/templates/templates.d.ts +17 -0
- package/lib/add-route.js +3 -16
- package/lib/generate-routes.js +2 -7
- package/lib/templates/long-running-process.js +60 -0
- package/lib/templates/templates.js +22 -0
- package/package.json +1 -1
- package/src/add-route.ts +3 -16
- package/src/generate-routes.ts +3 -9
- package/src/templates/long-running-process.ts +59 -0
- package/src/templates/templates.ts +19 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function LongRunningProcessTemplate(action_name: string, newfilefullpath: string): Promise<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { formTemplate } from "./form";
|
|
2
|
+
import { LongRunningProcessTemplate } from "./long-running-process";
|
|
3
|
+
import { multiformTemplate } from "./multiform";
|
|
4
|
+
import { pageTemplate } from "./page";
|
|
5
|
+
import { postTemplate } from "./post";
|
|
6
|
+
import { redirectTemplate } from "./redirect";
|
|
7
|
+
import { statefulPageTemplate } from "./stateful-page";
|
|
8
|
+
export declare const Templates: {
|
|
9
|
+
page: typeof pageTemplate;
|
|
10
|
+
form: typeof formTemplate;
|
|
11
|
+
list: (action_name: string, newfilefullpath: string) => Promise<string>;
|
|
12
|
+
multiform: typeof multiformTemplate;
|
|
13
|
+
redirect: typeof redirectTemplate;
|
|
14
|
+
post: typeof postTemplate;
|
|
15
|
+
sreact: typeof statefulPageTemplate;
|
|
16
|
+
lpr: typeof LongRunningProcessTemplate;
|
|
17
|
+
};
|
package/lib/add-route.js
CHANGED
|
@@ -8,16 +8,10 @@ const fs_1 = require("fs");
|
|
|
8
8
|
const locreq_1 = __importDefault(require("locreq"));
|
|
9
9
|
const path_1 = require("path");
|
|
10
10
|
const generate_routes_1 = require("./generate-routes");
|
|
11
|
-
const form_1 = require("./templates/form");
|
|
12
|
-
const list_1 = require("./templates/list");
|
|
13
|
-
const multiform_1 = require("./templates/multiform");
|
|
14
|
-
const page_1 = require("./templates/page");
|
|
15
|
-
const redirect_1 = require("./templates/redirect");
|
|
16
11
|
const route_test_1 = require("./templates/route-test");
|
|
17
12
|
const escape_url_params_1 = require("./utils/escape-url-params");
|
|
18
13
|
const prompts = require("prompts");
|
|
19
|
-
const
|
|
20
|
-
const stateful_page_1 = require("./templates/stateful-page");
|
|
14
|
+
const templates_1 = require("./templates/templates");
|
|
21
15
|
async function addRoute(params, app_directory = process.cwd()) {
|
|
22
16
|
const target_locreq = (0, locreq_1.default)(app_directory);
|
|
23
17
|
prompts.override(params);
|
|
@@ -46,21 +40,14 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
46
40
|
{ title: "multiform", value: "multiform" },
|
|
47
41
|
{ title: "redirect", value: "redirect" },
|
|
48
42
|
{ title: "raw POST", value: "post" },
|
|
43
|
+
{ title: "Long Running Process status page", value: "lpr" },
|
|
49
44
|
],
|
|
50
45
|
},
|
|
51
46
|
]);
|
|
52
47
|
const { action, url, mode } = response;
|
|
53
48
|
const file_path = target_locreq.resolve(`src/back/routes/${(0, escape_url_params_1.escape_url_params)(url)}.${mode}.ts`);
|
|
54
49
|
const test_file_path = target_locreq.resolve(`src/back/routes/${(0, escape_url_params_1.escape_url_params)(url)}.test.ts`);
|
|
55
|
-
const template =
|
|
56
|
-
page: page_1.pageTemplate,
|
|
57
|
-
form: form_1.formTemplate,
|
|
58
|
-
list: list_1.listTemplate,
|
|
59
|
-
multiform: multiform_1.multiformTemplate,
|
|
60
|
-
redirect: redirect_1.redirectTemplate,
|
|
61
|
-
post: post_1.postTemplate,
|
|
62
|
-
sreact: stateful_page_1.statefulPageTemplate,
|
|
63
|
-
}[mode];
|
|
50
|
+
const template = templates_1.Templates[mode];
|
|
64
51
|
if (!template) {
|
|
65
52
|
throw new Error(`Could not get template ${mode}`);
|
|
66
53
|
}
|
package/lib/generate-routes.js
CHANGED
|
@@ -36,6 +36,7 @@ const import_path_1 = require("./utils/import-path");
|
|
|
36
36
|
const ts_predicates_1 = require("@sealcode/ts-predicates");
|
|
37
37
|
const escape_url_params_1 = require("./utils/escape-url-params");
|
|
38
38
|
const prettier_1 = require("./utils/prettier");
|
|
39
|
+
const templates_1 = require("./templates/templates");
|
|
39
40
|
const target_locreq = (0, locreq_1.default)(process.cwd());
|
|
40
41
|
async function extractActionName(full_file_path) {
|
|
41
42
|
const file_content = await fs_1.promises.readFile(full_file_path, "utf-8");
|
|
@@ -65,13 +66,7 @@ function generateURL(actionName, url) {
|
|
|
65
66
|
}
|
|
66
67
|
async function generateRoutes() {
|
|
67
68
|
const files = await Promise.all((await (0, walk_1.walkDir)(target_locreq.resolve("src/back/routes")))
|
|
68
|
-
.filter((f) => f.endsWith(
|
|
69
|
-
f.endsWith(".form.ts") ||
|
|
70
|
-
f.endsWith(".multiform.ts") ||
|
|
71
|
-
f.endsWith(".list.ts") ||
|
|
72
|
-
f.endsWith(".redirect.ts") ||
|
|
73
|
-
f.endsWith(".post.ts") ||
|
|
74
|
-
f.endsWith(".sreact.ts"))
|
|
69
|
+
.filter((f) => Object.keys(templates_1.Templates).some((key) => f.endsWith(`.${key}.ts`)))
|
|
75
70
|
.map(async (fullpath) => ({
|
|
76
71
|
fullpath,
|
|
77
72
|
actionName: await extractActionName(fullpath),
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LongRunningProcessTemplate = void 0;
|
|
4
|
+
const import_path_1 = require("../utils/import-path");
|
|
5
|
+
async function LongRunningProcessTemplate(action_name, newfilefullpath) {
|
|
6
|
+
const rel = (0, import_path_1.curryImportPath)(newfilefullpath);
|
|
7
|
+
return `import { Context } from "koa";
|
|
8
|
+
import { tempstream } from "tempstream";
|
|
9
|
+
import { Page } from "@sealcode/sealgen";
|
|
10
|
+
import html from "${rel("src/back/html.js")}";
|
|
11
|
+
import { LongRunningProcess } from "sealious";
|
|
12
|
+
|
|
13
|
+
export const actionName = "${action_name}";
|
|
14
|
+
|
|
15
|
+
export default new (class PatroniteAutoImportStatusPage extends Page {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
17
|
+
async canAccess(_: Context) {
|
|
18
|
+
return { canAccess: true, message: "" };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public interval = 2000;
|
|
22
|
+
|
|
23
|
+
async render(ctx: Context) {
|
|
24
|
+
const lpr_id = ctx.params.id;
|
|
25
|
+
const lpr_data = LongRunningProcess.getByID(ctx.$context, lpr_id);
|
|
26
|
+
return html(
|
|
27
|
+
ctx,
|
|
28
|
+
"PatroniteAutoImportStatus",
|
|
29
|
+
tempstream/* HTML */ \`\${lpr_data.then(
|
|
30
|
+
(lpr_data) => tempstream/* HTML */ \`
|
|
31
|
+
<div>status: \${lpr_data.state}</div>
|
|
32
|
+
<div style="height: 20px; width: 100%">
|
|
33
|
+
<div
|
|
34
|
+
style="height: 100%; background-color: green; width: \${Math.round(
|
|
35
|
+
lpr_data.progress * 100
|
|
36
|
+
)}%"
|
|
37
|
+
></div>
|
|
38
|
+
</div>
|
|
39
|
+
<div>
|
|
40
|
+
\${lpr_data.events.map(
|
|
41
|
+
(e) => /* HTML */ \`<div>\${e.message}</div>\`
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
\${lpr_data.state !== "error" &&
|
|
45
|
+
lpr_data.state !== "finished"
|
|
46
|
+
? /* HTML */ \`<script>
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
document.location = document.location;
|
|
49
|
+
}, \${this.interval});
|
|
50
|
+
</script>\`
|
|
51
|
+
: ""}
|
|
52
|
+
\`
|
|
53
|
+
)}\`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
exports.LongRunningProcessTemplate = LongRunningProcessTemplate;
|
|
60
|
+
//# sourceMappingURL=long-running-process.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Templates = void 0;
|
|
4
|
+
const form_1 = require("./form");
|
|
5
|
+
const list_1 = require("./list");
|
|
6
|
+
const long_running_process_1 = require("./long-running-process");
|
|
7
|
+
const multiform_1 = require("./multiform");
|
|
8
|
+
const page_1 = require("./page");
|
|
9
|
+
const post_1 = require("./post");
|
|
10
|
+
const redirect_1 = require("./redirect");
|
|
11
|
+
const stateful_page_1 = require("./stateful-page");
|
|
12
|
+
exports.Templates = {
|
|
13
|
+
page: page_1.pageTemplate,
|
|
14
|
+
form: form_1.formTemplate,
|
|
15
|
+
list: list_1.listTemplate,
|
|
16
|
+
multiform: multiform_1.multiformTemplate,
|
|
17
|
+
redirect: redirect_1.redirectTemplate,
|
|
18
|
+
post: post_1.postTemplate,
|
|
19
|
+
sreact: stateful_page_1.statefulPageTemplate,
|
|
20
|
+
lpr: long_running_process_1.LongRunningProcessTemplate,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=templates.js.map
|
package/package.json
CHANGED
package/src/add-route.ts
CHANGED
|
@@ -2,16 +2,10 @@ import { existsSync, promises as fs } from "fs";
|
|
|
2
2
|
import _locreq from "locreq";
|
|
3
3
|
import { resolve } from "path";
|
|
4
4
|
import { generateRoutes } from "./generate-routes";
|
|
5
|
-
import { formTemplate } from "./templates/form";
|
|
6
|
-
import { listTemplate } from "./templates/list";
|
|
7
|
-
import { multiformTemplate } from "./templates/multiform";
|
|
8
|
-
import { pageTemplate } from "./templates/page";
|
|
9
|
-
import { redirectTemplate } from "./templates/redirect";
|
|
10
5
|
import { testTemplate } from "./templates/route-test";
|
|
11
6
|
import { escape_url_params } from "./utils/escape-url-params";
|
|
12
7
|
import prompts = require("prompts");
|
|
13
|
-
import {
|
|
14
|
-
import { statefulPageTemplate } from "./templates/stateful-page";
|
|
8
|
+
import { Templates } from "./templates/templates";
|
|
15
9
|
|
|
16
10
|
export async function addRoute(
|
|
17
11
|
params: Partial<{ [key in "action" | "url" | "mode"]: string }>,
|
|
@@ -47,6 +41,7 @@ export async function addRoute(
|
|
|
47
41
|
{ title: "multiform", value: "multiform" },
|
|
48
42
|
{ title: "redirect", value: "redirect" },
|
|
49
43
|
{ title: "raw POST", value: "post" },
|
|
44
|
+
{ title: "Long Running Process status page", value: "lpr" },
|
|
50
45
|
],
|
|
51
46
|
},
|
|
52
47
|
]);
|
|
@@ -59,15 +54,7 @@ export async function addRoute(
|
|
|
59
54
|
const test_file_path = target_locreq.resolve(
|
|
60
55
|
`src/back/routes/${escape_url_params(url)}.test.ts`
|
|
61
56
|
);
|
|
62
|
-
const template =
|
|
63
|
-
page: pageTemplate,
|
|
64
|
-
form: formTemplate,
|
|
65
|
-
list: listTemplate,
|
|
66
|
-
multiform: multiformTemplate,
|
|
67
|
-
redirect: redirectTemplate,
|
|
68
|
-
post: postTemplate,
|
|
69
|
-
sreact: statefulPageTemplate,
|
|
70
|
-
}[mode];
|
|
57
|
+
const template = Templates[mode as keyof typeof Templates];
|
|
71
58
|
|
|
72
59
|
if (!template) {
|
|
73
60
|
throw new Error(`Could not get template ${mode}`);
|
package/src/generate-routes.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { importPath } from "./utils/import-path";
|
|
|
7
7
|
import { assertType, predicates } from "@sealcode/ts-predicates";
|
|
8
8
|
import { unescape_url_params } from "./utils/escape-url-params";
|
|
9
9
|
import { getPrettierConfig } from "./utils/prettier";
|
|
10
|
+
import { Templates } from "./templates/templates";
|
|
10
11
|
|
|
11
12
|
const target_locreq = _locreq(process.cwd());
|
|
12
13
|
|
|
@@ -49,15 +50,8 @@ export async function generateRoutes(): Promise<void> {
|
|
|
49
50
|
(
|
|
50
51
|
await walkDir(target_locreq.resolve("src/back/routes"))
|
|
51
52
|
)
|
|
52
|
-
.filter(
|
|
53
|
-
(
|
|
54
|
-
f.endsWith(".page.ts") ||
|
|
55
|
-
f.endsWith(".form.ts") ||
|
|
56
|
-
f.endsWith(".multiform.ts") ||
|
|
57
|
-
f.endsWith(".list.ts") ||
|
|
58
|
-
f.endsWith(".redirect.ts") ||
|
|
59
|
-
f.endsWith(".post.ts") ||
|
|
60
|
-
f.endsWith(".sreact.ts")
|
|
53
|
+
.filter((f) =>
|
|
54
|
+
Object.keys(Templates).some((key) => f.endsWith(`.${key}.ts`))
|
|
61
55
|
)
|
|
62
56
|
.map(async (fullpath) => ({
|
|
63
57
|
fullpath,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
|
|
3
|
+
export async function LongRunningProcessTemplate(
|
|
4
|
+
action_name: string,
|
|
5
|
+
newfilefullpath: string
|
|
6
|
+
): Promise<string> {
|
|
7
|
+
const rel = curryImportPath(newfilefullpath);
|
|
8
|
+
return `import { Context } from "koa";
|
|
9
|
+
import { tempstream } from "tempstream";
|
|
10
|
+
import { Page } from "@sealcode/sealgen";
|
|
11
|
+
import html from "${rel("src/back/html.js")}";
|
|
12
|
+
import { LongRunningProcess } from "sealious";
|
|
13
|
+
|
|
14
|
+
export const actionName = "${action_name}";
|
|
15
|
+
|
|
16
|
+
export default new (class PatroniteAutoImportStatusPage extends Page {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
async canAccess(_: Context) {
|
|
19
|
+
return { canAccess: true, message: "" };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public interval = 2000;
|
|
23
|
+
|
|
24
|
+
async render(ctx: Context) {
|
|
25
|
+
const lpr_id = ctx.params.id;
|
|
26
|
+
const lpr_data = LongRunningProcess.getByID(ctx.$context, lpr_id);
|
|
27
|
+
return html(
|
|
28
|
+
ctx,
|
|
29
|
+
"PatroniteAutoImportStatus",
|
|
30
|
+
tempstream/* HTML */ \`\${lpr_data.then(
|
|
31
|
+
(lpr_data) => tempstream/* HTML */ \`
|
|
32
|
+
<div>status: \${lpr_data.state}</div>
|
|
33
|
+
<div style="height: 20px; width: 100%">
|
|
34
|
+
<div
|
|
35
|
+
style="height: 100%; background-color: green; width: \${Math.round(
|
|
36
|
+
lpr_data.progress * 100
|
|
37
|
+
)}%"
|
|
38
|
+
></div>
|
|
39
|
+
</div>
|
|
40
|
+
<div>
|
|
41
|
+
\${lpr_data.events.map(
|
|
42
|
+
(e) => /* HTML */ \`<div>\${e.message}</div>\`
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
\${lpr_data.state !== "error" &&
|
|
46
|
+
lpr_data.state !== "finished"
|
|
47
|
+
? /* HTML */ \`<script>
|
|
48
|
+
setTimeout(() => {
|
|
49
|
+
document.location = document.location;
|
|
50
|
+
}, \${this.interval});
|
|
51
|
+
</script>\`
|
|
52
|
+
: ""}
|
|
53
|
+
\`
|
|
54
|
+
)}\`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { formTemplate } from "./form";
|
|
2
|
+
import { listTemplate } from "./list";
|
|
3
|
+
import { LongRunningProcessTemplate } from "./long-running-process";
|
|
4
|
+
import { multiformTemplate } from "./multiform";
|
|
5
|
+
import { pageTemplate } from "./page";
|
|
6
|
+
import { postTemplate } from "./post";
|
|
7
|
+
import { redirectTemplate } from "./redirect";
|
|
8
|
+
import { statefulPageTemplate } from "./stateful-page";
|
|
9
|
+
|
|
10
|
+
export const Templates = {
|
|
11
|
+
page: pageTemplate,
|
|
12
|
+
form: formTemplate,
|
|
13
|
+
list: listTemplate,
|
|
14
|
+
multiform: multiformTemplate,
|
|
15
|
+
redirect: redirectTemplate,
|
|
16
|
+
post: postTemplate,
|
|
17
|
+
sreact: statefulPageTemplate,
|
|
18
|
+
lpr: LongRunningProcessTemplate,
|
|
19
|
+
};
|