Skip to content

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 (default true), 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 empty layout.
ts
// nuxt.config.ts: disable it
export default defineNuxtConfig({
  we: { gen: false },
})

How it works ​

  1. 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.
  2. Resource name: the backend resource, e.g. users. Its fields are loaded from GET /datatables/fields/{resource} through useApi, so the backend must expose that endpoint and you must be able to reach it (log in from the app first if needed).
  3. Route: Prefix (default /, e.g. /admin/) and Page name (defaults to the resource name with _ replaced by -).
  4. Edit/create template:
    • FormWrapper: the list page opens the form in a useFormWrapper dialog;
    • Dedicated page ([id].vue): create and edit open a separate page (/new for new items);
    • None: list only, without the add button.
  5. i18n: flat (dotted keys), nested (nested objects) or none (labels written in the templates).
  6. 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 as paginate for the generated WeSelect.
  7. 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:

FileContent
app/pages/admin/holidays.vueList page with WeDatatable (FormWrapper and None modes)
app/pages/admin/holidays/index.vueList page (dedicated page mode)
app/pages/admin/holidays/[id].vueCreate/edit page (dedicated page mode)
app/components/FormHolidays.vueForm built with useForm, with a field per selected column
i18n/locales/it.jsonKeys 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.

Source Code ​