@sealcode/sealgen 0.17.20 → 0.17.21
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/src/templates/jdd-editor.d.ts +1 -0
- package/@types/src/templates/templates.d.ts +2 -0
- package/lib/add-crud.js +1 -1
- package/lib/add-route.js +6 -3
- package/lib/templates/jdd-editor.js +81 -0
- package/lib/templates/templates.js +3 -1
- package/package.json +1 -1
- package/src/add-crud.ts +2 -1
- package/src/add-route.ts +5 -2
- package/src/templates/jdd-editor.ts +89 -0
- package/src/templates/templates.ts +2 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function jddEditorTemplate(actionName: string): Promise<string>;
|
|
@@ -6,6 +6,7 @@ import { pageTemplate } from "./page.js";
|
|
|
6
6
|
import { postTemplate } from "./post.js";
|
|
7
7
|
import { redirectTemplate } from "./redirect.js";
|
|
8
8
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
9
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
9
10
|
export declare const Templates: {
|
|
10
11
|
page: typeof pageTemplate;
|
|
11
12
|
form: typeof formTemplate;
|
|
@@ -16,4 +17,5 @@ export declare const Templates: {
|
|
|
16
17
|
sreact: typeof statefulPageTemplate;
|
|
17
18
|
lpr: typeof LongRunningProcessTemplate;
|
|
18
19
|
jdd: typeof jddComponentTemplate;
|
|
20
|
+
"jdd-editor": typeof jddEditorTemplate;
|
|
19
21
|
};
|
package/lib/add-crud.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
3
2
|
import prompts from "prompts";
|
|
3
|
+
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
4
4
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
5
5
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
6
|
import {
|
package/lib/add-route.js
CHANGED
|
@@ -41,12 +41,15 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
41
41
|
{ title: "multiform", value: "multiform" },
|
|
42
42
|
{ title: "redirect", value: "redirect" },
|
|
43
43
|
{ title: "raw POST", value: "post" },
|
|
44
|
-
{ title: "Long Running Process status page", value: "lpr" }
|
|
44
|
+
{ title: "Long Running Process status page", value: "lpr" },
|
|
45
|
+
{ title: "JDD content editor", value: "jdd-editor" }
|
|
45
46
|
]
|
|
46
47
|
}
|
|
47
48
|
]);
|
|
48
49
|
const { action, url, mode } = response;
|
|
49
|
-
const extension = ["list", "lpr", "page", "sreact"].includes(
|
|
50
|
+
const extension = ["list", "lpr", "page", "sreact", "jdd-editor"].includes(
|
|
51
|
+
mode
|
|
52
|
+
) ? "tsx" : "ts";
|
|
50
53
|
const base_file_name = escape_url_params(url) || "index";
|
|
51
54
|
const file_path = target_locreq.resolve(
|
|
52
55
|
`src/back/routes/${base_file_name}.${mode}.${extension}`
|
|
@@ -64,7 +67,7 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
64
67
|
}
|
|
65
68
|
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
66
69
|
await fs.writeFile(file_path, await template(action, file_path));
|
|
67
|
-
if (mode !== "lpr") {
|
|
70
|
+
if (mode !== "lpr" && mode !== "jdd-editor") {
|
|
68
71
|
await fs.writeFile(
|
|
69
72
|
test_file_path,
|
|
70
73
|
await testTemplate(action, file_path)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { toPascalCase } from "js-convert-case";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
4
|
+
import { listCollections } from "../utils/list-collections.js";
|
|
5
|
+
async function jddEditorTemplate(actionName) {
|
|
6
|
+
const response = await prompts([
|
|
7
|
+
{
|
|
8
|
+
type: "autocomplete",
|
|
9
|
+
name: "collection",
|
|
10
|
+
message: "Which sealious collection do you like to add CRUD forms for?",
|
|
11
|
+
choices: (await listCollections()).map((collection) => ({
|
|
12
|
+
title: collection,
|
|
13
|
+
value: collection
|
|
14
|
+
}))
|
|
15
|
+
}
|
|
16
|
+
]);
|
|
17
|
+
const collection_name = response.collection;
|
|
18
|
+
const jdd_fields = (await extract_fields_from_collection(collection_name)).filter((e) => e.type == "jdd");
|
|
19
|
+
let field_name = "";
|
|
20
|
+
if (jdd_fields.length == 1) {
|
|
21
|
+
field_name = jdd_fields[0].name;
|
|
22
|
+
console.log(
|
|
23
|
+
`Only one field of type JDD found: ${field_name}, so skipping the question...`
|
|
24
|
+
);
|
|
25
|
+
} else if (jdd_fields.length > 1) {
|
|
26
|
+
const response2 = await prompts([
|
|
27
|
+
{
|
|
28
|
+
type: "autocomplete",
|
|
29
|
+
name: "field_name",
|
|
30
|
+
message: `Which jdd field from the ${collection_name} do you want to setup the jdd-editor for?`,
|
|
31
|
+
choices: jdd_fields.map((field) => ({
|
|
32
|
+
title: field.name,
|
|
33
|
+
value: field.name
|
|
34
|
+
}))
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
field_name = response2.field_name;
|
|
38
|
+
} else {
|
|
39
|
+
console.error(
|
|
40
|
+
`Collection ${collection_name} does not have any fields of type JDD. Add such a field and try again.`
|
|
41
|
+
);
|
|
42
|
+
process.exit(13);
|
|
43
|
+
}
|
|
44
|
+
const collectionClassName = toPascalCase(collection_name);
|
|
45
|
+
return `import type { Context } from "koa";
|
|
46
|
+
import type { FieldNames } from "sealious";
|
|
47
|
+
import { TempstreamJSX } from "tempstream";
|
|
48
|
+
import type ${collectionClassName} from "src/back/collections/${collection_name}.js";
|
|
49
|
+
import { EditJDDField } from "@sealcode/jdd-editor";
|
|
50
|
+
import html from "src/back/html.js";
|
|
51
|
+
import { registry } from "src/back/jdd-components/registry.js";
|
|
52
|
+
import { makeJDDContext } from "src/back/jdd-context.js";
|
|
53
|
+
import { defaultHead } from "src/back/defaultHead.js";
|
|
54
|
+
|
|
55
|
+
export const actionName = "${actionName}";
|
|
56
|
+
|
|
57
|
+
export default new (class JDDCreatePreviewPage extends EditJDDField<${collectionClassName}> {
|
|
58
|
+
getCollection(ctx: Context) {
|
|
59
|
+
return ctx.$app.collections["${collection_name}"];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getJDDFieldName(): FieldNames<${collectionClassName}["fields"]> {
|
|
63
|
+
return "${field_name}";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async renderPreParameterButtons(ctx: Context) {
|
|
67
|
+
const item = await this.getItem(ctx);
|
|
68
|
+
return (
|
|
69
|
+
<div>
|
|
70
|
+
<h1>Edit ${collection_name}: {item.id}</h1>{" "}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
})({ html, registry, makeJDDContext, defaultHead });
|
|
75
|
+
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
export {
|
|
79
|
+
jddEditorTemplate
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=jdd-editor.js.map
|
|
@@ -7,6 +7,7 @@ import { pageTemplate } from "./page.js";
|
|
|
7
7
|
import { postTemplate } from "./post.js";
|
|
8
8
|
import { redirectTemplate } from "./redirect.js";
|
|
9
9
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
10
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
10
11
|
const Templates = {
|
|
11
12
|
page: pageTemplate,
|
|
12
13
|
form: formTemplate,
|
|
@@ -16,7 +17,8 @@ const Templates = {
|
|
|
16
17
|
post: postTemplate,
|
|
17
18
|
sreact: statefulPageTemplate,
|
|
18
19
|
lpr: LongRunningProcessTemplate,
|
|
19
|
-
jdd: jddComponentTemplate
|
|
20
|
+
jdd: jddComponentTemplate,
|
|
21
|
+
"jdd-editor": jddEditorTemplate
|
|
20
22
|
};
|
|
21
23
|
export {
|
|
22
24
|
Templates
|
package/package.json
CHANGED
package/src/add-crud.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
3
2
|
import prompts from "prompts";
|
|
3
|
+
|
|
4
|
+
import { escape_url_params } from "./utils/escape-url-params.js";
|
|
4
5
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
5
6
|
import { listCollections } from "./utils/list-collections.js";
|
|
6
7
|
import {
|
package/src/add-route.ts
CHANGED
|
@@ -49,12 +49,15 @@ export async function addRoute(
|
|
|
49
49
|
{ title: "redirect", value: "redirect" },
|
|
50
50
|
{ title: "raw POST", value: "post" },
|
|
51
51
|
{ title: "Long Running Process status page", value: "lpr" },
|
|
52
|
+
{ title: "JDD content editor", value: "jdd-editor" },
|
|
52
53
|
],
|
|
53
54
|
},
|
|
54
55
|
]);
|
|
55
56
|
|
|
56
57
|
const { action, url, mode } = response as Record<string, string>;
|
|
57
|
-
const extension = ["list", "lpr", "page", "sreact"].includes(
|
|
58
|
+
const extension = ["list", "lpr", "page", "sreact", "jdd-editor"].includes(
|
|
59
|
+
mode
|
|
60
|
+
)
|
|
58
61
|
? "tsx"
|
|
59
62
|
: "ts";
|
|
60
63
|
|
|
@@ -78,7 +81,7 @@ export async function addRoute(
|
|
|
78
81
|
}
|
|
79
82
|
await fs.mkdir(resolve(file_path, "../"), { recursive: true });
|
|
80
83
|
await fs.writeFile(file_path, await template(action, file_path));
|
|
81
|
-
if (mode !== "lpr") {
|
|
84
|
+
if (mode !== "lpr" && mode !== "jdd-editor") {
|
|
82
85
|
await fs.writeFile(
|
|
83
86
|
test_file_path,
|
|
84
87
|
await testTemplate(action, file_path)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { toPascalCase } from "js-convert-case";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
4
|
+
|
|
5
|
+
import { listCollections } from "../utils/list-collections.js";
|
|
6
|
+
|
|
7
|
+
export async function jddEditorTemplate(actionName: string) {
|
|
8
|
+
const response = await prompts([
|
|
9
|
+
{
|
|
10
|
+
type: "autocomplete",
|
|
11
|
+
name: "collection",
|
|
12
|
+
message:
|
|
13
|
+
"Which sealious collection do you like to add CRUD forms for?",
|
|
14
|
+
choices: (
|
|
15
|
+
await listCollections()
|
|
16
|
+
).map((collection) => ({
|
|
17
|
+
title: collection,
|
|
18
|
+
value: collection,
|
|
19
|
+
})),
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const collection_name = response.collection as string;
|
|
24
|
+
|
|
25
|
+
const jdd_fields = (
|
|
26
|
+
await extract_fields_from_collection(collection_name)
|
|
27
|
+
).filter((e) => e.type == "jdd");
|
|
28
|
+
|
|
29
|
+
let field_name = "";
|
|
30
|
+
if (jdd_fields.length == 1) {
|
|
31
|
+
field_name = jdd_fields[0].name;
|
|
32
|
+
console.log(
|
|
33
|
+
`Only one field of type JDD found: ${field_name}, so skipping the question...`
|
|
34
|
+
);
|
|
35
|
+
} else if (jdd_fields.length > 1) {
|
|
36
|
+
const response = await prompts([
|
|
37
|
+
{
|
|
38
|
+
type: "autocomplete",
|
|
39
|
+
name: "field_name",
|
|
40
|
+
message: `Which jdd field from the ${collection_name} do you want to setup the jdd-editor for?`,
|
|
41
|
+
choices: jdd_fields.map((field) => ({
|
|
42
|
+
title: field.name,
|
|
43
|
+
value: field.name,
|
|
44
|
+
})),
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
field_name = response.field_name as string;
|
|
48
|
+
} else {
|
|
49
|
+
console.error(
|
|
50
|
+
`Collection ${collection_name} does not have any fields of type JDD. Add such a field and try again.`
|
|
51
|
+
);
|
|
52
|
+
process.exit(13);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const collectionClassName = toPascalCase(collection_name);
|
|
56
|
+
|
|
57
|
+
return `import type { Context } from "koa";
|
|
58
|
+
import type { FieldNames } from "sealious";
|
|
59
|
+
import { TempstreamJSX } from "tempstream";
|
|
60
|
+
import type ${collectionClassName} from "src/back/collections/${collection_name}.js";
|
|
61
|
+
import { EditJDDField } from "@sealcode/jdd-editor";
|
|
62
|
+
import html from "src/back/html.js";
|
|
63
|
+
import { registry } from "src/back/jdd-components/registry.js";
|
|
64
|
+
import { makeJDDContext } from "src/back/jdd-context.js";
|
|
65
|
+
import { defaultHead } from "src/back/defaultHead.js";
|
|
66
|
+
|
|
67
|
+
export const actionName = "${actionName}";
|
|
68
|
+
|
|
69
|
+
export default new (class JDDCreatePreviewPage extends EditJDDField<${collectionClassName}> {
|
|
70
|
+
getCollection(ctx: Context) {
|
|
71
|
+
return ctx.$app.collections["${collection_name}"];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getJDDFieldName(): FieldNames<${collectionClassName}["fields"]> {
|
|
75
|
+
return "${field_name}";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async renderPreParameterButtons(ctx: Context) {
|
|
79
|
+
const item = await this.getItem(ctx);
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<h1>Edit ${collection_name}: {item.id}</h1>{" "}
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
})({ html, registry, makeJDDContext, defaultHead });
|
|
87
|
+
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
@@ -7,6 +7,7 @@ import { pageTemplate } from "./page.js";
|
|
|
7
7
|
import { postTemplate } from "./post.js";
|
|
8
8
|
import { redirectTemplate } from "./redirect.js";
|
|
9
9
|
import { statefulPageTemplate } from "./stateful-page.js";
|
|
10
|
+
import { jddEditorTemplate } from "./jdd-editor.js";
|
|
10
11
|
|
|
11
12
|
export const Templates = {
|
|
12
13
|
page: pageTemplate,
|
|
@@ -18,4 +19,5 @@ export const Templates = {
|
|
|
18
19
|
sreact: statefulPageTemplate,
|
|
19
20
|
lpr: LongRunningProcessTemplate,
|
|
20
21
|
jdd: jddComponentTemplate,
|
|
22
|
+
"jdd-editor": jddEditorTemplate,
|
|
21
23
|
};
|