@sealcode/sealgen 0.19.0 → 0.19.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/forms/fields/deep-reverse-single-reference-list.d.ts +1 -5
- package/@types/forms/fields/file.d.ts +1 -1
- package/@types/forms/fields/password.d.ts +1 -2
- package/@types/forms/fields/simple-form-field.d.ts +4 -4
- package/@types/forms/fields/single-reference.d.ts +1 -1
- package/@types/register-external.d.ts +2 -2
- package/@types/templates/form.d.ts +1 -3
- package/@types/templates/jdd-component.d.ts +1 -1
- package/@types/templates/page.d.ts +1 -1
- package/@types/templates/shared/shared-crud-form-fields.d.ts +1 -1
- package/@types/templates/templates.d.ts +1 -21
- package/eslint.config.mjs +56 -0
- package/lib/add-crud.js +1 -4
- package/lib/add-jdd-component.js +3 -3
- package/lib/add-route.js +2 -2
- package/lib/build.js +3 -3
- package/lib/builders/backend-ts-builder.js +0 -1
- package/lib/builders/colors-builder.js +11 -8
- package/lib/builders/fonts-builder.js +0 -1
- package/lib/builders/frontend-ts-builder.js +0 -1
- package/lib/cli.js +2 -2
- package/lib/components/tabs.js +36 -36
- package/lib/esbuild-plugins/rewrite-asset-imports.js +7 -10
- package/lib/forms/controls/array.js +5 -6
- package/lib/forms/controls/checkboxed-list-input.js +1 -2
- package/lib/forms/controls/checkboxed-list-input.test.js +6 -6
- package/lib/forms/controls/derived-frame.js +3 -3
- package/lib/forms/controls/dropdown.js +1 -2
- package/lib/forms/controls/file.test.js +1 -1
- package/lib/forms/controls/form-control.js +1 -1
- package/lib/forms/controls/image.test.js +2 -2
- package/lib/forms/controls/single-reference.test.js +1 -1
- package/lib/forms/controls/table.js +10 -15
- package/lib/forms/controls/textarea.js +1 -1
- package/lib/forms/fields/deep-reverse-single-reference-list.js +1 -1
- package/lib/forms/fields/field.test.js +3 -3
- package/lib/forms/fields/file.js +1 -1
- package/lib/forms/fields/file.test.js +1 -1
- package/lib/forms/fields/password.js +1 -1
- package/lib/forms/fields/simple-form-field.js +4 -3
- package/lib/forms/fields/single-reference.js +1 -1
- package/lib/forms/fields/structured-array.js +0 -2
- package/lib/forms/fields/table.js +1 -1
- package/lib/forms/form.js +0 -1
- package/lib/forms/form.test.js +2 -3
- package/lib/forms/multiform.js +6 -7
- package/lib/forms/multiform.test.js +2 -2
- package/lib/generate-collections.js +2 -3
- package/lib/generate-components.js +2 -3
- package/lib/generate-routes.js +3 -5
- package/lib/generate-routes.test.js +7 -16
- package/lib/generate-stimulus.js +4 -5
- package/lib/get-fonts.js +29 -27
- package/lib/make-env.js +1 -1
- package/lib/make-hidden-inputs.js +4 -4
- package/lib/mount.js +0 -1
- package/lib/notifier.js +3 -3
- package/lib/page/list.js +5 -7
- package/lib/page/mountable.js +0 -1
- package/lib/page/page.js +0 -1
- package/lib/register-external.js +4 -4
- package/lib/templates/form.js +1 -1
- package/lib/templates/jdd-component.js +1 -1
- package/lib/templates/jdd-editor.js +1 -1
- package/lib/templates/page.js +1 -1
- package/lib/templates/shared/collection-create-form.js +4 -5
- package/lib/templates/shared/collection-edit-form.js +4 -5
- package/lib/templates/shared/collection-list.js +2 -2
- package/lib/templates/shared/shared-crud-form-fields.js +3 -5
- package/lib/test_utils/exec_async.js +3 -3
- package/lib/test_utils/test-on-real-app.js +9 -11
- package/lib/utils/write-file.js +1 -1
- package/package.json +9 -8
- package/src/add-collection.ts +1 -3
- package/src/add-crud.ts +2 -7
- package/src/add-jdd-component.ts +4 -5
- package/src/add-route.ts +3 -6
- package/src/build.ts +3 -3
- package/src/builders/backend-ts-builder.ts +0 -1
- package/src/builders/builder.ts +4 -1
- package/src/builders/colors-builder.ts +11 -9
- package/src/builders/css-builder.ts +4 -1
- package/src/builders/fonts-builder.ts +0 -1
- package/src/builders/frontend-ts-builder.ts +0 -1
- package/src/cli.ts +2 -2
- package/src/components/tabs.ts +38 -37
- package/src/components/toggle-modal.ts +1 -1
- package/src/controllers/table-add-button.stimulus.ts +1 -1
- package/src/esbuild-plugins/rewrite-asset-imports.ts +7 -10
- package/src/forms/controls/array.ts +12 -16
- package/src/forms/controls/autocomplete.ts +1 -1
- package/src/forms/controls/big-radio-group.ts +2 -2
- package/src/forms/controls/checkbox-group.ts +1 -1
- package/src/forms/controls/checkboxed-list-input.test.ts +6 -6
- package/src/forms/controls/checkboxed-list-input.ts +18 -22
- package/src/forms/controls/derived-frame.ts +11 -10
- package/src/forms/controls/derived.ts +6 -5
- package/src/forms/controls/dropdown.ts +8 -11
- package/src/forms/controls/editable-collection-subset.ts +2 -1
- package/src/forms/controls/field-group.ts +1 -1
- package/src/forms/controls/file.test.ts +1 -1
- package/src/forms/controls/file.ts +4 -7
- package/src/forms/controls/form-control.ts +1 -1
- package/src/forms/controls/hidden-input.ts +1 -0
- package/src/forms/controls/html.ts +1 -0
- package/src/forms/controls/image.test.ts +2 -2
- package/src/forms/controls/image.ts +1 -1
- package/src/forms/controls/multiple-files.ts +5 -7
- package/src/forms/controls/multiple-images.ts +1 -1
- package/src/forms/controls/simple-input.ts +8 -4
- package/src/forms/controls/single-reference.test.ts +1 -1
- package/src/forms/controls/single-reference.ts +1 -1
- package/src/forms/controls/table.ts +16 -21
- package/src/forms/controls/textarea.ts +1 -1
- package/src/forms/controls/tickable.ts +0 -2
- package/src/forms/fields/boolean.ts +4 -1
- package/src/forms/fields/checkboxed-list.ts +1 -1
- package/src/forms/fields/collection-field.ts +5 -2
- package/src/forms/fields/color.ts +1 -1
- package/src/forms/fields/coordinates.ts +2 -2
- package/src/forms/fields/deep-reverse-single-reference-list.ts +2 -8
- package/src/forms/fields/deep-reverse-single-reference-table.ts +1 -1
- package/src/forms/fields/email.ts +1 -1
- package/src/forms/fields/enum-multiple-sealious.ts +1 -1
- package/src/forms/fields/existing-sealious-value.ts +1 -1
- package/src/forms/fields/field.test.ts +3 -3
- package/src/forms/fields/field.ts +6 -5
- package/src/forms/fields/file.test.ts +1 -1
- package/src/forms/fields/file.ts +2 -2
- package/src/forms/fields/float.ts +1 -1
- package/src/forms/fields/get-field-for-sealious.ts +97 -64
- package/src/forms/fields/int.ts +1 -1
- package/src/forms/fields/number.ts +2 -2
- package/src/forms/fields/password.ts +2 -6
- package/src/forms/fields/pick-from-list-sealious.ts +1 -1
- package/src/forms/fields/pick-from-list.ts +1 -1
- package/src/forms/fields/proxy-field.ts +1 -0
- package/src/forms/fields/simple-form-field.ts +19 -9
- package/src/forms/fields/single-reference.ts +2 -2
- package/src/forms/fields/structured-array.ts +2 -6
- package/src/forms/fields/table.ts +7 -15
- package/src/forms/fields/text.ts +1 -1
- package/src/forms/fields/url.ts +1 -1
- package/src/forms/form-types.ts +3 -4
- package/src/forms/form.test.ts +2 -3
- package/src/forms/form.ts +5 -7
- package/src/forms/multiform.test.ts +6 -6
- package/src/forms/multiform.ts +10 -10
- package/src/generate-collections.ts +2 -3
- package/src/generate-components.ts +2 -3
- package/src/generate-routes.test.ts +7 -16
- package/src/generate-routes.ts +6 -10
- package/src/generate-stimulus.ts +4 -6
- package/src/get-fonts.ts +32 -30
- package/src/make-env.ts +1 -1
- package/src/make-hidden-inputs.ts +8 -7
- package/src/mount.ts +2 -7
- package/src/notifier.ts +4 -6
- package/src/page/default-list-filters.ts +1 -0
- package/src/page/list.ts +18 -20
- package/src/page/mountable-with-fields.ts +3 -3
- package/src/page/mountable.ts +0 -1
- package/src/page/page.ts +2 -3
- package/src/page/props-parser.ts +1 -1
- package/src/page/sealious-list.ts +1 -1
- package/src/page/stateful-page.ts +6 -10
- package/src/register-external.ts +4 -4
- package/src/templates/form.ts +1 -2
- package/src/templates/jdd-component.ts +1 -1
- package/src/templates/jdd-editor.ts +2 -4
- package/src/templates/list.ts +0 -1
- package/src/templates/page.ts +1 -4
- package/src/templates/shared/collection-create-form.ts +5 -6
- package/src/templates/shared/collection-edit-form.ts +5 -6
- package/src/templates/shared/collection-list.ts +2 -2
- package/src/templates/shared/shared-crud-form-fields.ts +4 -9
- package/src/templates/templates.ts +5 -1
- package/src/test_utils/exec_async.ts +3 -4
- package/src/test_utils/test-on-real-app.ts +9 -11
- package/src/utils/browser-creator.js +0 -1
- package/src/utils/exec.ts +0 -1
- package/src/utils/input-wrapper.ts +1 -1
- package/src/utils/wrap-attributes.ts +1 -1
- package/src/utils/write-file.ts +1 -1
- package/.eslintrc.cjs +0 -44
|
@@ -35,20 +35,15 @@ class Table extends FormControl {
|
|
|
35
35
|
return (
|
|
36
36
|
/* HTML */
|
|
37
37
|
tempstream`<tr>
|
|
38
|
-
${
|
|
39
|
-
Object.entries(this.table_field.columns).map(
|
|
40
|
-
(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
)
|
|
48
|
-
)).map(
|
|
49
|
-
(html) => html.replaceAll(
|
|
50
|
-
TABLE_COLUMN_FIELD_INDEX_PLACEHOLDER,
|
|
51
|
-
row_index.toString()
|
|
38
|
+
${Promise.all(
|
|
39
|
+
Object.entries(this.table_field.columns).map(([column_name]) => {
|
|
40
|
+
const inner_fctx = get_row_fctx(row, row_index);
|
|
41
|
+
return tempstream`<td>${this.options.subfield_controls[column_name].render({ ...fctx, ...inner_fctx })}</td>`;
|
|
42
|
+
}).map(
|
|
43
|
+
async (html) => (await html).replaceAll(
|
|
44
|
+
TABLE_COLUMN_FIELD_INDEX_PLACEHOLDER,
|
|
45
|
+
row_index.toString()
|
|
46
|
+
)
|
|
52
47
|
)
|
|
53
48
|
)}
|
|
54
49
|
${this.options.allow_removing ? (
|
|
@@ -76,7 +71,7 @@ class Table extends FormControl {
|
|
|
76
71
|
)}"
|
|
77
72
|
/>
|
|
78
73
|
</noscript>
|
|
79
|
-
|
|
74
|
+
</td>`
|
|
80
75
|
) : ""}
|
|
81
76
|
</tr>`
|
|
82
77
|
);
|
|
@@ -69,7 +69,7 @@ class DeepReverseSingleReferenceList extends CheckboxedListField {
|
|
|
69
69
|
generateFieldDeclaration(_field_info, vars) {
|
|
70
70
|
return `new ${vars.form_field_types}.${this.constructor.name}(${vars.sealious_field})`;
|
|
71
71
|
}
|
|
72
|
-
generateCreateValueGetter(field_info
|
|
72
|
+
generateCreateValueGetter(field_info) {
|
|
73
73
|
return `${wrapKeyName(
|
|
74
74
|
field_info.name
|
|
75
75
|
)}: undefined /* handled below in postSealiousCreate */`;
|
|
@@ -19,7 +19,7 @@ describe("basic field", () => {
|
|
|
19
19
|
});
|
|
20
20
|
it("sends the values", async () => {
|
|
21
21
|
const port = await getPort();
|
|
22
|
-
console.
|
|
22
|
+
console.info(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
23
23
|
const app = new Koa();
|
|
24
24
|
const router = new Router();
|
|
25
25
|
const fields = {
|
|
@@ -58,7 +58,7 @@ describe("basic field", () => {
|
|
|
58
58
|
});
|
|
59
59
|
it("Doesn't call `isValueValid` and `parse` if the value is empty", async () => {
|
|
60
60
|
const port = await getPort();
|
|
61
|
-
console.
|
|
61
|
+
console.info(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
62
62
|
const app = new Koa();
|
|
63
63
|
const router = new Router();
|
|
64
64
|
let is_value_valid_called = false;
|
|
@@ -104,7 +104,7 @@ describe("basic field", () => {
|
|
|
104
104
|
});
|
|
105
105
|
it("Accepts a form where non-required values are empty", async () => {
|
|
106
106
|
const port = await getPort();
|
|
107
|
-
console.
|
|
107
|
+
console.info(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
108
108
|
const app = new Koa();
|
|
109
109
|
const router = new Router();
|
|
110
110
|
let submit_called = false;
|
package/lib/forms/fields/file.js
CHANGED
|
@@ -21,7 +21,7 @@ describe("file field", () => {
|
|
|
21
21
|
});
|
|
22
22
|
it("should handle as imple upload scenario", async () => {
|
|
23
23
|
const port = await getPort();
|
|
24
|
-
console.
|
|
24
|
+
console.info(`Using port http://localhost:${port} form file field test`);
|
|
25
25
|
const app = new Koa();
|
|
26
26
|
const router = new Router();
|
|
27
27
|
const fields = {
|
|
@@ -7,7 +7,7 @@ class SimpleFormField extends FormField {
|
|
|
7
7
|
this.type = type;
|
|
8
8
|
this.predicate = predicates.string;
|
|
9
9
|
}
|
|
10
|
-
async sealiousValueToForm(
|
|
10
|
+
async sealiousValueToForm(_ctx, value) {
|
|
11
11
|
if (value === null) {
|
|
12
12
|
return "";
|
|
13
13
|
}
|
|
@@ -17,6 +17,7 @@ class SimpleFormField extends FormField {
|
|
|
17
17
|
class TextBasedSimpleField extends SimpleFormField {
|
|
18
18
|
async parse(_, raw_value) {
|
|
19
19
|
return {
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
20
21
|
parsed_value: (raw_value || "").toString(),
|
|
21
22
|
parsable: true,
|
|
22
23
|
error: null
|
|
@@ -29,9 +30,9 @@ class TextBasedSimpleField extends SimpleFormField {
|
|
|
29
30
|
);
|
|
30
31
|
return parsed || "";
|
|
31
32
|
}
|
|
32
|
-
async postSealiousCreate(
|
|
33
|
+
async postSealiousCreate(_ctx, _created_item, _formData) {
|
|
33
34
|
}
|
|
34
|
-
async postSealiousEdit(ctx,
|
|
35
|
+
async postSealiousEdit(ctx, _edited_item, _formData) {
|
|
35
36
|
}
|
|
36
37
|
getControl() {
|
|
37
38
|
return new SimpleInput(this, {
|
|
@@ -36,7 +36,7 @@ class Table extends FormField {
|
|
|
36
36
|
if (!is(row_data, predicates.object)) {
|
|
37
37
|
throw new Error(`Expected object, got ${String(row_data)}`);
|
|
38
38
|
}
|
|
39
|
-
for (const key
|
|
39
|
+
for (const key of Object.keys(row_data)) {
|
|
40
40
|
const field = this.columns[key];
|
|
41
41
|
if (field == void 0) {
|
|
42
42
|
return {
|
package/lib/forms/form.js
CHANGED
package/lib/forms/form.test.js
CHANGED
|
@@ -34,7 +34,7 @@ function form_factory(canAccessFun) {
|
|
|
34
34
|
return result;
|
|
35
35
|
}
|
|
36
36
|
const port = await getPort();
|
|
37
|
-
console.
|
|
37
|
+
console.info("Using port " + port + " for form.test.ts");
|
|
38
38
|
describe("form test", () => {
|
|
39
39
|
let page;
|
|
40
40
|
before(async () => {
|
|
@@ -81,7 +81,6 @@ describe("form test", () => {
|
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
);
|
|
84
|
-
console.log(res_axios.data);
|
|
85
84
|
if (!res_axios.data.includes("Some fields are invalid")) {
|
|
86
85
|
throw new Error("when sending a empty request with axios, the error didnt appear");
|
|
87
86
|
}
|
|
@@ -306,7 +305,7 @@ describe("form test", () => {
|
|
|
306
305
|
await page.getByPlaceholder("text").click();
|
|
307
306
|
await page.getByPlaceholder("text").fill("yes@an.email");
|
|
308
307
|
await page.getByRole("button", { name: "Submit" }).click();
|
|
309
|
-
assertThrowsAsync(async () => {
|
|
308
|
+
await assertThrowsAsync(async () => {
|
|
310
309
|
return page.getByText("Please enter a proper email address").click({ timeout: 500 });
|
|
311
310
|
});
|
|
312
311
|
});
|
package/lib/forms/multiform.js
CHANGED
|
@@ -29,12 +29,12 @@ class Multiform extends MountableWithFields {
|
|
|
29
29
|
form.makeSubmitButton = () => (
|
|
30
30
|
/* HTML */
|
|
31
31
|
`<input
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
type="submit"
|
|
33
|
+
value="${form.submitButtonText}"
|
|
34
|
+
formaction="${form.action}"
|
|
35
|
+
id="${submit_button_id}"
|
|
36
|
+
${form.form_id ? `form="${form.form_id}"` : ""}
|
|
37
|
+
/> `
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
for (const form of Object.values(this.forms)) {
|
|
@@ -56,7 +56,6 @@ class Multiform extends MountableWithFields {
|
|
|
56
56
|
message: "this view includes multiple forms and each of them have their unique access rules"
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
59
|
getSubformsToRender(ctx) {
|
|
61
60
|
const requested_frame = ctx.headers["turbo-frame"];
|
|
62
61
|
if (!is(
|
|
@@ -15,7 +15,7 @@ import { SimpleInput } from "./controls/simple-input.js";
|
|
|
15
15
|
import { EmailField } from "./fields/email.js";
|
|
16
16
|
import getPort from "get-port";
|
|
17
17
|
const port = await getPort();
|
|
18
|
-
console.
|
|
18
|
+
console.info(`Using port ${port} form multiform.test.ts`);
|
|
19
19
|
const fields1 = {
|
|
20
20
|
email: new TextBasedSimpleField(true)
|
|
21
21
|
};
|
|
@@ -134,7 +134,7 @@ async function individual_field_validation_e2e_tests(javaScriptEnabled) {
|
|
|
134
134
|
await page.getByPlaceholder("text").click();
|
|
135
135
|
await page.getByPlaceholder("text").fill("yes@an.email");
|
|
136
136
|
await page.locator("#multiform_test_form1_submit").click();
|
|
137
|
-
assertThrowsAsync(async () => {
|
|
137
|
+
await assertThrowsAsync(async () => {
|
|
138
138
|
return page.getByText("Please enter a proper email address").click({ timeout: 500 });
|
|
139
139
|
});
|
|
140
140
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import * as prettier from "prettier";
|
|
3
2
|
import { promises as fs } from "fs";
|
|
4
3
|
import { assertType, predicates } from "@sealcode/ts-predicates";
|
|
5
|
-
import {
|
|
4
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
6
5
|
const target_locreq = _locreq(process.cwd());
|
|
7
6
|
async function extractCollectionClassname(full_file_path) {
|
|
8
7
|
const file_content = await fs.readFile(full_file_path, "utf-8");
|
|
@@ -52,7 +51,7 @@ ${file_data.map(({ class_name, urlname }) => ` "${urlname}": ${class_name},`).jo
|
|
|
52
51
|
};`;
|
|
53
52
|
await fs.writeFile(
|
|
54
53
|
target_locreq.resolve("src/back/collections/collections.ts"),
|
|
55
|
-
|
|
54
|
+
await formatWithPrettier(content)
|
|
56
55
|
);
|
|
57
56
|
console.log(
|
|
58
57
|
"Successfuly generated new src/back/collections/collections.ts file"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import * as prettier from "prettier";
|
|
3
2
|
import { promises as fs } from "fs";
|
|
4
|
-
import {
|
|
3
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
5
4
|
import recursive from "recursive-readdir";
|
|
6
5
|
import path from "path";
|
|
7
6
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
@@ -29,7 +28,7 @@ ${component_data.map(
|
|
|
29
28
|
const target = "src/back/jdd-components/components.ts";
|
|
30
29
|
await fs.writeFile(
|
|
31
30
|
target_locreq.resolve(target),
|
|
32
|
-
|
|
31
|
+
await formatWithPrettier(content)
|
|
33
32
|
);
|
|
34
33
|
console.log(`Successfuly generated new ${target} file`);
|
|
35
34
|
}
|
package/lib/generate-routes.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { promises as fs } from "fs";
|
|
2
|
-
import * as prettier from "prettier";
|
|
3
2
|
import { relative, resolve, basename } from "path";
|
|
4
3
|
import _locreq from "locreq";
|
|
5
4
|
import { walkDir } from "./utils/walk.js";
|
|
6
5
|
import { importPath } from "./utils/import-path.js";
|
|
7
6
|
import { assertType, predicates } from "@sealcode/ts-predicates";
|
|
8
7
|
import { unescape_url_params } from "./utils/escape-url-params.js";
|
|
9
|
-
import {
|
|
8
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
10
9
|
import { Templates } from "./templates/templates.js";
|
|
11
10
|
const target_locreq = _locreq(process.cwd());
|
|
12
11
|
async function extractActionName(full_file_path) {
|
|
@@ -91,14 +90,13 @@ ${sortRoutes(files).map(
|
|
|
91
90
|
}`;
|
|
92
91
|
const urls_content = `${sortRoutes(files).map(({ actionName, url }) => generateURL(actionName, url)).join("\n")}
|
|
93
92
|
`;
|
|
94
|
-
const prettier_config = await getPrettierConfig();
|
|
95
93
|
await fs.writeFile(
|
|
96
94
|
target_locreq.resolve("src/back/routes/routes.ts"),
|
|
97
|
-
|
|
95
|
+
await formatWithPrettier(routes_content)
|
|
98
96
|
);
|
|
99
97
|
await fs.writeFile(
|
|
100
98
|
target_locreq.resolve("src/back/routes/urls.ts"),
|
|
101
|
-
|
|
99
|
+
await formatWithPrettier(urls_content)
|
|
102
100
|
);
|
|
103
101
|
console.log(
|
|
104
102
|
"Successfuly generated new src/back/routes/routes.ts and src/back/routes/urls.ts"
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { generateURL, sortRoutes } from "./generate-routes.js";
|
|
2
|
-
import
|
|
3
|
-
import { getPrettierConfig } from "./utils/prettier.js";
|
|
2
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
4
3
|
import assert from "node:assert";
|
|
5
4
|
describe("generate routes", () => {
|
|
6
5
|
it("handles a url with params", async () => {
|
|
7
6
|
assert.strictEqual(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
await getPrettierConfig()
|
|
11
|
-
),
|
|
12
|
-
prettier.format(
|
|
7
|
+
await formatWithPrettier(generateURL("EditUser", "/admin/users/:id/edit/")),
|
|
8
|
+
await formatWithPrettier(
|
|
13
9
|
`export const EditUserURL = (id: string) => \`/admin/users/\${id}/edit/\`;
|
|
14
10
|
EditUserURL.params = ["id"];
|
|
15
|
-
EditUserURL.rawURL = "/admin/users/:id/edit/"
|
|
16
|
-
await getPrettierConfig()
|
|
11
|
+
EditUserURL.rawURL = "/admin/users/:id/edit/";`
|
|
17
12
|
)
|
|
18
13
|
);
|
|
19
14
|
});
|
|
@@ -25,15 +20,11 @@ EditUserURL.rawURL = "/admin/users/:id/edit/";`,
|
|
|
25
20
|
});
|
|
26
21
|
it("handles a url with params and diacritics", async () => {
|
|
27
22
|
assert.strictEqual(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await getPrettierConfig()
|
|
31
|
-
),
|
|
32
|
-
prettier.format(
|
|
23
|
+
await formatWithPrettier(generateURL("EditUser", "/admin/u\u017Cytkownicy/:id/edit/")),
|
|
24
|
+
await formatWithPrettier(
|
|
33
25
|
`export const EditUserURL = (id: string) => \`/admin/u%C5%BCytkownicy/\${id}/edit/\`;
|
|
34
26
|
EditUserURL.params = ["id"];
|
|
35
|
-
EditUserURL.rawURL = "/admin/u%C5%BCytkownicy/:id/edit/"
|
|
36
|
-
await getPrettierConfig()
|
|
27
|
+
EditUserURL.rawURL = "/admin/u%C5%BCytkownicy/:id/edit/";`
|
|
37
28
|
)
|
|
38
29
|
);
|
|
39
30
|
});
|
package/lib/generate-stimulus.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
-
import * as prettier from "prettier";
|
|
3
2
|
import { promises as fs } from "fs";
|
|
4
|
-
import {
|
|
3
|
+
import { formatWithPrettier } from "./utils/prettier.js";
|
|
5
4
|
import recursive from "recursive-readdir";
|
|
6
5
|
import path, { dirname } from "path";
|
|
7
6
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
@@ -12,7 +11,7 @@ async function generateStimulusControllers(controller_dirs) {
|
|
|
12
11
|
target_locreq.resolve("src/"),
|
|
13
12
|
...controller_dirs
|
|
14
13
|
];
|
|
15
|
-
console.
|
|
14
|
+
console.info("Looking for controllers in ", stimulus_search_dirs);
|
|
16
15
|
const controller_names = (await Promise.all(stimulus_search_dirs.map((dir) => recursive(dir)))).flat().filter((c) => c.endsWith(".stimulus.ts")).sort();
|
|
17
16
|
const controller_data = controller_names.map(
|
|
18
17
|
(p) => "./" + path.relative(target_locreq.resolve(dirname(output_file)), p).replace(/\.[tj]sx?$/, ".js")
|
|
@@ -35,9 +34,9 @@ export { Turbo };
|
|
|
35
34
|
`;
|
|
36
35
|
await fs.writeFile(
|
|
37
36
|
target_locreq.resolve(output_file),
|
|
38
|
-
|
|
37
|
+
await formatWithPrettier(content)
|
|
39
38
|
);
|
|
40
|
-
console.
|
|
39
|
+
console.info(`Successfuly generated new ${output_file} file`);
|
|
41
40
|
}
|
|
42
41
|
export {
|
|
43
42
|
generateStimulusControllers
|
package/lib/get-fonts.js
CHANGED
|
@@ -27,43 +27,45 @@ async function getFonts(_ = {}) {
|
|
|
27
27
|
fontsPath: "/dist/fonts"
|
|
28
28
|
});
|
|
29
29
|
await downloader.execute();
|
|
30
|
-
console.
|
|
30
|
+
console.info("Downloaded new fonts pack from google fonts");
|
|
31
31
|
const squirrel_fonts = fonts_config.fontSquirrel;
|
|
32
|
-
if (
|
|
32
|
+
if (is(
|
|
33
33
|
squirrel_fonts,
|
|
34
34
|
predicates.record(
|
|
35
35
|
predicates.string,
|
|
36
36
|
predicates.array(predicates.string)
|
|
37
37
|
)
|
|
38
38
|
)) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
44
|
-
const config_file = `{
|
|
39
|
+
await mkdir(target_locreq.resolve("public/dist/fontsquirrel/"), {
|
|
40
|
+
recursive: true
|
|
41
|
+
});
|
|
42
|
+
const config_file = `{
|
|
45
43
|
"tmpDir": "/tmp/fonts",
|
|
46
44
|
"fontsDir": "/dist/fontsquirrel/fonts",
|
|
47
45
|
"cssDir": "/dist/fontsquirrel/css",
|
|
48
46
|
"cssFile": "fonts.css"
|
|
49
47
|
}`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
await writeFile("public/fonsta.config.json", config_file);
|
|
49
|
+
await Promise.all(
|
|
50
|
+
Object.keys(squirrel_fonts).map((font) => {
|
|
51
|
+
if (squirrel_fonts[font].length) {
|
|
52
|
+
return execPromise(
|
|
53
|
+
`node ${path_to_fonsta} install ${font}:${squirrel_fonts[font].join(",")}`,
|
|
54
|
+
{
|
|
55
|
+
cwd: target_locreq.resolve("public")
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
} else {
|
|
59
|
+
return execPromise(
|
|
60
|
+
`node ${path_to_fonsta} install ${font}`,
|
|
61
|
+
{
|
|
62
|
+
cwd: target_locreq.resolve("public")
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}
|
|
67
69
|
const fonts_css_file_path = resolve(
|
|
68
70
|
target_locreq.resolve("public/dist/fonts"),
|
|
69
71
|
"fonts.css"
|
|
@@ -75,8 +77,8 @@ async function getFonts(_ = {}) {
|
|
|
75
77
|
);
|
|
76
78
|
await unlink("public/fonsta.config.json");
|
|
77
79
|
await rmdir("public/tmp");
|
|
78
|
-
console.
|
|
79
|
-
console.
|
|
80
|
+
console.info("Downloaded new fonts pack from Font Squirrel");
|
|
81
|
+
console.info("Downloaded new fonts pack");
|
|
80
82
|
}
|
|
81
83
|
export {
|
|
82
84
|
FONTS_CONFIG_PATH,
|
package/lib/make-env.js
CHANGED
|
@@ -3,10 +3,10 @@ import { attribute } from "./sanitize.js";
|
|
|
3
3
|
function makeHiddenInputs(ctx, fields, values, fields_to_skip) {
|
|
4
4
|
return tempstream`${Object.entries(fields).filter(([key]) => !fields_to_skip.includes(key)).map(
|
|
5
5
|
([key, field]) => tempstream`<input
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
type="hidden"
|
|
7
|
+
name="${key}"
|
|
8
|
+
value="${field.getParsedValue(ctx, values).then((r) => attribute(JSON.stringify(r.raw) || ""))}"
|
|
9
|
+
/>`
|
|
10
10
|
)}`;
|
|
11
11
|
}
|
|
12
12
|
export {
|
package/lib/mount.js
CHANGED
package/lib/notifier.js
CHANGED
|
@@ -13,7 +13,7 @@ async function wait_for_run_id_to_change(app_port) {
|
|
|
13
13
|
try {
|
|
14
14
|
const { started_at } = await get_status(app_port);
|
|
15
15
|
first_timestamp = started_at;
|
|
16
|
-
} catch (
|
|
16
|
+
} catch (_e) {
|
|
17
17
|
await wait_for_app_to_be_stable(app_port);
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
@@ -76,8 +76,8 @@ function make_notifier(port, app_port) {
|
|
|
76
76
|
sockets = sockets.filter((s) => s !== socket);
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
-
console.
|
|
80
|
-
"
|
|
79
|
+
console.info(
|
|
80
|
+
"\u{1F514} Build notifier listening on websocket at port " + port.toString()
|
|
81
81
|
);
|
|
82
82
|
return function notify(message) {
|
|
83
83
|
sockets.forEach((s) => s.send(message));
|
package/lib/page/list.js
CHANGED
|
@@ -90,17 +90,16 @@ class ListPage extends Page {
|
|
|
90
90
|
(n) => (
|
|
91
91
|
/* HTML */
|
|
92
92
|
`<option
|
|
93
|
-
|
|
93
|
+
value="${UrlWithNewParams(
|
|
94
94
|
ctx,
|
|
95
|
-
//eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
96
95
|
this.propsParser.overwriteProp(ctx, {
|
|
97
96
|
page: n
|
|
98
97
|
})
|
|
99
98
|
)}"
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
${page === n ? "selected" : ""}
|
|
100
|
+
>
|
|
101
|
+
${n}
|
|
102
|
+
</option>`
|
|
104
103
|
)
|
|
105
104
|
)}
|
|
106
105
|
</select>
|
|
@@ -117,7 +116,6 @@ class ListPage extends Page {
|
|
|
117
116
|
`<a
|
|
118
117
|
href="${UrlWithNewParams(
|
|
119
118
|
ctx,
|
|
120
|
-
//eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
121
119
|
this.propsParser.overwriteProp(ctx, {
|
|
122
120
|
page
|
|
123
121
|
})
|
package/lib/page/mountable.js
CHANGED
package/lib/page/page.js
CHANGED
package/lib/register-external.js
CHANGED
|
@@ -43,7 +43,7 @@ async function updatePackageJson(projectDir, moduleName, subdirectory, type) {
|
|
|
43
43
|
const pathToAdd = `node_modules/${moduleName}/${subdirectory}`;
|
|
44
44
|
const existingPaths = packageJson.sealgen[type];
|
|
45
45
|
if (existingPaths.includes(pathToAdd)) {
|
|
46
|
-
console.
|
|
46
|
+
console.warn(`${type} already contains: ${pathToAdd}`);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
existingPaths.push(pathToAdd);
|
|
@@ -52,9 +52,9 @@ async function updatePackageJson(projectDir, moduleName, subdirectory, type) {
|
|
|
52
52
|
"json"
|
|
53
53
|
);
|
|
54
54
|
await fs.writeFile(packageJsonPath, updatedContent);
|
|
55
|
-
console.
|
|
55
|
+
console.info(`Added ${pathToAdd} to ${type} in ${packageJsonPath}`);
|
|
56
56
|
}
|
|
57
|
-
async function registerExternalControllers(
|
|
57
|
+
async function registerExternalControllers(_args) {
|
|
58
58
|
const moduleName = process.argv.at(3);
|
|
59
59
|
const subdirectory = process.argv.at(4);
|
|
60
60
|
if (!moduleName || !subdirectory) {
|
|
@@ -76,7 +76,7 @@ async function registerExternalControllers(args) {
|
|
|
76
76
|
process.exit(1);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
async function registerExternalStyles(
|
|
79
|
+
async function registerExternalStyles(_args) {
|
|
80
80
|
const moduleName = process.argv.at(3);
|
|
81
81
|
const subdirectory = process.argv.at(4);
|
|
82
82
|
if (!moduleName || !subdirectory) {
|
package/lib/templates/form.js
CHANGED
|
@@ -39,7 +39,7 @@ const defaults = {
|
|
|
39
39
|
other_methods: "",
|
|
40
40
|
success_message: "Success!"
|
|
41
41
|
};
|
|
42
|
-
async function formTemplate(action_name,
|
|
42
|
+
async function formTemplate(action_name, _params = defaults) {
|
|
43
43
|
const params = { ...defaults, ..._params };
|
|
44
44
|
const content = `import type { Context } from "koa";
|
|
45
45
|
import type { FormData } from "@sealcode/sealgen";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
function jddComponentTemplate(component_name) {
|
|
2
|
+
async function jddComponentTemplate(component_name) {
|
|
3
3
|
return `import { TempstreamJSX } from "tempstream";
|
|
4
4
|
import type { ComponentToHTMLArgs } from "@sealcode/jdd";
|
|
5
5
|
import { Component, ComponentArguments } from "@sealcode/jdd";
|
|
@@ -20,7 +20,7 @@ async function jddEditorTemplate(actionName) {
|
|
|
20
20
|
let field_name = "";
|
|
21
21
|
if (jdd_fields.length == 1) {
|
|
22
22
|
field_name = jdd_fields[0].name;
|
|
23
|
-
console.
|
|
23
|
+
console.info(
|
|
24
24
|
`Only one field of type JDD found: ${field_name}, so skipping the question...`
|
|
25
25
|
);
|
|
26
26
|
} else if (jdd_fields.length > 1) {
|