MakeInertiaColumns Command Documentation / Dokumentasi Command MakeInertiaColumns
English Documentation
Overview
TheMakeInertiaColumns command is a custom Laravel Artisan command that generates TanStack Table column definitions from YAML configuration files. This command is designed to automate the creation of table column configurations for Inertia.js applications using Vue 3 and TypeScript.
Command Signature
Required Arguments
- yamlFile: Path to the YAML configuration file (relative to project root)
- outputPath: Path where the generated TypeScript file will be saved (relative to project root)
Available Options
--edit-mode=page: Sets the edit mode for the generated columns (default: “page”)--create-mode=page: Sets the create mode for the generated columns (default: “page”)--route-prefix=: Sets the route prefix for the generated columns--entity-name=: Sets the entity name for the generated columns--entity-name-lower=: Sets the lowercase entity name for the generated columns
YAML Configuration Structure
The command expects a YAML file with the following structure:YAML Configuration Details
Table Section:name: The accessor key for the column datalabel: The display header text for the columnshow: Boolean flag to determine if the column should be included in the output
model: The field name that will be used in the TypeScript interfacetype: The data type for TypeScript type mapping
Supported Data Types
The command maps YAML types to TypeScript types as follows:integer,number→numberboolean→booleanstring,text,textarea,datetime→string- Any other type →
any
Detailed YAML Structure (Based on Project Example)
The project uses comprehensive YAML configuration files likemanager_controller.yml with the following structure:
Key Features of Project YAML Structure:
- Rich Table Configuration: Each table column includes styling, behavior, and display options
- Multiple Data Types: Support for text, image, date, boolean, and custom types
- Search and Filter Options: Granular control over column searchability and filtering
- CSS Integration: Built-in support for Tailwind CSS classes and custom styling
- TypeScript Integration: Automatic generation of TypeScript interfaces from Vue section
Generated Output
The command uses a stub template located atresources/views/stubs/inertia/js/columns.ts.stub and replaces the following placeholders:
{{pl_columns}}: Generated column definitions{{pl_interface_fields}}: Generated TypeScript interface fields{{pl_edit_mode}}: Edit mode value{{pl_create_mode}}: Create mode value{{pl_route_prefix}}: Route prefix value{{pl_entity_name}}: Entity name value{{pl_primary_entity_lower}}: Lowercase entity name value
Real-World Example
Using the existingmanager_controller.yml file in the project:
Example Usage
Error Handling
The command includes comprehensive error handling:- Validates YAML file existence and format
- Creates output directories if they don’t exist
- Provides clear error messages for debugging
- Returns appropriate exit codes (0 for success, 1 for error)
Dependencies
This command requires:symfony/yamlpackage for YAML parsing- Laravel’s Console Command base class
- A properly formatted stub template
Integration with Other Commands
This command works well with other Inertia commands:MakeInertiaForm: Generates form components from the same YAML file’sform,view, andvuesections- The
vuesection is now utilized for TypeScript interface generation and additional field definitions - Provides type safety and consistency across form components and table columns
- The
MakeInertiaCrud: Generates complete CRUD interfaces using all sections of the YAML
Enhanced MakeInertiaForm Integration
TheMakeInertiaForm command has been enhanced to utilize the vue section:
- TypeScript interfaces from the
vuesection field definitions - Additional form fields for fields defined in
vuebut not inform - Proper type mapping from YAML types to TypeScript types
- Duplicate field prevention to avoid conflicts between
formandvuesections
{{{pl_vue_interface_fields}}}: TypeScript interface field definitions{{{pl_vue_additional_fields}}}: Additional form fields from vue section
Dokumentasi Bahasa Indonesia
Gambaran Umum
CommandMakeInertiaColumns adalah perintah Laravel Artisan kustom yang menghasilkan definisi kolom TanStack Table dari file konfigurasi YAML. Command ini dirancang untuk mengotomatisasi pembuatan konfigurasi kolom tabel untuk aplikasi Inertia.js yang menggunakan Vue 3 dan TypeScript.
Tanda Tangan Command
Argumen Wajib
- yamlFile: Path ke file konfigurasi YAML (relatif terhadap root proyek)
- outputPath: Path tempat file TypeScript yang dihasilkan akan disimpan (relatif terhadap root proyek)
Opsi yang Tersedia
--edit-mode=page: Mengatur mode edit untuk kolom yang dihasilkan (default: “page”)--create-mode=page: Mengatur mode create untuk kolom yang dihasilkan (default: “page”)--route-prefix=: Mengatur prefix route untuk kolom yang dihasilkan--entity-name=: Mengatur nama entitas untuk kolom yang dihasilkan--entity-name-lower=: Mengatur nama entitas huruf kecil untuk kolom yang dihasilkan
Struktur Konfigurasi YAML
Command ini mengharapkan file YAML dengan struktur sebagai berikut:Detail Konfigurasi YAML
Seksi Table:name: Kunci accessor untuk data kolomlabel: Teks header yang ditampilkan untuk kolomshow: Flag boolean untuk menentukan apakah kolom harus disertakan dalam output
model: Nama field yang akan digunakan dalam interface TypeScripttype: Tipe data untuk mapping tipe TypeScript
Tipe Data yang Didukung
Command ini memetakan tipe YAML ke tipe TypeScript sebagai berikut:integer,number→numberboolean→booleanstring,text,textarea,datetime→string- Tipe lainnya →
any
Output yang Dihasilkan
Command ini menggunakan template stub yang terletak diresources/views/stubs/inertia/js/columns.ts.stub dan mengganti placeholder berikut:
{{pl_columns}}: Definisi kolom yang dihasilkan{{pl_interface_fields}}: Field interface TypeScript yang dihasilkan{{pl_edit_mode}}: Nilai mode edit{{pl_create_mode}}: Nilai mode create{{pl_route_prefix}}: Nilai prefix route{{pl_entity_name}}: Nilai nama entitas{{pl_primary_entity_lower}}: Nilai nama entitas huruf kecil
Contoh Penggunaan
Penanganan Error
Command ini mencakup penanganan error yang komprehensif:- Memvalidasi keberadaan dan format file YAML
- Membuat direktori output jika belum ada
- Menyediakan pesan error yang jelas untuk debugging
- Mengembalikan kode keluar yang sesuai (0 untuk sukses, 1 untuk error)
Dependencies
Command ini membutuhkan:- Package
symfony/yamluntuk parsing YAML - Kelas base Laravel Console Command
- Template stub yang terformat dengan benar
Catatan Implementasi
Fitur Utama:- Parsing YAML: Menggunakan Symfony YAML parser untuk membaca konfigurasi
- Generasi Kolom: Membuat definisi kolom TanStack Table secara otomatis
- Interface TypeScript: Menghasilkan interface TypeScript berdasarkan konfigurasi Vue
- Template System: Menggunakan sistem template dengan placeholder replacement
- Directory Management: Otomatis membuat direktori output jika diperlukan
- Validasi input untuk mencegah path traversal
- Error handling yang robust
- Type checking untuk data YAML
- Efisien dalam memproses file YAML besar
- Minimal memory footprint
- Fast string replacement operations
Integrasi dengan Proyek
Command ini terintegrasi dengan baik dengan arsitektur proyek:- Menggunakan konvensi Laravel untuk Artisan commands
- Kompatibel dengan struktur direktori proyek
- Mendukung workflow development yang ada
- Konsisten dengan pola code generation lainnya
Troubleshooting
Masalah Umum:- File YAML tidak ditemukan: Pastikan path file YAML benar dan relatif terhadap root proyek
- Direktori output tidak dapat dibuat: Periksa permission sistem file
- Template stub tidak ditemukan: Pastikan file stub ada di
resources/views/stubs/inertia/js/columns.ts.stub - Format YAML tidak valid: Validasi syntax YAML menggunakan parser online
- Gunakan
--verboseflag untuk output lebih detail - Periksa log Laravel untuk error tambahan
- Validasi struktur YAML sebelum menjalankan command
