@sealcode/sealgen 0.17.4 → 0.17.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/@types/src/templates/shared/collection-list.d.ts +1 -1
- package/lib/add-route.js +3 -2
- package/lib/forms/controls/file.test.js +0 -8
- package/lib/forms/controls/single-reference.test.js +1 -1
- package/lib/generate-routes.js +2 -2
- package/lib/templates/form.js +1 -1
- package/lib/templates/page.js +2 -2
- package/lib/templates/shared/collection-list.js +11 -16
- package/lib/test_utils/test-on-real-app.js +1 -1
- package/package.json +1 -1
- package/src/add-route.ts +3 -2
- package/src/forms/controls/file.test.ts +0 -8
- package/src/forms/controls/single-reference.test.ts +1 -1
- package/src/generate-routes.ts +3 -2
- package/src/templates/form.ts +1 -1
- package/src/templates/page.ts +2 -2
- package/src/templates/shared/collection-list.ts +11 -20
- package/src/test_utils/test-on-real-app.ts +1 -1
|
@@ -12,5 +12,5 @@ declare const default_hooks: {
|
|
|
12
12
|
post_import_js: string;
|
|
13
13
|
render_item: (collection_name: string) => string;
|
|
14
14
|
};
|
|
15
|
-
export declare function collectionListTemplate(collection_name: string, action_name: string,
|
|
15
|
+
export declare function collectionListTemplate(collection_name: string, action_name: string, _: string, _hooks?: Partial<typeof default_hooks>): Promise<string>;
|
|
16
16
|
export {};
|
package/lib/add-route.js
CHANGED
|
@@ -47,11 +47,12 @@ async function addRoute(params, app_directory = process.cwd()) {
|
|
|
47
47
|
]);
|
|
48
48
|
const { action, url, mode } = response;
|
|
49
49
|
const extension = ["list", "lpr", "page", "sreact"].includes(mode) ? "tsx" : "ts";
|
|
50
|
+
const base_file_name = escape_url_params(url) || "index";
|
|
50
51
|
const file_path = target_locreq.resolve(
|
|
51
|
-
`src/back/routes/${
|
|
52
|
+
`src/back/routes/${base_file_name}.${mode}.${extension}`
|
|
52
53
|
);
|
|
53
54
|
const test_file_path = target_locreq.resolve(
|
|
54
|
-
`src/back/routes/${
|
|
55
|
+
`src/back/routes/${base_file_name}.test.ts`
|
|
55
56
|
);
|
|
56
57
|
const template = Templates[mode];
|
|
57
58
|
if (!template) {
|
|
@@ -60,18 +60,10 @@ describe("file-control", () => {
|
|
|
60
60
|
browser = await getBrowser();
|
|
61
61
|
const context = await browser.newContext();
|
|
62
62
|
page = await context.newPage();
|
|
63
|
-
let screenshot = true;
|
|
64
|
-
(async function() {
|
|
65
|
-
while (screenshot) {
|
|
66
|
-
await page.screenshot({ path: "/home/kuba/Downloads/" + Date.now() + ".png" });
|
|
67
|
-
await sleep(100);
|
|
68
|
-
}
|
|
69
|
-
})();
|
|
70
63
|
await page.goto(`http://localhost:${port}`);
|
|
71
64
|
await page.getByRole("button", { name: "Wy\u015Blij" }).click();
|
|
72
65
|
await sleep(100);
|
|
73
66
|
assert(submit_called, "Submit not called - something prevented submit on click?");
|
|
74
|
-
screenshot = false;
|
|
75
67
|
});
|
|
76
68
|
}).timeout(1e4);
|
|
77
69
|
});
|
|
@@ -13,7 +13,7 @@ describe("single-reference.test", () => {
|
|
|
13
13
|
after(async () => {
|
|
14
14
|
await page.close();
|
|
15
15
|
});
|
|
16
|
-
it("creates minimal sealious app and adds
|
|
16
|
+
it("creates minimal sealious app and adds form using single-reference field that works", async function() {
|
|
17
17
|
const test_app = await RealAppTest.init();
|
|
18
18
|
await test_app.addFile(
|
|
19
19
|
"src/back/collections/articles.ts",
|
package/lib/generate-routes.js
CHANGED
|
@@ -42,6 +42,7 @@ async function generateRoutes() {
|
|
|
42
42
|
).map(async (fullpath) => ({
|
|
43
43
|
fullpath,
|
|
44
44
|
actionName: await extractActionName(fullpath),
|
|
45
|
+
// trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
|
|
45
46
|
url: unescape_url_params(
|
|
46
47
|
"/" + relative(
|
|
47
48
|
target_locreq.resolve("src/back/routes"),
|
|
@@ -50,8 +51,7 @@ async function generateRoutes() {
|
|
|
50
51
|
basename(fullpath).startsWith("index.") ? "../" : ""
|
|
51
52
|
)
|
|
52
53
|
).replace(/\..+/, "") + "/"
|
|
53
|
-
|
|
54
|
-
)
|
|
54
|
+
).replace(/\/\//g, "/")
|
|
55
55
|
}))
|
|
56
56
|
);
|
|
57
57
|
const routes_content = `// DO NOT EDIT! This file is generated automaticaly with npm run generate-routes
|
package/lib/templates/form.js
CHANGED
|
@@ -35,7 +35,7 @@ const defaults = {
|
|
|
35
35
|
return { canAccess: true, message: "" };
|
|
36
36
|
}`,
|
|
37
37
|
render: `async render(ctx: Context, data: FormData, show_field_errors: boolean) {
|
|
38
|
-
return html(ctx, "Form", await super.render(ctx, data, show_field_errors));
|
|
38
|
+
return html({ctx, title: "Form", description: "", body: await super.render(ctx, data, show_field_errors)});
|
|
39
39
|
}`,
|
|
40
40
|
get_initial_values: "",
|
|
41
41
|
other_methods: ""
|
package/lib/templates/page.js
CHANGED
|
@@ -4,7 +4,7 @@ async function pageTemplate(action_name, newfilefullpath) {
|
|
|
4
4
|
return `import type { Context } from "koa";
|
|
5
5
|
import { TempstreamJSX } from "tempstream";
|
|
6
6
|
import { Page } from "@sealcode/sealgen";
|
|
7
|
-
import html from "
|
|
7
|
+
import html from "src/back/html.js";
|
|
8
8
|
|
|
9
9
|
export const actionName = "${action_name}";
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ export default new (class ${action_name}Page extends Page {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
async render(ctx: Context) {
|
|
18
|
-
return html(ctx, "${action_name}", <div></div
|
|
18
|
+
return html({ ctx: ctx, title: "${action_name}", body: <div></div>, description: "" });
|
|
19
19
|
}
|
|
20
20
|
})();
|
|
21
21
|
`;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { extractCollectionClassname } from "../../generate-collections.js";
|
|
2
2
|
import extract_fields_from_collection from "../../utils/extract-fields-from-collection.js";
|
|
3
3
|
import _locreq from "locreq";
|
|
4
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
5
4
|
import { DefaultListFilters } from "../../page/default-list-filters.js";
|
|
6
5
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
7
6
|
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
8
7
|
const target_locreq = _locreq(process.cwd());
|
|
9
|
-
function fieldImport({ type }
|
|
8
|
+
function fieldImport({ type }) {
|
|
10
9
|
if (type == "image") {
|
|
11
10
|
return `
|
|
12
11
|
import type { FilePointer } from "@sealcode/file-manager";
|
|
13
|
-
import { imageRouter } from "
|
|
12
|
+
import { imageRouter } from ""src/back/image-router.js";
|
|
14
13
|
`;
|
|
15
14
|
}
|
|
16
15
|
return "";
|
|
@@ -73,7 +72,7 @@ const default_hooks = {
|
|
|
73
72
|
</tr>;
|
|
74
73
|
}`
|
|
75
74
|
};
|
|
76
|
-
async function collectionListTemplate(collection_name, action_name,
|
|
75
|
+
async function collectionListTemplate(collection_name, action_name, _, _hooks = {}) {
|
|
77
76
|
const hooks = { ...default_hooks, ..._hooks };
|
|
78
77
|
const [uppercase_collection, collection_fields] = await Promise.all([
|
|
79
78
|
extractCollectionClassname(
|
|
@@ -83,20 +82,15 @@ async function collectionListTemplate(collection_name, action_name, newfilefullp
|
|
|
83
82
|
),
|
|
84
83
|
extract_fields_from_collection(collection_name)
|
|
85
84
|
]);
|
|
86
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
87
85
|
const field_import_string = Array.from(
|
|
88
|
-
new Set(
|
|
89
|
-
collection_fields.map((field) => fieldImport(field, importPath))
|
|
90
|
-
)
|
|
86
|
+
new Set(collection_fields.map((field) => fieldImport(field)))
|
|
91
87
|
).join("\n");
|
|
92
88
|
const result = `import type { Context } from "koa";
|
|
93
89
|
import type { CollectionItem } from "sealious";
|
|
94
90
|
import type { FlatTemplatable, Templatable } from "tempstream";
|
|
95
91
|
import { TempstreamJSX, tempstream } from "tempstream";
|
|
96
|
-
import { ${uppercase_collection} } from "
|
|
97
|
-
|
|
98
|
-
)}";
|
|
99
|
-
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
92
|
+
import { ${uppercase_collection} } from "src/back/collections/collections.js";
|
|
93
|
+
import html from "src/back/html.js";
|
|
100
94
|
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
101
95
|
import {
|
|
102
96
|
SealiousItemListPage,
|
|
@@ -203,16 +197,17 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
203
197
|
}
|
|
204
198
|
|
|
205
199
|
async render(ctx: Context) {
|
|
206
|
-
return html(
|
|
200
|
+
return html({
|
|
207
201
|
ctx,
|
|
208
|
-
"${action_name}",
|
|
209
|
-
|
|
202
|
+
title: "${action_name}",
|
|
203
|
+
description: "",
|
|
204
|
+
body: <div class="sealious-list-wrapper ${toKebabCase(action_name)}--wrapper">
|
|
210
205
|
${hooks.pre_header_html}
|
|
211
206
|
<h2>${action_name} List</h2>
|
|
212
207
|
${hooks.post_header_html}
|
|
213
208
|
{super.render(ctx)}
|
|
214
209
|
</div>
|
|
215
|
-
);
|
|
210
|
+
});
|
|
216
211
|
}
|
|
217
212
|
|
|
218
213
|
})(${uppercase_collection});
|
|
@@ -10,7 +10,7 @@ import { module_dirname } from "../utils/module-dirname.js";
|
|
|
10
10
|
import EventEmitter from "events";
|
|
11
11
|
const locreq = _locreq(module_dirname(import.meta.url));
|
|
12
12
|
const callSealgenBin = () => `node ${locreq.resolve("lib/cli.js")}`;
|
|
13
|
-
const sealious_minimal_commit = "
|
|
13
|
+
const sealious_minimal_commit = "833e70c";
|
|
14
14
|
class RealAppTest {
|
|
15
15
|
constructor() {
|
|
16
16
|
this.emitter = new EventEmitter();
|
package/package.json
CHANGED
package/src/add-route.ts
CHANGED
|
@@ -58,11 +58,12 @@ export async function addRoute(
|
|
|
58
58
|
? "tsx"
|
|
59
59
|
: "ts";
|
|
60
60
|
|
|
61
|
+
const base_file_name = escape_url_params(url) || "index";
|
|
61
62
|
const file_path = target_locreq.resolve(
|
|
62
|
-
`src/back/routes/${
|
|
63
|
+
`src/back/routes/${base_file_name}.${mode}.${extension}`
|
|
63
64
|
);
|
|
64
65
|
const test_file_path = target_locreq.resolve(
|
|
65
|
-
`src/back/routes/${
|
|
66
|
+
`src/back/routes/${base_file_name}.test.ts`
|
|
66
67
|
);
|
|
67
68
|
const template = Templates[mode as keyof typeof Templates];
|
|
68
69
|
|
|
@@ -69,19 +69,11 @@ describe("file-control", () => {
|
|
|
69
69
|
browser = await getBrowser();
|
|
70
70
|
const context = await browser.newContext();
|
|
71
71
|
page = await context.newPage();
|
|
72
|
-
let screenshot = true;
|
|
73
|
-
(async function () {
|
|
74
|
-
while (screenshot) {
|
|
75
|
-
await page.screenshot({ path: "/home/kuba/Downloads/" + Date.now() + ".png" });
|
|
76
|
-
await sleep(100);
|
|
77
|
-
}
|
|
78
|
-
})();
|
|
79
72
|
await page.goto(`http://localhost:${port}`);
|
|
80
73
|
|
|
81
74
|
await page.getByRole("button", { name: "Wyślij" }).click();
|
|
82
75
|
await sleep(100);
|
|
83
76
|
assert(submit_called, "Submit not called - something prevented submit on click?");
|
|
84
|
-
screenshot = false;
|
|
85
77
|
});
|
|
86
78
|
}).timeout(10000);
|
|
87
79
|
});
|
|
@@ -17,7 +17,7 @@ describe("single-reference.test", () => {
|
|
|
17
17
|
await page.close();
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
it("creates minimal sealious app and adds
|
|
20
|
+
it("creates minimal sealious app and adds form using single-reference field that works", async function () {
|
|
21
21
|
const test_app = await RealAppTest.init();
|
|
22
22
|
|
|
23
23
|
// add possiblity to modify templates (form and collection) and create test case
|
package/src/generate-routes.ts
CHANGED
|
@@ -61,6 +61,7 @@ export async function generateRoutes(): Promise<void> {
|
|
|
61
61
|
.map(async (fullpath) => ({
|
|
62
62
|
fullpath,
|
|
63
63
|
actionName: await extractActionName(fullpath),
|
|
64
|
+
// trailing slash is important here, as it enables to use the entire path while building relative URLs. For example, while visiting /users/123, the path ./add-photo leads to /users/add-photo. While visiting /users/123/ (note the trailing slash), the path ./add-photo leads to /users/123/add-photo
|
|
64
65
|
url: unescape_url_params(
|
|
65
66
|
"/" +
|
|
66
67
|
relative(
|
|
@@ -72,8 +73,8 @@ export async function generateRoutes(): Promise<void> {
|
|
|
72
73
|
: ""
|
|
73
74
|
)
|
|
74
75
|
).replace(/\..+/, "") +
|
|
75
|
-
"/"
|
|
76
|
-
),
|
|
76
|
+
"/"
|
|
77
|
+
).replace(/\/\//g, "/"),
|
|
77
78
|
}))
|
|
78
79
|
);
|
|
79
80
|
|
package/src/templates/form.ts
CHANGED
|
@@ -36,7 +36,7 @@ const defaults = {
|
|
|
36
36
|
return { canAccess: true, message: "" };
|
|
37
37
|
}`,
|
|
38
38
|
render: `async render(ctx: Context, data: FormData, show_field_errors: boolean) {
|
|
39
|
-
return html(ctx, "Form", await super.render(ctx, data, show_field_errors));
|
|
39
|
+
return html({ctx, title: "Form", description: "", body: await super.render(ctx, data, show_field_errors)});
|
|
40
40
|
}`,
|
|
41
41
|
get_initial_values: "",
|
|
42
42
|
other_methods: "",
|
package/src/templates/page.ts
CHANGED
|
@@ -7,7 +7,7 @@ export async function pageTemplate(
|
|
|
7
7
|
return `import type { Context } from "koa";
|
|
8
8
|
import { TempstreamJSX } from "tempstream";
|
|
9
9
|
import { Page } from "@sealcode/sealgen";
|
|
10
|
-
import html from "
|
|
10
|
+
import html from "src/back/html.js";
|
|
11
11
|
|
|
12
12
|
export const actionName = "${action_name}";
|
|
13
13
|
|
|
@@ -18,7 +18,7 @@ export default new (class ${action_name}Page extends Page {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
async render(ctx: Context) {
|
|
21
|
-
return html(ctx, "${action_name}", <div></div
|
|
21
|
+
return html({ ctx: ctx, title: "${action_name}", body: <div></div>, description: "" });
|
|
22
22
|
}
|
|
23
23
|
})();
|
|
24
24
|
`;
|
|
@@ -3,20 +3,16 @@ import extract_fields_from_collection, {
|
|
|
3
3
|
ExtractedFieldInfo,
|
|
4
4
|
} from "../../utils/extract-fields-from-collection.js";
|
|
5
5
|
import _locreq from "locreq";
|
|
6
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
7
6
|
import { DefaultListFilters } from "../../page/default-list-filters.js";
|
|
8
7
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
9
8
|
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
10
9
|
const target_locreq = _locreq(process.cwd());
|
|
11
10
|
|
|
12
|
-
function fieldImport(
|
|
13
|
-
{ type }: ExtractedFieldInfo,
|
|
14
|
-
importPath: (path: string) => string
|
|
15
|
-
): string {
|
|
11
|
+
function fieldImport({ type }: ExtractedFieldInfo): string {
|
|
16
12
|
if (type == "image") {
|
|
17
13
|
return `
|
|
18
14
|
import type { FilePointer } from "@sealcode/file-manager";
|
|
19
|
-
import { imageRouter } from "
|
|
15
|
+
import { imageRouter } from ""src/back/image-router.js";
|
|
20
16
|
`;
|
|
21
17
|
}
|
|
22
18
|
return "";
|
|
@@ -100,7 +96,7 @@ const default_hooks = {
|
|
|
100
96
|
export async function collectionListTemplate(
|
|
101
97
|
collection_name: string,
|
|
102
98
|
action_name: string,
|
|
103
|
-
|
|
99
|
+
_: string,
|
|
104
100
|
_hooks: Partial<typeof default_hooks> = {}
|
|
105
101
|
) {
|
|
106
102
|
const hooks = { ...default_hooks, ..._hooks };
|
|
@@ -112,22 +108,16 @@ export async function collectionListTemplate(
|
|
|
112
108
|
),
|
|
113
109
|
extract_fields_from_collection(collection_name),
|
|
114
110
|
]);
|
|
115
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
116
|
-
|
|
117
111
|
const field_import_string = Array.from(
|
|
118
|
-
new Set(
|
|
119
|
-
collection_fields.map((field) => fieldImport(field, importPath))
|
|
120
|
-
)
|
|
112
|
+
new Set(collection_fields.map((field) => fieldImport(field)))
|
|
121
113
|
).join("\n");
|
|
122
114
|
|
|
123
115
|
const result = `import type { Context } from "koa";
|
|
124
116
|
import type { CollectionItem } from "sealious";
|
|
125
117
|
import type { FlatTemplatable, Templatable } from "tempstream";
|
|
126
118
|
import { TempstreamJSX, tempstream } from "tempstream";
|
|
127
|
-
import { ${uppercase_collection} } from "
|
|
128
|
-
|
|
129
|
-
)}";
|
|
130
|
-
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
119
|
+
import { ${uppercase_collection} } from "src/back/collections/collections.js";
|
|
120
|
+
import html from "src/back/html.js";
|
|
131
121
|
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
132
122
|
import {
|
|
133
123
|
SealiousItemListPage,
|
|
@@ -234,16 +224,17 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
234
224
|
}
|
|
235
225
|
|
|
236
226
|
async render(ctx: Context) {
|
|
237
|
-
return html(
|
|
227
|
+
return html({
|
|
238
228
|
ctx,
|
|
239
|
-
"${action_name}",
|
|
240
|
-
|
|
229
|
+
title: "${action_name}",
|
|
230
|
+
description: "",
|
|
231
|
+
body: <div class="sealious-list-wrapper ${toKebabCase(action_name)}--wrapper">
|
|
241
232
|
${hooks.pre_header_html}
|
|
242
233
|
<h2>${action_name} List</h2>
|
|
243
234
|
${hooks.post_header_html}
|
|
244
235
|
{super.render(ctx)}
|
|
245
236
|
</div>
|
|
246
|
-
);
|
|
237
|
+
});
|
|
247
238
|
}
|
|
248
239
|
|
|
249
240
|
})(${uppercase_collection});
|
|
@@ -15,7 +15,7 @@ const locreq = _locreq(module_dirname(import.meta.url));
|
|
|
15
15
|
|
|
16
16
|
export const callSealgenBin = () => `node ${locreq.resolve("lib/cli.js")}`;
|
|
17
17
|
|
|
18
|
-
const sealious_minimal_commit = "
|
|
18
|
+
const sealious_minimal_commit = "833e70c";
|
|
19
19
|
|
|
20
20
|
export class RealAppTest {
|
|
21
21
|
public node_pid: number;
|