@sealcode/sealgen 0.15.10 → 0.15.12
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/lib/templates/list.js +30 -11
- package/package.json +1 -1
- package/src/templates/list.ts +30 -11
package/lib/templates/list.js
CHANGED
|
@@ -5,6 +5,7 @@ import { listCollections } from "../utils/list-collections.js";
|
|
|
5
5
|
import { extractCollectionClassname } from "../generate-collections.js";
|
|
6
6
|
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
7
7
|
import { DefaultListFilters } from "../page/default-list-filters.js";
|
|
8
|
+
import { formatWithPrettier } from "../utils/prettier.js";
|
|
8
9
|
const target_locreq = _locreq(process.cwd());
|
|
9
10
|
const listTemplate = async (action_name, newfilefullpath) => {
|
|
10
11
|
const response = await prompts({
|
|
@@ -25,25 +26,30 @@ const listTemplate = async (action_name, newfilefullpath) => {
|
|
|
25
26
|
),
|
|
26
27
|
extract_fields_from_collection(collection_name)
|
|
27
28
|
]);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
import { CollectionItem } from "sealious";
|
|
31
|
-
import { FlatTemplatable
|
|
32
|
-
import {
|
|
33
|
-
|
|
29
|
+
const importPath = curryImportPath(newfilefullpath);
|
|
30
|
+
const result = `import type { Context } from "koa";
|
|
31
|
+
import type { CollectionItem } from "sealious";
|
|
32
|
+
import type { FlatTemplatable } from "tempstream";
|
|
33
|
+
import { TempstreamJSX } from "tempstream";
|
|
34
|
+
import { ${uppercase_collection} } from "${importPath(
|
|
35
|
+
target_locreq.resolve("src/back/collections/collections.ts")
|
|
34
36
|
)}";
|
|
35
|
-
import html from "${
|
|
37
|
+
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
38
|
+
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
36
39
|
import {
|
|
37
40
|
SealiousItemListPage,
|
|
38
41
|
BaseListPageFields,
|
|
39
42
|
DefaultListFilters,
|
|
40
|
-
|
|
41
|
-
} from "@sealcode/sealgen";;
|
|
43
|
+
} from "@sealcode/sealgen";
|
|
42
44
|
import qs from "qs";
|
|
43
|
-
import {
|
|
45
|
+
import type { FilePointer } from "@sealcode/file-manager";
|
|
46
|
+
import { imageRouter } from "${importPath(
|
|
47
|
+
target_locreq.resolve("src/back/image-router.ts")
|
|
48
|
+
)}";
|
|
44
49
|
|
|
45
50
|
export const actionName = "${action_name}";
|
|
46
51
|
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
47
53
|
const filterFields = [
|
|
48
54
|
${collection_fields.map(
|
|
49
55
|
(field) => ` { field: "${field.name}", render: ${DefaultListFilters[field.type] ? `DefaultListFilters["${field.type}"]` : `DefaultListFilters.fallback`} }`
|
|
@@ -73,6 +79,17 @@ ${collection_fields.map((field) => {
|
|
|
73
79
|
},
|
|
74
80
|
}`;
|
|
75
81
|
}
|
|
82
|
+
if (field.type == "image") {
|
|
83
|
+
return `{
|
|
84
|
+
field: "${field.name}",
|
|
85
|
+
label: "${field.name}",
|
|
86
|
+
format: async (value: FilePointer) => {
|
|
87
|
+
return imageRouter.image(await value.getPath(), {
|
|
88
|
+
container: { width: 45, height: 45 },
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
}`;
|
|
92
|
+
}
|
|
76
93
|
return ` { field: "${field.name}", label: "${field.name}" }`;
|
|
77
94
|
}).join(",\n")}
|
|
78
95
|
] as {
|
|
@@ -116,9 +133,10 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
116
133
|
</form>;
|
|
117
134
|
}
|
|
118
135
|
|
|
119
|
-
async renderItem(
|
|
136
|
+
async renderItem(ctx: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
120
137
|
return <tr>
|
|
121
138
|
{displayFields.map(({ field, format }) => {
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
|
122
140
|
const value = item.get(field as any);
|
|
123
141
|
return <td>{format ? format(value) : value}</td>;
|
|
124
142
|
})}
|
|
@@ -141,6 +159,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
141
159
|
|
|
142
160
|
})(${uppercase_collection});
|
|
143
161
|
`;
|
|
162
|
+
return formatWithPrettier(result);
|
|
144
163
|
};
|
|
145
164
|
export {
|
|
146
165
|
listTemplate
|
package/package.json
CHANGED
package/src/templates/list.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { listCollections } from "../utils/list-collections.js";
|
|
|
5
5
|
import { extractCollectionClassname } from "../generate-collections.js";
|
|
6
6
|
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
7
7
|
import { DefaultListFilters } from "../page/default-list-filters.js";
|
|
8
|
+
import { formatWithPrettier } from "../utils/prettier.js";
|
|
8
9
|
const target_locreq = _locreq(process.cwd());
|
|
9
10
|
|
|
10
11
|
export const listTemplate = async (
|
|
@@ -31,25 +32,30 @@ export const listTemplate = async (
|
|
|
31
32
|
),
|
|
32
33
|
extract_fields_from_collection(collection_name),
|
|
33
34
|
]);
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
import { CollectionItem } from "sealious";
|
|
37
|
-
import { FlatTemplatable
|
|
38
|
-
import {
|
|
39
|
-
|
|
35
|
+
const importPath = curryImportPath(newfilefullpath);
|
|
36
|
+
const result = `import type { Context } from "koa";
|
|
37
|
+
import type { CollectionItem } from "sealious";
|
|
38
|
+
import type { FlatTemplatable } from "tempstream";
|
|
39
|
+
import { TempstreamJSX } from "tempstream";
|
|
40
|
+
import { ${uppercase_collection} } from "${importPath(
|
|
41
|
+
target_locreq.resolve("src/back/collections/collections.ts")
|
|
40
42
|
)}";
|
|
41
|
-
import html from "${
|
|
43
|
+
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
44
|
+
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
42
45
|
import {
|
|
43
46
|
SealiousItemListPage,
|
|
44
47
|
BaseListPageFields,
|
|
45
48
|
DefaultListFilters,
|
|
46
|
-
|
|
47
|
-
} from "@sealcode/sealgen";;
|
|
49
|
+
} from "@sealcode/sealgen";
|
|
48
50
|
import qs from "qs";
|
|
49
|
-
import {
|
|
51
|
+
import type { FilePointer } from "@sealcode/file-manager";
|
|
52
|
+
import { imageRouter } from "${importPath(
|
|
53
|
+
target_locreq.resolve("src/back/image-router.ts")
|
|
54
|
+
)}";
|
|
50
55
|
|
|
51
56
|
export const actionName = "${action_name}";
|
|
52
57
|
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
53
59
|
const filterFields = [
|
|
54
60
|
${collection_fields
|
|
55
61
|
.map(
|
|
@@ -87,6 +93,17 @@ ${collection_fields
|
|
|
87
93
|
},
|
|
88
94
|
}`;
|
|
89
95
|
}
|
|
96
|
+
if (field.type == "image") {
|
|
97
|
+
return `{
|
|
98
|
+
field: "${field.name}",
|
|
99
|
+
label: "${field.name}",
|
|
100
|
+
format: async (value: FilePointer) => {
|
|
101
|
+
return imageRouter.image(await value.getPath(), {
|
|
102
|
+
container: { width: 45, height: 45 },
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
}`;
|
|
106
|
+
}
|
|
90
107
|
return ` { field: "${field.name}", label: "${field.name}" }`;
|
|
91
108
|
})
|
|
92
109
|
.join(",\n")}
|
|
@@ -131,9 +148,10 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
131
148
|
</form>;
|
|
132
149
|
}
|
|
133
150
|
|
|
134
|
-
async renderItem(
|
|
151
|
+
async renderItem(ctx: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
135
152
|
return <tr>
|
|
136
153
|
{displayFields.map(({ field, format }) => {
|
|
154
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
|
137
155
|
const value = item.get(field as any);
|
|
138
156
|
return <td>{format ? format(value) : value}</td>;
|
|
139
157
|
})}
|
|
@@ -156,4 +174,5 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
156
174
|
|
|
157
175
|
})(${uppercase_collection});
|
|
158
176
|
`;
|
|
177
|
+
return formatWithPrettier(result);
|
|
159
178
|
};
|