generathor-laravel 1.0.0
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/LICENSE +21 -0
- package/README.md +419 -0
- package/dist/configuration.d.ts +25 -0
- package/dist/configuration.js +43 -0
- package/dist/helpers/handlebars.d.ts +3 -0
- package/dist/helpers/handlebars.js +20 -0
- package/dist/helpers/naming.d.ts +18 -0
- package/dist/helpers/naming.js +98 -0
- package/dist/helpers/string.d.ts +27 -0
- package/dist/helpers/string.js +120 -0
- package/dist/helpers/type.d.ts +4 -0
- package/dist/helpers/type.js +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +18 -0
- package/dist/template.d.ts +20 -0
- package/dist/template.js +284 -0
- package/dist/transformers/collection/attachForm.d.ts +4 -0
- package/dist/transformers/collection/attachForm.js +55 -0
- package/dist/transformers/collection/attachRequest.d.ts +5 -0
- package/dist/transformers/collection/attachRequest.js +92 -0
- package/dist/transformers/collection/base.d.ts +20 -0
- package/dist/transformers/collection/base.js +54 -0
- package/dist/transformers/collection/baseController.d.ts +4 -0
- package/dist/transformers/collection/baseController.js +14 -0
- package/dist/transformers/collection/belongsToRelation.d.ts +5 -0
- package/dist/transformers/collection/belongsToRelation.js +86 -0
- package/dist/transformers/collection/controller.d.ts +8 -0
- package/dist/transformers/collection/controller.js +163 -0
- package/dist/transformers/collection/createRelationForm.d.ts +4 -0
- package/dist/transformers/collection/createRelationForm.js +163 -0
- package/dist/transformers/collection/filterRelationForm.d.ts +4 -0
- package/dist/transformers/collection/filterRelationForm.js +164 -0
- package/dist/transformers/collection/hasManyRelation.d.ts +5 -0
- package/dist/transformers/collection/hasManyRelation.js +91 -0
- package/dist/transformers/collection/menu.d.ts +4 -0
- package/dist/transformers/collection/menu.js +25 -0
- package/dist/transformers/collection/route.d.ts +5 -0
- package/dist/transformers/collection/route.js +123 -0
- package/dist/transformers/item/base.d.ts +19 -0
- package/dist/transformers/item/base.js +33 -0
- package/dist/transformers/item/edit.d.ts +4 -0
- package/dist/transformers/item/edit.js +21 -0
- package/dist/transformers/item/eloquent.d.ts +4 -0
- package/dist/transformers/item/eloquent.js +158 -0
- package/dist/transformers/item/filter.d.ts +5 -0
- package/dist/transformers/item/filter.js +41 -0
- package/dist/transformers/item/forms.d.ts +4 -0
- package/dist/transformers/item/forms.js +226 -0
- package/dist/transformers/item/laravel.d.ts +15 -0
- package/dist/transformers/item/laravel.js +36 -0
- package/dist/transformers/item/list.d.ts +4 -0
- package/dist/transformers/item/list.js +36 -0
- package/dist/transformers/item/requests.d.ts +4 -0
- package/dist/transformers/item/requests.js +125 -0
- package/dist/transformers/item/show.d.ts +5 -0
- package/dist/transformers/item/show.js +54 -0
- package/package.json +46 -0
- package/templates/eloquent/child.handlebars +13 -0
- package/templates/eloquent/filter.handlebars +88 -0
- package/templates/eloquent/parent.handlebars +64 -0
- package/templates/others/base-controller.handlebars +46 -0
- package/templates/others/controller.handlebars +185 -0
- package/templates/others/pk-trait.handlebars +157 -0
- package/templates/others/request.handlebars +32 -0
- package/templates/others/routes.handlebars +16 -0
- package/templates/views/breadcrumbs.handlebars +21 -0
- package/templates/views/edit.handlebars +41 -0
- package/templates/views/form.handlebars +103 -0
- package/templates/views/icons/check-circle.handlebars +3 -0
- package/templates/views/icons/chevron-down.handlebars +3 -0
- package/templates/views/icons/chevron-right.handlebars +3 -0
- package/templates/views/icons/computer.handlebars +3 -0
- package/templates/views/icons/eye.handlebars +4 -0
- package/templates/views/icons/funnel.handlebars +3 -0
- package/templates/views/icons/home.handlebars +3 -0
- package/templates/views/icons/link.handlebars +3 -0
- package/templates/views/icons/list-bullet.handlebars +3 -0
- package/templates/views/icons/pencil.handlebars +3 -0
- package/templates/views/icons/plus.handlebars +3 -0
- package/templates/views/icons/trash.handlebars +3 -0
- package/templates/views/icons/unlink.handlebars +3 -0
- package/templates/views/icons/x-circle.handlebars +3 -0
- package/templates/views/icons/x.handlebars +3 -0
- package/templates/views/index.handlebars +181 -0
- package/templates/views/loader.handlebars +6 -0
- package/templates/views/menu.handlebars +39 -0
- package/templates/views/modal.handlebars +36 -0
- package/templates/views/record-input.handlebars +90 -0
- package/templates/views/relation-item.handlebars +180 -0
- package/templates/views/relation-list.handlebars +199 -0
- package/templates/views/show.handlebars +134 -0
- package/templates/views/tabs.handlebars +16 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Diego Michelena Polo <damp1991@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://cldup.com/U-06c9VkSH.png" alt="Generathor Logo" width="130">
|
|
3
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="130" preserveAspectRatio="xMidYMid" viewBox="0 0 256 264">
|
|
4
|
+
<path d="m255.9 59.6.1 1.1v56.6c0 1.4-.8 2.8-2 3.5l-47.6 27.4v54.2c0 1.4-.7 2.8-2 3.5l-99.1 57-.7.4-.3.1c-.7.2-1.4.2-2.1 0l-.4-.1-.6-.3L2 206c-1.3-.8-2.1-2.2-2.1-3.6V32.7l.1-1.1.2-.4.3-.6.2-.4.4-.5.4-.3c.2 0 .3-.2.5-.3L51.6.6c1.3-.8 2.9-.8 4.1 0L105.3 29c.2 0 .3.2.4.3l.5.3c0 .2.2.4.3.5l.3.4.3.6.1.4.2 1v106l41.2-23.7V60.7c0-.4 0-.7.2-1l.1-.4.3-.7.3-.3.3-.5.5-.3.4-.4 49.6-28.5c1.2-.7 2.8-.7 4 0L254 57l.5.4.4.3.4.5.2.3c.2.2.2.5.3.7l.2.3Zm-8.2 55.3v-47l-17.3 10-24 13.7v47l41.3-23.7Zm-49.5 85v-47l-23.6 13.5-67.2 38.4v47.5l90.8-52.3ZM8.2 39.9V200l90.9 52.3v-47.5l-47.5-26.9-.4-.4c-.2 0-.3-.1-.4-.3l-.4-.4-.3-.4-.2-.5-.2-.5v-.6l-.2-.5V63.6L25.6 49.8l-17.3-10Zm45.5-31L12.4 32.8l41.3 23.7 41.2-23.7L53.7 8.9ZM75 157.3l24-13.8V39.8l-17.3 10-24 13.8v103.6l17.3-10ZM202.3 36.9 161 60.7l41.3 23.8 41.3-23.8-41.3-23.8Zm-4.1 54.7-24-13.8-17.3-10v47l24 13.9 17.3 10v-47Zm-95 106 60.6-34.5 30.2-17.3-41.2-23.8-47.5 27.4L62 174.3l41.2 23.3Z" fill="#FF2D20"/>
|
|
5
|
+
</svg>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/generathor-laravel">
|
|
10
|
+
<img src="https://img.shields.io/npm/v/generathor-laravel.svg" alt="NPM Version">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://npmcharts.com/compare/generathor-laravel?minimal=true">
|
|
13
|
+
<img src="https://img.shields.io/npm/dt/generathor-laravel.svg" alt="Downloads">
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/generathor-laravel">
|
|
16
|
+
<img src="https://img.shields.io/npm/l/generathor-laravel.svg" alt="License">
|
|
17
|
+
</a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
# Generathor Laravel
|
|
21
|
+
|
|
22
|
+
**Generathor Laravel** allows you to automatically generate Eloquent models and CRUD operations based on your database structure.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Table of Contents
|
|
27
|
+
|
|
28
|
+
1. [Installation](#installation)
|
|
29
|
+
2. [Generating Files](#generating-files)
|
|
30
|
+
1. [Generating Eloquent Models](#generating-eloquent-models)
|
|
31
|
+
2. [Generating Eloquent Models and CRUDs](#generating-eloquent-models-and-cruds)
|
|
32
|
+
3. [Additional Settings](#additional-settings)
|
|
33
|
+
4. [Files](#files)
|
|
34
|
+
5. [TODO](#todo)
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
To begin using Generathor Laravel, install the necessary dependencies:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
$ npm i -D generathor generathor-db generathor-laravel mysql2
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then, create the generathor configuration file:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
$ touch generathor.config.cjs
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> The content of the configuration file will depend on what you want to generate.
|
|
53
|
+
|
|
54
|
+
Add the following script to your `package.json`:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
"scripts": {
|
|
58
|
+
"generathor": "generathor -c generathor.config.cjs"
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Generating Files
|
|
65
|
+
|
|
66
|
+
Whether you need to generate Eloquent models or CRUDs, you must install the PHP dependencies by running the following command:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
$ composer require tucker-eric/eloquentfilter kyslik/column-sortable
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Next, follow one of the steps below.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
### Generating Eloquent Models
|
|
77
|
+
|
|
78
|
+
Your `generathor.config.cjs` file should look like this:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
const { Source } = require('generathor-db');
|
|
82
|
+
const { LaravelGenerator } = require('generathor-laravel');
|
|
83
|
+
|
|
84
|
+
const laravel = new LaravelGenerator({
|
|
85
|
+
createEloquentModelsOnly: true
|
|
86
|
+
});
|
|
87
|
+
const dbSource = new Source({
|
|
88
|
+
type: 'mysql',
|
|
89
|
+
configuration: {
|
|
90
|
+
host: 'localhost',
|
|
91
|
+
port: '3306',
|
|
92
|
+
user: 'my_user',
|
|
93
|
+
password: 'my_password',
|
|
94
|
+
database: 'my_database'
|
|
95
|
+
},
|
|
96
|
+
excludes: ['migrations']
|
|
97
|
+
}, [
|
|
98
|
+
laravel.transformer.bind(laravel)
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
module.exports = {
|
|
102
|
+
sources: {
|
|
103
|
+
db: dbSource,
|
|
104
|
+
},
|
|
105
|
+
generators: laravel.generators()
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Then, run the following command:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
$ npm run generathor
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### Generating Eloquent Models and CRUDs
|
|
118
|
+
|
|
119
|
+
Your `generathor.config.cjs` file should look like this:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
const { Source } = require('generathor-db');
|
|
123
|
+
const { LaravelGenerator } = require('generathor-laravel');
|
|
124
|
+
|
|
125
|
+
const laravel = new LaravelGenerator();
|
|
126
|
+
const dbSource = new Source({
|
|
127
|
+
type: 'mysql',
|
|
128
|
+
configuration: {
|
|
129
|
+
host: 'localhost',
|
|
130
|
+
port: '3306',
|
|
131
|
+
user: 'my_user',
|
|
132
|
+
password: 'my_password',
|
|
133
|
+
database: 'my_database'
|
|
134
|
+
},
|
|
135
|
+
excludes: ['migrations']
|
|
136
|
+
}, [
|
|
137
|
+
laravel.transformer.bind(laravel)
|
|
138
|
+
]);
|
|
139
|
+
|
|
140
|
+
module.exports = {
|
|
141
|
+
sources: {
|
|
142
|
+
db: dbSource,
|
|
143
|
+
},
|
|
144
|
+
generators: laravel.generators()
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Then, run the following command:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
$ npm run generathor
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
To make everything work, it's necessary to set up other things in your project:
|
|
155
|
+
|
|
156
|
+
#### Installing frontend dependencies
|
|
157
|
+
|
|
158
|
+
You need to install TailwindCSS:
|
|
159
|
+
[https://tailwindcss.com/docs/guides/laravel](https://tailwindcss.com/docs/guides/laravel)
|
|
160
|
+
|
|
161
|
+
Also, you need to install the following packages:
|
|
162
|
+
|
|
163
|
+
* alpinejs
|
|
164
|
+
* @alpinejs/collapse
|
|
165
|
+
* laravel-precognition-alpine
|
|
166
|
+
* sweetalert2
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npm i -D alpinejs @alpinejs/collapse laravel-precognition-alpine sweetalert2
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
File `app.js` must contain:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
import Alpine from 'alpinejs';
|
|
176
|
+
import collapse from '@alpinejs/collapse'
|
|
177
|
+
import Precognition from 'laravel-precognition-alpine';
|
|
178
|
+
import Swal from 'sweetalert2';
|
|
179
|
+
|
|
180
|
+
window.Alpine = Alpine;
|
|
181
|
+
window.Swal = Swal;
|
|
182
|
+
|
|
183
|
+
Alpine.plugin(Precognition);
|
|
184
|
+
Alpine.plugin(collapse);
|
|
185
|
+
Alpine.start();
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
File `app.css` must contain:
|
|
189
|
+
|
|
190
|
+
```css
|
|
191
|
+
@import "@fortawesome/fontawesome-free/css/all.css";
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Expose the routes
|
|
195
|
+
|
|
196
|
+
Add generatehor routes to `routes/web.php`:
|
|
197
|
+
|
|
198
|
+
```php
|
|
199
|
+
Route::prefix('manage')->group(function () {
|
|
200
|
+
require __DIR__.'/generathor.php';
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Set up your 'home' route
|
|
205
|
+
|
|
206
|
+
You neet to set up your `home` route. You can change the home route reference in the `generathor.config.cjs` file.
|
|
207
|
+
|
|
208
|
+
```php
|
|
209
|
+
Route::get('/', function () {
|
|
210
|
+
return view('welcome');
|
|
211
|
+
})->name('home');
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Set up datepickers (optional)
|
|
215
|
+
|
|
216
|
+
Install the following package:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npm i -D flatpickr
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Add the following code to `app.js`:
|
|
223
|
+
|
|
224
|
+
```js
|
|
225
|
+
import flatpickr from 'flatpickr';
|
|
226
|
+
|
|
227
|
+
flatpickr('.input-datetime', {
|
|
228
|
+
enableTime: true,
|
|
229
|
+
enableSeconds: true,
|
|
230
|
+
dateFormat: 'Y-m-d H:i:S',
|
|
231
|
+
});
|
|
232
|
+
flatpickr('.input-date', {
|
|
233
|
+
dateFormat: 'Y-m-d',
|
|
234
|
+
});
|
|
235
|
+
flatpickr('.input-time', {
|
|
236
|
+
noCalendar: true,
|
|
237
|
+
enableTime: true,
|
|
238
|
+
enableSeconds: true,
|
|
239
|
+
dateFormat: 'H:i:S',
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Add the following code to `app.css`:
|
|
244
|
+
|
|
245
|
+
```css
|
|
246
|
+
@import "flatpickr/dist/flatpickr.css";
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Set up loading spinner (optional)
|
|
250
|
+
|
|
251
|
+
Add the following code to `app.js`:
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
const loader = document.getElementById('generathor-loader');
|
|
255
|
+
window.showLoading = () => {
|
|
256
|
+
if (loader) {
|
|
257
|
+
loader.classList.remove('hidden');
|
|
258
|
+
loader.classList.add('flex');
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
window.hideLoading = () => {
|
|
262
|
+
if (loader) {
|
|
263
|
+
loader.classList.remove('flex');
|
|
264
|
+
loader.classList.add('hidden');
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const forms = document.getElementsByTagName('form');
|
|
269
|
+
for (const form of forms) {
|
|
270
|
+
form.addEventListener('submit', window.showLoading);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Only for Livewire
|
|
274
|
+
if (typeof Livewire !== undefined) {
|
|
275
|
+
Livewire.hook('commit', ({ succeed, fail }) => {
|
|
276
|
+
succeed(() => {
|
|
277
|
+
window.hideLoading();
|
|
278
|
+
});
|
|
279
|
+
fail(() => {
|
|
280
|
+
window.hideLoading();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Add the following code in `layout.blade.php` or in your layout:
|
|
287
|
+
|
|
288
|
+
```blade
|
|
289
|
+
<x-generathor.loader />
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### Set up header (optional)
|
|
293
|
+
|
|
294
|
+
You can define a header in your layout. For example, in `layout.blade.php` or in your layout:
|
|
295
|
+
|
|
296
|
+
```blade
|
|
297
|
+
@if(isset($header))
|
|
298
|
+
<div>
|
|
299
|
+
{{$header}}
|
|
300
|
+
</div>
|
|
301
|
+
@endif
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## Additional settings
|
|
307
|
+
|
|
308
|
+
You can modify settings in the `generathor.config.cjs` file.
|
|
309
|
+
|
|
310
|
+
| Variable | Required | Type | Default | Description |
|
|
311
|
+
|----------------------------|----------|------------------------|--------------------------------------|-------------------------------------------------------------------------------------|
|
|
312
|
+
| `createChildModel` | `No` | boolean | true | Prevents overwriting the child class of a model, so you retain your custom changes. |
|
|
313
|
+
| `createEloquentModelsOnly` | `No` | boolean | false | Creates only Eloquent models, skipping the generation of other files. |
|
|
314
|
+
| `reference` | `No` | string | 'laravel-generathor' | Reference name used in templates. |
|
|
315
|
+
| `source` | `No` | string | 'db' | Reference to the Generathor source for database structure. |
|
|
316
|
+
| `directory` | `No` | string | '.' | Directory path for the Laravel project. |
|
|
317
|
+
| `homeRoute` | `No` | string | 'home' | Initial base route, used for redirection to the home page. |
|
|
318
|
+
| `layout` | `No` | string | 'layout' | Main layout of your project. |
|
|
319
|
+
| `eloquent` | `No` | object | | Object for defining parent classes for models. |
|
|
320
|
+
| `eloquent.parent` | `No` | string | 'Illuminate\Database\Eloquent\Model' | General parent class for models. |
|
|
321
|
+
| `eloquent.customParents` | `No` | Record<string, string> | {} | Parent class by table, allowing custom parent classes for specific tables. |
|
|
322
|
+
|
|
323
|
+
Example
|
|
324
|
+
|
|
325
|
+
```js
|
|
326
|
+
const { Source } = require('generathor-db');
|
|
327
|
+
const { LaravelGenerator }= require('generathor-laravel-testing');
|
|
328
|
+
|
|
329
|
+
const laravel = new LaravelGenerator({
|
|
330
|
+
ccreateChildModel: true,
|
|
331
|
+
createEloquentModelsOnly: false,
|
|
332
|
+
reference: 'laravel',
|
|
333
|
+
source: 'db2',
|
|
334
|
+
directory: './project',
|
|
335
|
+
homeRoute: 'index',
|
|
336
|
+
layout: 'app',
|
|
337
|
+
eloquent: {
|
|
338
|
+
parent: 'App\\Models\\Model',
|
|
339
|
+
customParents: {
|
|
340
|
+
users: 'App\\Models\\Jetstream\\User as Model',
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
const dbSource = new Source({
|
|
345
|
+
type: 'mysql',
|
|
346
|
+
configuration: {
|
|
347
|
+
host: 'localhost',
|
|
348
|
+
port: '3306',
|
|
349
|
+
user: 'my_user',
|
|
350
|
+
password: 'my_password',
|
|
351
|
+
database: 'my_database'
|
|
352
|
+
},
|
|
353
|
+
excludes: ['migrations']
|
|
354
|
+
}, [
|
|
355
|
+
laravel.transformer.bind(laravel)
|
|
356
|
+
]);
|
|
357
|
+
|
|
358
|
+
module.exports = {
|
|
359
|
+
sources: {
|
|
360
|
+
db: dbSource,
|
|
361
|
+
},
|
|
362
|
+
generators: laravel.generators()
|
|
363
|
+
};
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Files
|
|
369
|
+
|
|
370
|
+
* `app/Models/Generathor/[model].php` (for each table)
|
|
371
|
+
* `app/Models/[model].php` (for each table)
|
|
372
|
+
* `app/ModelFilters/[filter].php` (for each table)
|
|
373
|
+
* `app/Http/Requests/Generathor/[create-request].php` (for each table)
|
|
374
|
+
* `app/Http/Requests/Generathor/[update-request].php` (for each table)
|
|
375
|
+
* `app/Http/Requests/Generathor/[filter-request].php` (for each table)
|
|
376
|
+
* `app/Http/Requests/Generathor/[attach-request].php` (for each 'has-many' relationship in each table)
|
|
377
|
+
* `resources/views/generathor/menu.blade.php`
|
|
378
|
+
* `routes/generathor.php`
|
|
379
|
+
* `app/Http/Controllers/Generathor/Controller.php`
|
|
380
|
+
* `app/Http/Controllers/Generathor/[controller].php` (for each table)
|
|
381
|
+
* `resources/views/generathor/[table-context]/index.blade.php` (for each table)
|
|
382
|
+
* `resources/views/generathor/[table-context]/edit.blade.php` (for each table)
|
|
383
|
+
* `resources/views/generathor/[table-context]/show.blade.php` (for each table)
|
|
384
|
+
* `resources/views/generathor/[table-context]/[relation].blade.php` (for each relationship in each table)
|
|
385
|
+
* `resources/views/components/generathor/[table-context]/create-form.blade.php` (for each table)
|
|
386
|
+
* `resources/views/components/generathor/[table-context]/filter-form.blade.php` (for each table)
|
|
387
|
+
* `resources/views/components/generathor/[table-context]/update-form.blade.php` (for each table)
|
|
388
|
+
* `resources/views/components/generathor/[table-context]/[attach-form].blade.php` (for each 'has-many' relationship in each table)
|
|
389
|
+
* `resources/views/components/generathor/[table-context]/[create-form].blade.php` (for each relationship in each table)
|
|
390
|
+
* `resources/views/components/generathor/[table-context]/[filter-form].blade.php` (for each 'has-many' relationship in each table)
|
|
391
|
+
* `app/Models/Generathor/GenerathorKey.php`
|
|
392
|
+
* `resources/views/components/generathor/record-input.blade.php`
|
|
393
|
+
* `resources/views/components/generathor/breadcrumbs.blade.php`
|
|
394
|
+
* `resources/views/components/generathor/tabs.blade.php`
|
|
395
|
+
* `resources/views/components/generathor/modal.blade.php`
|
|
396
|
+
* `resources/views/components/generathor/loader.blade.php`
|
|
397
|
+
* `resources/views/components/generathor/icon-check-circle.blade.php`
|
|
398
|
+
* `resources/views/components/generathor/icon-chevron-right.blade.php`
|
|
399
|
+
* `resources/views/components/generathor/icon-computer.blade.php`
|
|
400
|
+
* `resources/views/components/generathor/icon-eye.blade.php`
|
|
401
|
+
* `resources/views/components/generathor/icon-funnel.blade.php`
|
|
402
|
+
* `resources/views/components/generathor/icon-home.blade.php`
|
|
403
|
+
* `resources/views/components/generathor/icon-pencil.blade.php`
|
|
404
|
+
* `resources/views/components/generathor/icon-plus.blade.php`
|
|
405
|
+
* `resources/views/components/generathor/icon-trash.blade.php`
|
|
406
|
+
* `resources/views/components/generathor/icon-x-circle.blade.php`
|
|
407
|
+
* `resources/views/components/generathor/icon-x.blade.php`
|
|
408
|
+
* `resources/views/components/generathor/icon-chevron-down.blade.php`
|
|
409
|
+
* `resources/views/components/generathor/icon-list-bullet.blade.php`
|
|
410
|
+
* `resources/views/components/generathor/icon-link.blade.php`
|
|
411
|
+
* `resources/views/components/generathor/icon-unlink.blade.php`
|
|
412
|
+
|
|
413
|
+
---
|
|
414
|
+
|
|
415
|
+
## TODO
|
|
416
|
+
|
|
417
|
+
- [ ] Separate inputs into components.
|
|
418
|
+
- [ ] Customize inputs based on prefix or specific logic.
|
|
419
|
+
- [ ] TBD
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type ConfigurationType = {
|
|
2
|
+
createChildModel?: boolean;
|
|
3
|
+
createEloquentModelsOnly?: boolean;
|
|
4
|
+
reference?: string;
|
|
5
|
+
source?: string;
|
|
6
|
+
directory?: string;
|
|
7
|
+
homeRoute?: string;
|
|
8
|
+
layout?: string;
|
|
9
|
+
eloquent?: {
|
|
10
|
+
parent?: string;
|
|
11
|
+
customParents?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare class Configuration {
|
|
15
|
+
private $attributes;
|
|
16
|
+
constructor($attributes: ConfigurationType);
|
|
17
|
+
directory(): string;
|
|
18
|
+
reference(): string;
|
|
19
|
+
source(): string;
|
|
20
|
+
homeRoute(): string;
|
|
21
|
+
layout(): string;
|
|
22
|
+
eloquentParent(table: string): string;
|
|
23
|
+
createChildModel(): boolean;
|
|
24
|
+
createEloquentModelsOnly(): boolean;
|
|
25
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Configuration = void 0;
|
|
4
|
+
class Configuration {
|
|
5
|
+
constructor($attributes) {
|
|
6
|
+
this.$attributes = $attributes;
|
|
7
|
+
}
|
|
8
|
+
directory() {
|
|
9
|
+
return this.$attributes.directory || '.';
|
|
10
|
+
}
|
|
11
|
+
reference() {
|
|
12
|
+
return this.$attributes.reference || 'laravel-generathor';
|
|
13
|
+
}
|
|
14
|
+
source() {
|
|
15
|
+
return this.$attributes.source || 'db';
|
|
16
|
+
}
|
|
17
|
+
homeRoute() {
|
|
18
|
+
return this.$attributes.homeRoute || 'home';
|
|
19
|
+
}
|
|
20
|
+
layout() {
|
|
21
|
+
return this.$attributes.layout || 'layout';
|
|
22
|
+
}
|
|
23
|
+
eloquentParent(table) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const map = ((_a = this.$attributes.eloquent) === null || _a === void 0 ? void 0 : _a.customParents) || {};
|
|
26
|
+
if (map[table]) {
|
|
27
|
+
return map[table];
|
|
28
|
+
}
|
|
29
|
+
return (((_b = this.$attributes.eloquent) === null || _b === void 0 ? void 0 : _b.parent) ||
|
|
30
|
+
'Illuminate\\Database\\Eloquent\\Model');
|
|
31
|
+
}
|
|
32
|
+
createChildModel() {
|
|
33
|
+
return typeof this.$attributes.createChildModel === 'undefined'
|
|
34
|
+
? true
|
|
35
|
+
: this.$attributes.createChildModel;
|
|
36
|
+
}
|
|
37
|
+
createEloquentModelsOnly() {
|
|
38
|
+
return typeof this.$attributes.createEloquentModelsOnly === 'undefined'
|
|
39
|
+
? false
|
|
40
|
+
: this.$attributes.createEloquentModelsOnly;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Configuration = Configuration;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HandlebarsHelper = void 0;
|
|
7
|
+
const handlebars_1 = __importDefault(require("handlebars"));
|
|
8
|
+
let configured = false;
|
|
9
|
+
class HandlebarsHelper {
|
|
10
|
+
static configure() {
|
|
11
|
+
if (configured) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
handlebars_1.default.registerHelper('eq', (arg1, arg2) => arg1 == arg2);
|
|
15
|
+
handlebars_1.default.registerHelper('not', (val) => !val);
|
|
16
|
+
handlebars_1.default.registerHelper('concat', (arg1, arg2) => arg1 + arg2);
|
|
17
|
+
configured = true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.HandlebarsHelper = HandlebarsHelper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Column, Relation } from 'generathor-db';
|
|
2
|
+
declare class Naming {
|
|
3
|
+
relationAttribute(relation: Relation, table: string): string;
|
|
4
|
+
capitalizedRelationAttribute(relation: Relation, table: string): string;
|
|
5
|
+
modelClass(table: string): string;
|
|
6
|
+
controller(table: string): string;
|
|
7
|
+
columnAttribute(column: Column): string;
|
|
8
|
+
columnLabel(column: Column): string;
|
|
9
|
+
label(text: string): string;
|
|
10
|
+
singularLabel(text: string): string;
|
|
11
|
+
context(table: string): string;
|
|
12
|
+
relationContext(relation: Relation, table: string): string;
|
|
13
|
+
relationLabel(relation: Relation, table: string): string;
|
|
14
|
+
listLabel(table: string): string;
|
|
15
|
+
recordName(table: string): string;
|
|
16
|
+
}
|
|
17
|
+
declare const _default: Naming;
|
|
18
|
+
export default _default;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const string_1 = __importDefault(require("./string"));
|
|
7
|
+
class Naming {
|
|
8
|
+
relationAttribute(relation, table) {
|
|
9
|
+
if (relation.columns.length !== 1) {
|
|
10
|
+
return relation.type === 'has-many'
|
|
11
|
+
? string_1.default.fromSnakeToPluralCamel(relation.on.table)
|
|
12
|
+
: string_1.default.fromSnakeToSingularCamel(relation.on.table);
|
|
13
|
+
}
|
|
14
|
+
if (relation.type !== 'has-many') {
|
|
15
|
+
return string_1.default.fromSnakeToSingularCamel(relation.columns[0].replace(/_id$/, ''));
|
|
16
|
+
}
|
|
17
|
+
//Has many relationship
|
|
18
|
+
const fk = relation.references[0].replace(/_id$/, '');
|
|
19
|
+
if (table === string_1.default.fromSnakeToSingularSnake(fk) ||
|
|
20
|
+
table === string_1.default.fromSnakeToPluralSnake(fk)) {
|
|
21
|
+
return string_1.default.fromSnakeToPluralCamel(relation.on.table);
|
|
22
|
+
}
|
|
23
|
+
return (string_1.default.fromSnakeToPluralCamel(relation.on.table) +
|
|
24
|
+
'As' +
|
|
25
|
+
string_1.default.fromSnakeToSingularPascal(fk));
|
|
26
|
+
}
|
|
27
|
+
capitalizedRelationAttribute(relation, table) {
|
|
28
|
+
return string_1.default.capitalize(this.relationAttribute(relation, table));
|
|
29
|
+
}
|
|
30
|
+
modelClass(table) {
|
|
31
|
+
const name = string_1.default.fromSnakeToSingularPascal(table);
|
|
32
|
+
return name === 'Class' ? name + 'Model' : name;
|
|
33
|
+
}
|
|
34
|
+
controller(table) {
|
|
35
|
+
return string_1.default.fromSnakeToSingularPascal(table) + 'Controller';
|
|
36
|
+
}
|
|
37
|
+
columnAttribute(column) {
|
|
38
|
+
return string_1.default.fromSnakeToCamel(column.name);
|
|
39
|
+
}
|
|
40
|
+
columnLabel(column) {
|
|
41
|
+
return this.label(column.name);
|
|
42
|
+
}
|
|
43
|
+
label(text) {
|
|
44
|
+
return string_1.default.fromSnakeToLabel(text.replace(/_id$/, ''));
|
|
45
|
+
}
|
|
46
|
+
singularLabel(text) {
|
|
47
|
+
return string_1.default.fromSnakeToSingularLabel(text);
|
|
48
|
+
}
|
|
49
|
+
context(table) {
|
|
50
|
+
return string_1.default.fromSnakeToKebab(table);
|
|
51
|
+
}
|
|
52
|
+
relationContext(relation, table) {
|
|
53
|
+
if (relation.columns.length !== 1) {
|
|
54
|
+
return relation.type === 'has-many'
|
|
55
|
+
? string_1.default.fromSnakeToPluralKebab(relation.on.table)
|
|
56
|
+
: string_1.default.fromSnakeToSingularKebab(relation.on.table);
|
|
57
|
+
}
|
|
58
|
+
if (relation.type !== 'has-many') {
|
|
59
|
+
return string_1.default.fromSnakeToSingularKebab(relation.columns[0].replace(/_id$/, ''));
|
|
60
|
+
}
|
|
61
|
+
//Has many relationship
|
|
62
|
+
const fk = relation.references[0].replace(/_id$/, '');
|
|
63
|
+
if (table === string_1.default.fromSnakeToSingularSnake(fk) ||
|
|
64
|
+
table === string_1.default.fromSnakeToPluralSnake(fk)) {
|
|
65
|
+
return string_1.default.fromSnakeToPluralKebab(relation.on.table);
|
|
66
|
+
}
|
|
67
|
+
return (string_1.default.fromSnakeToPluralKebab(relation.on.table) +
|
|
68
|
+
'-as-' +
|
|
69
|
+
string_1.default.fromSnakeToSingularKebab(fk));
|
|
70
|
+
}
|
|
71
|
+
relationLabel(relation, table) {
|
|
72
|
+
if (relation.columns.length !== 1) {
|
|
73
|
+
return relation.type === 'has-many'
|
|
74
|
+
? string_1.default.fromSnakeToPluralLabel(relation.on.table)
|
|
75
|
+
: string_1.default.fromSnakeToSingularLabel(relation.on.table);
|
|
76
|
+
}
|
|
77
|
+
if (relation.type !== 'has-many') {
|
|
78
|
+
return string_1.default.fromSnakeToSingularLabel(relation.columns[0].replace(/_id$/, ''));
|
|
79
|
+
}
|
|
80
|
+
//Has many relationship
|
|
81
|
+
const fk = relation.references[0].replace(/_id$/, '');
|
|
82
|
+
if (table === string_1.default.fromSnakeToSingularSnake(fk) ||
|
|
83
|
+
table === string_1.default.fromSnakeToPluralSnake(fk)) {
|
|
84
|
+
return string_1.default.fromSnakeToPluralLabel(relation.on.table);
|
|
85
|
+
}
|
|
86
|
+
return (string_1.default.fromSnakeToPluralLabel(relation.on.table) +
|
|
87
|
+
' as ' +
|
|
88
|
+
string_1.default.fromSnakeToSingularLabel(fk).toLowerCase());
|
|
89
|
+
}
|
|
90
|
+
listLabel(table) {
|
|
91
|
+
return string_1.default.fromSnakeToPluralLabel(table);
|
|
92
|
+
}
|
|
93
|
+
recordName(table) {
|
|
94
|
+
const recordName = string_1.default.fromSnakeToSingularCamel(table);
|
|
95
|
+
return recordName.length > 32 ? 'record' : recordName;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.default = new Naming();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
declare class StringHelper {
|
|
2
|
+
fromSnakeToSingularPascal(text: string): string;
|
|
3
|
+
fromSnakeToPluralPascal(text: string): string;
|
|
4
|
+
fromSnakeToPascal(text: string): string;
|
|
5
|
+
fromSnakeToSingularSnake(text: string): string;
|
|
6
|
+
fromSnakeToPluralSnake(text: string): string;
|
|
7
|
+
fromSnakeToSingularKebab(text: string): string;
|
|
8
|
+
fromSnakeToPluralKebab(text: string): string;
|
|
9
|
+
fromSnakeToKebab(text: string): string;
|
|
10
|
+
fromSnakeToSingularCamel(text: string): string;
|
|
11
|
+
fromSnakeToPluralCamel(text: string): string;
|
|
12
|
+
fromSnakeToCamel(text: string): string;
|
|
13
|
+
fromSnakeToPluralLabel(text: string): string;
|
|
14
|
+
fromSnakeToSingularLabel(text: string): string;
|
|
15
|
+
fromSnakeToLabel(text: string): string;
|
|
16
|
+
capitalize(text: string): string;
|
|
17
|
+
uncapitalize(text: string): string;
|
|
18
|
+
className(text: string): string;
|
|
19
|
+
classLabel(text: string): string;
|
|
20
|
+
columnLabel(text: string): string;
|
|
21
|
+
toPluralKebab(text: string): string;
|
|
22
|
+
toPluralLabel(text: string): string;
|
|
23
|
+
toSingularLabel(text: string): string;
|
|
24
|
+
toSingularKebab(text: string): string;
|
|
25
|
+
}
|
|
26
|
+
declare const _default: StringHelper;
|
|
27
|
+
export default _default;
|