Page MenuHomeSealhub

crud-field-snippets.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

crud-field-snippets.ts

import _locreq from "locreq";
import prompts from "prompts";
import { getFieldHandler } from "./templates/shared/shared-crud-form-fields.js";
import extract_fields_from_collection from "./utils/extract-fields-from-collection.js";
import { listCollections } from "./utils/list-collections.js";
import { formatWithPrettier } from "./utils/prettier.js";
export async function crudFieldSnippets(
params: Partial<{ [key in "collection" | "url"]: string }>,
app_directory: string = process.cwd()
) {
const target_locreq = _locreq(app_directory);
prompts.override(params);
const { collection_name } = (await prompts([
{
type: "autocomplete",
name: "collection_name",
message:
"Which sealious collection do you like to show a CRUD field config for?",
choices: (
await listCollections()
).map((collection) => ({
title: collection,
value: collection,
})),
},
])) as { collection_name: string };
const all_fields = await extract_fields_from_collection(collection_name);
const { field_name } = (await prompts([
{
type: "autocomplete",
name: "field_name",
message: `Which field do you want to show CRUD config for??`,
choices: all_fields.map((field) => ({
title: field.name,
value: field.name,
})),
},
])) as { field_name: string };
const handler = await getFieldHandler(
collection_name,
all_fields.find((e) => e.name == field_name)!,
(p) => p
);
console.log(`
### Field in shared.ts
${handler.field}
### Control in shared.ts
${await formatWithPrettier(handler.controls)}
`);
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 15:32 (1 d, 2 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1199738
Default Alt Text
crud-field-snippets.ts (1 KB)

Event Timeline