Generator (/gen)
In development the module adds a /gen page that scaffolds the CRUD for a backend resource: a datatable page, a form component and the translations. The URL is printed in the dev server console next to the "Listening" URL.
- Enabled by
we.gen(defaulttrue), see Configuration. - Only registered in
nuxt dev: it never ends up in a production build. - Writes files with the File System Access API, so it needs a Chromium-based browser (Chrome, Edge, ...).
- The page excludes itself from the Sanctum auth middleware and uses the
emptylayout.
ts
// nuxt.config.ts: disable it
export default defineNuxtConfig({
we: { gen: false },
})How it works
- Project folder: click the folder field and pick the root of your Nuxt project. If you skip this step, the browser asks for it when the files are written.
- Resource name: the backend resource, e.g.
users. Its fields are loaded fromGET /datatables/fields/{resource}throughuseApi, so the backend must expose that endpoint and you must be able to reach it (log in from the app first if needed). - Route:
Prefix(default/, e.g./admin/) andPage name(defaults to the resource name with_replaced by-). - Edit/create template:
FormWrapper: the list page opens the form in auseFormWrapperdialog;Dedicated page ([id].vue): create and edit open a separate page (/newfor new items);None: list only, without the add button.
- i18n:
flat(dotted keys),nested(nested objects) ornone(labels written in the templates). - Select fields: pick the fields to include. Audit fields (
id,created_at,updated_user_id, ...) are hidden and unchecked by default. Foreign keys can be marked aspaginatefor the generatedWeSelect. - Generate: the code is shown in one tab per file; it is written right away if a project folder is selected (otherwise after a confirmation), or with the Write files button.
Generated files
With resource holidays, prefix /admin/ and page name holidays:
| File | Content |
|---|---|
app/pages/admin/holidays.vue | List page with WeDatatable (FormWrapper and None modes) |
app/pages/admin/holidays/index.vue | List page (dedicated page mode) |
app/pages/admin/holidays/[id].vue | Create/edit page (dedicated page mode) |
app/components/FormHolidays.vue | Form built with useForm, with a field per selected column |
i18n/locales/it.json | Keys under holidays.* (title, form titles, field labels, messages), unless i18n is none |
Generated files overwrite existing files with the same path without asking. Translations are merged into it.json at the top level: existing keys are kept, but a key with the same name (the resource key in nested mode, each dotted key in flat mode) is replaced.
The generated pages use WeHeader, FormWrapper and portal targets: these components come from the project template, not from the module.