@sealcode/sealgen 0.8.48 → 0.8.49
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/.log/ti-107027.log +576 -0
- package/.log/ti-129414.log +1355 -0
- package/.log/ti-135707.log +1049 -0
- package/.log/ti-136226.log +1049 -0
- package/.log/ti-147652.log +533 -0
- package/.log/ti-157088.log +2938 -0
- package/.log/ti-250667.log +548 -0
- package/.log/ti-29438.log +165 -0
- package/.log/ti-29894.log +149 -0
- package/.log/ti-33785.log +149 -0
- package/.log/ti-34262.log +149 -0
- package/.log/ti-35719.log +149 -0
- package/.log/ti-41629.log +518 -0
- package/.log/ti-441248.log +517 -0
- package/.log/ti-5352.log +517 -0
- package/.log/ti-76335.log +639 -0
- package/.log/ti-811639.log +517 -0
- package/.log/ti-81805.log +564 -0
- package/.log/ti-86459.log +517 -0
- package/.log/tsserver.log +6881 -0
- package/.log/tsserver.sync-conflict-20221010-222251-JUX7UR2.log +9412 -0
- package/package.json +1 -1
- package/src/add-collection.ts +31 -0
- package/src/add-route.test.ts +58 -0
- package/src/add-route.ts +89 -0
- package/src/build.ts +94 -0
- package/src/cli.ts +36 -0
- package/src/components/components.ts +2 -0
- package/src/components/tabs.ts +95 -0
- package/src/components/toggle-modal.ts +52 -0
- package/src/example.test.ts +3 -0
- package/src/find-scss-includes.ts +32 -0
- package/src/forms/controls/array.ts +226 -0
- package/src/forms/controls/autocomplete.ts +33 -0
- package/src/forms/controls/big-radio-group.ts +48 -0
- package/src/forms/controls/checkbox-group.ts +71 -0
- package/src/forms/controls/checkbox.ts +34 -0
- package/src/forms/controls/checkboxed-list-input.ts +50 -0
- package/src/forms/controls/collapsible-checkbox-group.ts +28 -0
- package/src/forms/controls/collapsible-field-group.ts +94 -0
- package/src/forms/controls/controls.ts +30 -0
- package/src/forms/controls/derived-frame.ts +91 -0
- package/src/forms/controls/derived.ts +108 -0
- package/src/forms/controls/dropdown.ts +87 -0
- package/src/forms/controls/editable-collection-subset.ts +97 -0
- package/src/forms/controls/field-group.ts +69 -0
- package/src/forms/controls/file.ts +47 -0
- package/src/forms/controls/form-control.ts +24 -0
- package/src/forms/controls/form-field-control.ts +22 -0
- package/src/forms/controls/form-header.ts +19 -0
- package/src/forms/controls/form-paragraph.ts +11 -0
- package/src/forms/controls/frame.ts +26 -0
- package/src/forms/controls/hidden-input.ts +22 -0
- package/src/forms/controls/html.ts +38 -0
- package/src/forms/controls/multiple-files.ts +256 -0
- package/src/forms/controls/multiple-photos.ts +44 -0
- package/src/forms/controls/number.ts +38 -0
- package/src/forms/controls/photo.ts +74 -0
- package/src/forms/controls/radio.ts +43 -0
- package/src/forms/controls/reverse-single-reference.ts +50 -0
- package/src/forms/controls/simple-input.ts +148 -0
- package/src/forms/controls/textarea.ts +60 -0
- package/src/forms/controls/tickable.ts +127 -0
- package/src/forms/fields/boolean.test.ts +36 -0
- package/src/forms/fields/boolean.ts +63 -0
- package/src/forms/fields/checkboxed-list.ts +66 -0
- package/src/forms/fields/collection-field.ts +62 -0
- package/src/forms/fields/email.test.ts +24 -0
- package/src/forms/fields/email.ts +20 -0
- package/src/forms/fields/enum-multiple.test.ts +31 -0
- package/src/forms/fields/enum-multiple.ts +62 -0
- package/src/forms/fields/enum.test.ts +25 -0
- package/src/forms/fields/enum.ts +56 -0
- package/src/forms/fields/existing-sealious-value.ts +22 -0
- package/src/forms/fields/field.ts +172 -0
- package/src/forms/fields/file.ts +89 -0
- package/src/forms/fields/multiple-files.ts +20 -0
- package/src/forms/fields/number.test.ts +34 -0
- package/src/forms/fields/number.ts +70 -0
- package/src/forms/fields/pick-from-list.test.ts +19 -0
- package/src/forms/fields/pick-from-list.ts +52 -0
- package/src/forms/fields/proxy-field.ts +24 -0
- package/src/forms/fields/regexp.test.ts +25 -0
- package/src/forms/fields/regexp.ts +53 -0
- package/src/forms/fields/reverse-single-reference.ts +20 -0
- package/src/forms/fields/simple-form-field.ts +30 -0
- package/src/forms/fields/structured-array.ts +27 -0
- package/src/forms/form.test.ts +351 -0
- package/src/forms/form.ts +294 -0
- package/src/forms/forms.scss +85 -0
- package/src/forms/multiform.test.ts +540 -0
- package/src/forms/multiform.ts +236 -0
- package/src/generate-collections.ts +77 -0
- package/src/generate-routes.ts +121 -0
- package/src/index.ts +25 -0
- package/src/make-env.ts +15 -0
- package/src/make-hidden-inputs.ts +24 -0
- package/src/mount.ts +85 -0
- package/src/page/access-control.ts +18 -0
- package/src/page/list.ts +240 -0
- package/src/page/mountable-with-fields.ts +158 -0
- package/src/page/mountable.ts +13 -0
- package/src/page/page.ts +46 -0
- package/src/page/props-parser.ts +38 -0
- package/src/page/stateful-page.ts +202 -0
- package/src/run.ts +0 -0
- package/src/sanitize.ts +9 -0
- package/src/templates/collection.ts +11 -0
- package/src/templates/form.ts +60 -0
- package/src/templates/list.ts +75 -0
- package/src/templates/multiform.ts +58 -0
- package/src/templates/page.ts +25 -0
- package/src/templates/post.ts +21 -0
- package/src/templates/redirect.ts +22 -0
- package/src/templates/route-test.ts +27 -0
- package/src/templates/stateful-page.ts +65 -0
- package/src/test_utils/locator_is_visible.ts +17 -0
- package/src/utils/assert-throws.ts +18 -0
- package/src/utils/base64.ts +7 -0
- package/src/utils/browser-creator.js +10 -0
- package/src/utils/escape-url-params.ts +14 -0
- package/src/utils/exec.ts +30 -0
- package/src/utils/format-external-url.ts +13 -0
- package/src/utils/import-path.ts +25 -0
- package/src/utils/input-wrapper.ts +21 -0
- package/src/utils/list-collections.ts +16 -0
- package/src/utils/make-slug.ts +5 -0
- package/src/utils/natural-numbers.ts +5 -0
- package/src/utils/prettier.ts +13 -0
- package/src/utils/question.ts +23 -0
- package/src/utils/render-attributes.ts +17 -0
- package/src/utils/sleep.ts +3 -0
- package/src/utils/translate.ts +13 -0
- package/src/utils/url-with-new-params.ts +9 -0
- package/src/utils/utils.ts +23 -0
- package/src/utils/walk.ts +20 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function collectionTemplate(collection_name: string) {
|
|
2
|
+
return `import { Collection, FieldTypes, Policies } from "sealious";
|
|
3
|
+
|
|
4
|
+
export default class ${collection_name} extends Collection {
|
|
5
|
+
fields = {
|
|
6
|
+
content: new FieldTypes.Text(),
|
|
7
|
+
};
|
|
8
|
+
defaultPolicy = new Policies.Public();
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
|
|
3
|
+
export async function formTemplate(
|
|
4
|
+
action_name: string,
|
|
5
|
+
newfilefullpath: string
|
|
6
|
+
): Promise<string> {
|
|
7
|
+
const rel = curryImportPath(newfilefullpath);
|
|
8
|
+
return `import { Context } from "koa";
|
|
9
|
+
import { Form, FormData, FormDataValue, Fields, Controls } from "@sealcode/sealgen";
|
|
10
|
+
import html from "${rel("src/back/html")}";
|
|
11
|
+
import { Users } from "${rel("src/back/collections/collections")}";
|
|
12
|
+
|
|
13
|
+
export const actionName = "${action_name}";
|
|
14
|
+
|
|
15
|
+
const fields = {
|
|
16
|
+
email: new Fields.CollectionField(true, Users.fields.email),
|
|
17
|
+
password: new Fields.SimpleFormField(true),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const ${action_name}Shape = Fields.fieldsToShape(fields);
|
|
21
|
+
|
|
22
|
+
export default new (class ${action_name}Form extends Form<typeof fields, void> {
|
|
23
|
+
defaultSuccessMessage = "Formularz wypełniony poprawnie";
|
|
24
|
+
fields = fields;
|
|
25
|
+
|
|
26
|
+
controls = [
|
|
27
|
+
new Controls.SimpleInput(fields.email, { label: "Email:", type: "email" }),
|
|
28
|
+
new Controls.SimpleInput(fields.password, { label: "Password:", type: "password" }),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
async validateValues(
|
|
32
|
+
ctx: Context,
|
|
33
|
+
data: Record<string, FormDataValue>
|
|
34
|
+
): Promise<{ valid: boolean; error: string }> {
|
|
35
|
+
// just an example
|
|
36
|
+
const { parsed: email } = await this.fields.email.getValue(ctx, data);
|
|
37
|
+
const { parsed: password } = await this.fields.password.getValue(ctx, data);
|
|
38
|
+
if ((password || "").length > (email || "").length) {
|
|
39
|
+
return { valid: false, error: "Password cannot be longer than email" };
|
|
40
|
+
} else {
|
|
41
|
+
return { valid: true, error: "" };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
|
+
async canAccess(_: Context) {
|
|
47
|
+
return { canAccess: true, message: "" };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async onSubmit() {
|
|
51
|
+
//noop
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async render(ctx: Context, data: FormData, show_field_errors: boolean) {
|
|
56
|
+
return html(ctx, "${action_name}", await super.render(ctx, data, show_field_errors));
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
import prompts = require("prompts");
|
|
3
|
+
import { listCollections } from "../utils/list-collections";
|
|
4
|
+
|
|
5
|
+
export const listTemplate = async (
|
|
6
|
+
action_name: string,
|
|
7
|
+
newfilefullpath: string
|
|
8
|
+
): Promise<string> => {
|
|
9
|
+
const response = await prompts({
|
|
10
|
+
type: "autocomplete",
|
|
11
|
+
name: "collection",
|
|
12
|
+
message: "Which sealious collection do you want to list?",
|
|
13
|
+
choices: (
|
|
14
|
+
await listCollections()
|
|
15
|
+
).map((collection) => ({
|
|
16
|
+
title: collection,
|
|
17
|
+
value: collection,
|
|
18
|
+
})),
|
|
19
|
+
});
|
|
20
|
+
const collection = response.collection as string;
|
|
21
|
+
const uppercase_collection =
|
|
22
|
+
collection[0].toLocaleUpperCase() + collection.slice(1);
|
|
23
|
+
const rel = curryImportPath(newfilefullpath);
|
|
24
|
+
return `import { Context } from "koa";
|
|
25
|
+
import { CollectionItem } from "sealious";
|
|
26
|
+
import { tempstream } from "tempstream";
|
|
27
|
+
import { ${uppercase_collection} } from "${rel(
|
|
28
|
+
"src/back/collections/collections"
|
|
29
|
+
)}";
|
|
30
|
+
import html from "${rel("src/back/html.ts")}";
|
|
31
|
+
import { SealiousItemListPage, BaseListPageFields } from "@sealcode/sealgen";
|
|
32
|
+
|
|
33
|
+
export const actionName = "${action_name}";
|
|
34
|
+
|
|
35
|
+
const filterFields = {};
|
|
36
|
+
|
|
37
|
+
export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
38
|
+
typeof ${uppercase_collection},
|
|
39
|
+
typeof BaseListPageFields
|
|
40
|
+
> {
|
|
41
|
+
fields = BaseListPageFields;
|
|
42
|
+
|
|
43
|
+
filterFields = filterFields;
|
|
44
|
+
filterControls = [];
|
|
45
|
+
|
|
46
|
+
async render(ctx: Context) {
|
|
47
|
+
return html(
|
|
48
|
+
ctx,
|
|
49
|
+
"${uppercase_collection}",
|
|
50
|
+
tempstream/* HTML */ \`<div>
|
|
51
|
+
<h2>${uppercase_collection} List</h2>
|
|
52
|
+
<table>
|
|
53
|
+
<thead>
|
|
54
|
+
<th>id</th>
|
|
55
|
+
\${Object.keys(${uppercase_collection}.fields).map(
|
|
56
|
+
(fieldname) => \`<th>\${fieldname}</th>\`
|
|
57
|
+
)}
|
|
58
|
+
</thead>
|
|
59
|
+
<tbody>
|
|
60
|
+
\${super.render(ctx)}
|
|
61
|
+
</tbody>
|
|
62
|
+
</table>
|
|
63
|
+
</div>\`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async renderItem(_: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
68
|
+
return tempstream\`<tr><td>\${item.id}</td>\${Object.keys(${uppercase_collection}.fields).map(
|
|
69
|
+
(fieldname: keyof typeof ${uppercase_collection}["fields"]) =>
|
|
70
|
+
tempstream\`<td>\${item.get(fieldname)}</td>\`
|
|
71
|
+
)}</tr>\`;
|
|
72
|
+
}
|
|
73
|
+
})(${uppercase_collection});
|
|
74
|
+
`;
|
|
75
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/utils";
|
|
2
|
+
|
|
3
|
+
export async function multiformTemplate(
|
|
4
|
+
action_name: string,
|
|
5
|
+
newfilefullpath: string
|
|
6
|
+
): Promise<string> {
|
|
7
|
+
const rel = curryImportPath(newfilefullpath);
|
|
8
|
+
return `import { Context } from "koa";
|
|
9
|
+
import html from "${rel("src/back/html")}";
|
|
10
|
+
import { Controls, Fields, Form, FormMessage, Multiform } from "@sealcode/sealgen";
|
|
11
|
+
import { FlatTemplatable } from "tempstream";
|
|
12
|
+
|
|
13
|
+
export const actionName = "${action_name}";
|
|
14
|
+
|
|
15
|
+
const fields1 = {
|
|
16
|
+
email: new Fields.SimpleFormField(true),
|
|
17
|
+
password: new Fields.SimpleFormField(true),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const form1 = new (class extends Form<typeof fields1> {
|
|
21
|
+
defaultSuccessMessage = "Form1 done!";
|
|
22
|
+
controls = [
|
|
23
|
+
new Controls.FormHeader("form1"),
|
|
24
|
+
new Controls.SimpleInput(fields1.email),
|
|
25
|
+
];
|
|
26
|
+
fields = fields1;
|
|
27
|
+
onSubmit() {
|
|
28
|
+
console.log("form1 submit");
|
|
29
|
+
}
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
const fields2 = {
|
|
33
|
+
name: new Fields.SimpleFormField(true),
|
|
34
|
+
surname: new Fields.SimpleFormField(true),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const form2 = new (class extends Form<Record<never, unknown>> {
|
|
38
|
+
defaultSuccessMessage = "Form2 done!";
|
|
39
|
+
controls = [new Controls.FormHeader("form2"), new Controls.SimpleInput(fields2.name)];
|
|
40
|
+
fields = fields2;
|
|
41
|
+
onSubmit() {
|
|
42
|
+
console.log("form2 submit");
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
|
|
46
|
+
export default new (class extends Multiform {
|
|
47
|
+
name = "multiform_test";
|
|
48
|
+
forms = { form1, form2 };
|
|
49
|
+
async render(
|
|
50
|
+
ctx: Context,
|
|
51
|
+
messages: FormMessage[],
|
|
52
|
+
prerenderedForms?: Record<string, FlatTemplatable | undefined>
|
|
53
|
+
): Promise<FlatTemplatable> {
|
|
54
|
+
return html(ctx, "${action_name}", await super.render(ctx, messages, prerenderedForms));
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
export async function pageTemplate(
|
|
3
|
+
action_name: string,
|
|
4
|
+
newfilefullpath: string
|
|
5
|
+
): Promise<string> {
|
|
6
|
+
const rel = 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")}";
|
|
11
|
+
|
|
12
|
+
export const actionName = "${action_name}";
|
|
13
|
+
|
|
14
|
+
export default new (class ${action_name}Page extends Page {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
async canAccess(_: Context) {
|
|
17
|
+
return { canAccess: true, message: "" };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async render(ctx: Context) {
|
|
21
|
+
return html(ctx, "${action_name}", tempstream/* HTML */ \`<div></div>\`);
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export async function postTemplate(action_name: string): Promise<string> {
|
|
2
|
+
return `import { Context } from "koa";
|
|
3
|
+
import { Mountable } from "@sealcode/sealgen";
|
|
4
|
+
import Router from "@koa/router";
|
|
5
|
+
|
|
6
|
+
export const actionName = "${action_name}";
|
|
7
|
+
|
|
8
|
+
export default new (class ${action_name}Redirect extends Mountable {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
async canAccess(_: Context) {
|
|
11
|
+
return { canAccess: true, message: "" };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mount(router: Router, path: string) {
|
|
15
|
+
router.post(path, async (ctx) => {
|
|
16
|
+
ctx.body = { message: "OK!" }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
})();
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export async function redirectTemplate(action_name: string): Promise<string> {
|
|
2
|
+
return `import { Context } from "koa";
|
|
3
|
+
import { Mountable } from "@sealcode/sealgen";
|
|
4
|
+
import Router from "@koa/router";
|
|
5
|
+
|
|
6
|
+
export const actionName = "${action_name}";
|
|
7
|
+
|
|
8
|
+
export default new (class ${action_name}Redirect extends Mountable {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
+
async canAccess(_: Context) {
|
|
11
|
+
return { canAccess: true, message: "" };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
mount(router: Router, path: string) {
|
|
15
|
+
router.get(path, async (ctx) => {
|
|
16
|
+
ctx.status = 302;
|
|
17
|
+
ctx.redirect("/new_url");
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
})();
|
|
21
|
+
`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
|
|
3
|
+
export function testTemplate(action_name: string, new_file_fullpath: string) {
|
|
4
|
+
const rel = curryImportPath(new_file_fullpath);
|
|
5
|
+
return `import { withProdApp } from "${rel(
|
|
6
|
+
"src/back/test_utils/with-prod-app"
|
|
7
|
+
)}";
|
|
8
|
+
import { LONG_TEST_TIMEOUT, webhintURL } from "${rel(
|
|
9
|
+
"src/back/test_utils/webhint"
|
|
10
|
+
)}";
|
|
11
|
+
import { ${action_name}URL } from "${rel("src/back/routes/urls")}";
|
|
12
|
+
|
|
13
|
+
describe("${action_name}", () => {
|
|
14
|
+
it("doesn't crash", async function () {
|
|
15
|
+
this.timeout(LONG_TEST_TIMEOUT);
|
|
16
|
+
return withProdApp(async ({ base_url, rest_api }) => {
|
|
17
|
+
await rest_api.get(${action_name}URL);
|
|
18
|
+
await webhintURL(base_url + ${action_name}URL);
|
|
19
|
+
// alternatively you can use webhintHTML for faster but less precise scans
|
|
20
|
+
// or for scanning responses of requests that use some form of authorization:
|
|
21
|
+
// const response = await rest_api.get(${action_name}URL);
|
|
22
|
+
// await webhintHTML(response);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { curryImportPath } from "../utils/import-path";
|
|
2
|
+
|
|
3
|
+
export async function statefulPageTemplate(
|
|
4
|
+
action_name: string,
|
|
5
|
+
newfilefullpath: string
|
|
6
|
+
): Promise<string> {
|
|
7
|
+
const rel = curryImportPath(newfilefullpath);
|
|
8
|
+
return `import { BaseContext } from "koa";
|
|
9
|
+
import { tempstream, Templatable } from "tempstream";
|
|
10
|
+
import { StatefulPage } from "@sealcode/sealgen";
|
|
11
|
+
import html from "${rel("src/back/html")}";
|
|
12
|
+
|
|
13
|
+
export const actionName = "${action_name}";
|
|
14
|
+
|
|
15
|
+
const actions = <const>{
|
|
16
|
+
add: (state: State, inputs: Record<string, string>) => {
|
|
17
|
+
console.log({ inputs });
|
|
18
|
+
return {
|
|
19
|
+
...state,
|
|
20
|
+
elements: [...state.elements, inputs.element_to_add || "new element"],
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
remove: (state: State, _: unknown, index_to_remove: number) => {
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
elements: state.elements.filter((_, index) => index != index_to_remove),
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type State = {
|
|
32
|
+
elements: string[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default new (class ${action_name}Page extends StatefulPage<State, typeof actions> {
|
|
36
|
+
actions = actions;
|
|
37
|
+
|
|
38
|
+
getInitialState() {
|
|
39
|
+
return { elements: ["one", "two", "three"] };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
wrapInLayout(ctx: BaseContext, content: Templatable): Templatable {
|
|
43
|
+
return html(ctx, "${action_name}", content);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
render(ctx: BaseContext, state: State, inputs: Record<string, string>) {
|
|
47
|
+
return tempstream/* HTML */ \`<ul>
|
|
48
|
+
\${state.elements.map(
|
|
49
|
+
(e, index) => /* HTML */ \`<li>
|
|
50
|
+
\${e} \${this.makeActionButton(state, "remove", index)}
|
|
51
|
+
</li>\`
|
|
52
|
+
)}
|
|
53
|
+
</ul>
|
|
54
|
+
<div>
|
|
55
|
+
<input
|
|
56
|
+
name="element_to_add"
|
|
57
|
+
type="text"
|
|
58
|
+
value="\${inputs.element_to_add || ""}"
|
|
59
|
+
/>
|
|
60
|
+
\${this.makeActionButton(state, "add")}
|
|
61
|
+
</div>\`;
|
|
62
|
+
}
|
|
63
|
+
})();
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-await-in-loop */
|
|
2
|
+
import { Locator } from "playwright";
|
|
3
|
+
import { sleep } from "../utils/sleep";
|
|
4
|
+
|
|
5
|
+
export async function locator_is_visible(
|
|
6
|
+
locator: Locator,
|
|
7
|
+
timeout = 500
|
|
8
|
+
): Promise<boolean> {
|
|
9
|
+
let exists = false;
|
|
10
|
+
while (timeout > 0 && !exists) {
|
|
11
|
+
await sleep(50);
|
|
12
|
+
timeout -= 50;
|
|
13
|
+
exists = await locator.isVisible();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return exists;
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
|
|
3
|
+
export async function assertThrowsAsync(
|
|
4
|
+
fn: () => Promise<unknown>,
|
|
5
|
+
error_handler?: (e: unknown) => Promise<void> | void
|
|
6
|
+
): Promise<void> {
|
|
7
|
+
let error: unknown = null;
|
|
8
|
+
try {
|
|
9
|
+
await fn();
|
|
10
|
+
} catch (e: unknown) {
|
|
11
|
+
error = e;
|
|
12
|
+
} finally {
|
|
13
|
+
assert.notStrictEqual(error, null, "It didn't throw");
|
|
14
|
+
if (error_handler) {
|
|
15
|
+
await error_handler(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { firefox } from "playwright";
|
|
2
|
+
|
|
3
|
+
let browser_promise = null;
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
6
|
+
export async function getBrowser() {
|
|
7
|
+
if (!browser_promise) browser_promise = firefox.launch();
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
9
|
+
return browser_promise;
|
|
10
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function escape_url_params(url: string): string {
|
|
2
|
+
return url
|
|
3
|
+
.split("/")
|
|
4
|
+
.map((e) => (e.startsWith(":") ? `[${e.slice(1)}]` : e))
|
|
5
|
+
.filter((e) => e != "")
|
|
6
|
+
.join("/");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function unescape_url_params(url: string): string {
|
|
10
|
+
return url
|
|
11
|
+
.split("/")
|
|
12
|
+
.map((e) => (e.startsWith("[") ? `:${e.slice(1, e.length - 1)}` : e))
|
|
13
|
+
.join("/");
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
|
|
4
|
+
export async function exec(
|
|
5
|
+
program: string,
|
|
6
|
+
args: string[]
|
|
7
|
+
): Promise<{ stderr: string; stdout: string; exitCode: number }> {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
let stdout = "";
|
|
10
|
+
let stderr = "";
|
|
11
|
+
const process = spawn(program, args);
|
|
12
|
+
process.stdout.on(
|
|
13
|
+
"data",
|
|
14
|
+
(data: Buffer) => (stdout += data.toString())
|
|
15
|
+
);
|
|
16
|
+
process.stderr.on(
|
|
17
|
+
"data",
|
|
18
|
+
(data: Buffer) => (stderr += data.toString())
|
|
19
|
+
);
|
|
20
|
+
process.on("close", (exitCode) => {
|
|
21
|
+
if (exitCode === 0) {
|
|
22
|
+
resolve({ stdout, stderr, exitCode });
|
|
23
|
+
} else {
|
|
24
|
+
console.error([program, ...args].join(" "));
|
|
25
|
+
console.error(stderr);
|
|
26
|
+
reject({ stdout, stderr, exitCode });
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// this is not an ultra-safe parser. It's meant to help parse urls that users
|
|
2
|
+
// have entered in a simple input file withour validation
|
|
3
|
+
|
|
4
|
+
export function formatExternalURL(url: string) {
|
|
5
|
+
const trimmed = url.trim();
|
|
6
|
+
if (
|
|
7
|
+
!trimmed.toLowerCase().startsWith("https://") ||
|
|
8
|
+
!trimmed.toLowerCase().startsWith("https://")
|
|
9
|
+
) {
|
|
10
|
+
return `http://${trimmed}`;
|
|
11
|
+
}
|
|
12
|
+
return trimmed;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { relative, dirname } from "path";
|
|
2
|
+
import _locreq from "locreq";
|
|
3
|
+
const target_locreq = _locreq(process.cwd());
|
|
4
|
+
|
|
5
|
+
export function importPath(
|
|
6
|
+
project_module_path: string,
|
|
7
|
+
project_target_path: string
|
|
8
|
+
): string {
|
|
9
|
+
let result = relative(
|
|
10
|
+
dirname(target_locreq.resolve(project_module_path)),
|
|
11
|
+
target_locreq.resolve(project_target_path).replace(/.ts$/, "")
|
|
12
|
+
);
|
|
13
|
+
if (result[0] != ".") {
|
|
14
|
+
result = "./" + result;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function curryImportPath(
|
|
20
|
+
project_module_path: string
|
|
21
|
+
): (project_target_path: string) => string {
|
|
22
|
+
return function (project_target_path: string) {
|
|
23
|
+
return importPath(project_module_path, project_target_path);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
2
|
+
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
|
+
|
|
4
|
+
export function getRequiredClass(isRequired: boolean): string {
|
|
5
|
+
return isRequired ? "required" : "";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function getModifierClasses(modifiers: string[]) {
|
|
9
|
+
return modifiers.map((m) => "form-input__wrapper--" + m).join(" ");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function inputWrapper(
|
|
13
|
+
modifiers: string[],
|
|
14
|
+
input: FlatTemplatable
|
|
15
|
+
): Readable {
|
|
16
|
+
return tempstream/* HTML */ `<div
|
|
17
|
+
class="form-input form-input__wrapper ${getModifierClasses(modifiers)}"
|
|
18
|
+
>
|
|
19
|
+
${input}
|
|
20
|
+
</div>`;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _locreq from "locreq";
|
|
2
|
+
import { walkDir } from "./walk";
|
|
3
|
+
const target_locreq = _locreq(process.cwd());
|
|
4
|
+
|
|
5
|
+
export async function listCollections(): Promise<string[]> {
|
|
6
|
+
const files = await walkDir(target_locreq.resolve("src/back/collections"));
|
|
7
|
+
return files
|
|
8
|
+
.filter(
|
|
9
|
+
(f) =>
|
|
10
|
+
f.endsWith(".ts") &&
|
|
11
|
+
!f.endsWith(".test.ts") &&
|
|
12
|
+
!f.endsWith("collections.ts")
|
|
13
|
+
)
|
|
14
|
+
.map((f) => f.replace(/.ts$/, "").split("/").at(-1) || "")
|
|
15
|
+
.filter((e) => e !== "");
|
|
16
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as prettier from "prettier";
|
|
2
|
+
import { Options } from "prettier";
|
|
3
|
+
import _locreq from "locreq";
|
|
4
|
+
const target_locreq = _locreq(process.cwd());
|
|
5
|
+
|
|
6
|
+
export async function getPrettierConfig(): Promise<Options> {
|
|
7
|
+
return {
|
|
8
|
+
...(await prettier.resolveConfig(
|
|
9
|
+
target_locreq.resolve("src/back/routes")
|
|
10
|
+
)),
|
|
11
|
+
parser: "typescript",
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createInterface } from "readline";
|
|
2
|
+
|
|
3
|
+
export async function question(
|
|
4
|
+
text: string,
|
|
5
|
+
validator: (answer: string) => boolean
|
|
6
|
+
) {
|
|
7
|
+
const rl = createInterface({
|
|
8
|
+
input: process.stdin,
|
|
9
|
+
output: process.stdout,
|
|
10
|
+
});
|
|
11
|
+
let answer = "";
|
|
12
|
+
while (answer == "" || !validator(answer)) {
|
|
13
|
+
// eslint-disable-next-line no-await-in-loop
|
|
14
|
+
answer = await new Promise((resolve) => rl.question(text, resolve));
|
|
15
|
+
if (!validator(answer)) {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.log("Try again");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
rl.close();
|
|
22
|
+
return answer;
|
|
23
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { attribute } from "../sanitize";
|
|
2
|
+
|
|
3
|
+
export function renderAttributes(attrs: Record<string, string | boolean>) {
|
|
4
|
+
return Object.entries(attrs)
|
|
5
|
+
.map(([key, value]) => {
|
|
6
|
+
if (typeof value === "boolean") {
|
|
7
|
+
if (value) {
|
|
8
|
+
return key;
|
|
9
|
+
} else {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
} else {
|
|
13
|
+
return `${key}="${attribute(value)}"`;
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
.join(" ");
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { Translation } from "sealious";
|
|
3
|
+
|
|
4
|
+
export function t(
|
|
5
|
+
ctx: Context,
|
|
6
|
+
key: string,
|
|
7
|
+
props: any[],
|
|
8
|
+
default_translation: Translation
|
|
9
|
+
) {
|
|
10
|
+
return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}"
|
|
11
|
+
>${ctx.$app.getString(key, props, default_translation)}</span
|
|
12
|
+
>`;
|
|
13
|
+
}
|