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
|
@@ -0,0 +1,120 @@
|
|
|
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 pluralize_1 = __importDefault(require("pluralize"));
|
|
7
|
+
class StringHelper {
|
|
8
|
+
fromSnakeToSingularPascal(text) {
|
|
9
|
+
return text
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.split('_')
|
|
12
|
+
.map((part) => {
|
|
13
|
+
return this.capitalize(pluralize_1.default.singular(part));
|
|
14
|
+
})
|
|
15
|
+
.join('');
|
|
16
|
+
}
|
|
17
|
+
fromSnakeToPluralPascal(text) {
|
|
18
|
+
const parts = text.toLowerCase().split('_');
|
|
19
|
+
return parts
|
|
20
|
+
.map((part, index) => {
|
|
21
|
+
return index === parts.length - 1
|
|
22
|
+
? this.capitalize(pluralize_1.default.plural(part))
|
|
23
|
+
: this.capitalize(pluralize_1.default.singular(part));
|
|
24
|
+
})
|
|
25
|
+
.join('');
|
|
26
|
+
}
|
|
27
|
+
fromSnakeToPascal(text) {
|
|
28
|
+
return text.toLowerCase().split('_').map(this.capitalize).join('');
|
|
29
|
+
}
|
|
30
|
+
fromSnakeToSingularSnake(text) {
|
|
31
|
+
return text.toLowerCase().split('_').map(pluralize_1.default.singular).join('_');
|
|
32
|
+
}
|
|
33
|
+
fromSnakeToPluralSnake(text) {
|
|
34
|
+
const parts = text.toLowerCase().split('_');
|
|
35
|
+
return parts
|
|
36
|
+
.map((part, index) => {
|
|
37
|
+
return index === parts.length - 1
|
|
38
|
+
? pluralize_1.default.plural(part)
|
|
39
|
+
: pluralize_1.default.singular(part);
|
|
40
|
+
})
|
|
41
|
+
.join('_');
|
|
42
|
+
}
|
|
43
|
+
fromSnakeToSingularKebab(text) {
|
|
44
|
+
return text.toLowerCase().split('_').map(pluralize_1.default.singular).join('-');
|
|
45
|
+
}
|
|
46
|
+
fromSnakeToPluralKebab(text) {
|
|
47
|
+
const parts = text.toLowerCase().split('_');
|
|
48
|
+
return parts
|
|
49
|
+
.map((part, index) => {
|
|
50
|
+
return index === parts.length - 1
|
|
51
|
+
? pluralize_1.default.plural(part)
|
|
52
|
+
: pluralize_1.default.singular(part);
|
|
53
|
+
})
|
|
54
|
+
.join('-');
|
|
55
|
+
}
|
|
56
|
+
fromSnakeToKebab(text) {
|
|
57
|
+
return text.toLowerCase().split('_').join('-');
|
|
58
|
+
}
|
|
59
|
+
fromSnakeToSingularCamel(text) {
|
|
60
|
+
return this.uncapitalize(this.fromSnakeToSingularPascal(text));
|
|
61
|
+
}
|
|
62
|
+
fromSnakeToPluralCamel(text) {
|
|
63
|
+
return this.uncapitalize(this.fromSnakeToPluralPascal(text));
|
|
64
|
+
}
|
|
65
|
+
fromSnakeToCamel(text) {
|
|
66
|
+
return this.uncapitalize(this.fromSnakeToPascal(text));
|
|
67
|
+
}
|
|
68
|
+
fromSnakeToPluralLabel(text) {
|
|
69
|
+
const parts = text.toLowerCase().split('_');
|
|
70
|
+
return this.capitalize(parts
|
|
71
|
+
.map((part, index) => {
|
|
72
|
+
return index === parts.length - 1
|
|
73
|
+
? pluralize_1.default.plural(part)
|
|
74
|
+
: pluralize_1.default.singular(part);
|
|
75
|
+
})
|
|
76
|
+
.join(' '));
|
|
77
|
+
}
|
|
78
|
+
fromSnakeToSingularLabel(text) {
|
|
79
|
+
return this.capitalize(text.toLowerCase().split('_').map(pluralize_1.default.singular).join(' '));
|
|
80
|
+
}
|
|
81
|
+
fromSnakeToLabel(text) {
|
|
82
|
+
return this.capitalize(text.toLowerCase().split('_').join(' '));
|
|
83
|
+
}
|
|
84
|
+
//Delete this comment
|
|
85
|
+
//Helpers of helper
|
|
86
|
+
capitalize(text) {
|
|
87
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
88
|
+
}
|
|
89
|
+
uncapitalize(text) {
|
|
90
|
+
return text.charAt(0).toLowerCase() + text.slice(1);
|
|
91
|
+
}
|
|
92
|
+
//Delete this
|
|
93
|
+
className(text) {
|
|
94
|
+
const name = this.fromSnakeToSingularPascal(text);
|
|
95
|
+
return name === 'Class' ? name + 'Model' : name;
|
|
96
|
+
}
|
|
97
|
+
classLabel(text) {
|
|
98
|
+
return this.capitalize(text.toLowerCase().split('_').join(' '));
|
|
99
|
+
}
|
|
100
|
+
columnLabel(text) {
|
|
101
|
+
return this.capitalize(text.toLowerCase().split('_').join(' '));
|
|
102
|
+
}
|
|
103
|
+
toPluralKebab(text) {
|
|
104
|
+
const parts = text.toLowerCase().split('_');
|
|
105
|
+
parts[parts.length - 1] = pluralize_1.default.plural(parts[parts.length - 1]);
|
|
106
|
+
return parts.join('-');
|
|
107
|
+
}
|
|
108
|
+
toPluralLabel(text) {
|
|
109
|
+
const parts = text.toLowerCase().split('_');
|
|
110
|
+
parts[parts.length - 1] = pluralize_1.default.plural(parts[parts.length - 1]);
|
|
111
|
+
return this.capitalize(parts.join(' '));
|
|
112
|
+
}
|
|
113
|
+
toSingularLabel(text) {
|
|
114
|
+
return this.capitalize(text.toLowerCase().split('_').map(pluralize_1.default.singular).join(' '));
|
|
115
|
+
}
|
|
116
|
+
toSingularKebab(text) {
|
|
117
|
+
return text.toLowerCase().split('_').map(pluralize_1.default.singular).join('-');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.default = new StringHelper();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateRuleType = exports.ruleType = exports.phpType = void 0;
|
|
4
|
+
const typeMapper = {
|
|
5
|
+
string: 'string',
|
|
6
|
+
date: 'string|Carbon',
|
|
7
|
+
int: 'int',
|
|
8
|
+
float: 'float',
|
|
9
|
+
bool: 'bool',
|
|
10
|
+
};
|
|
11
|
+
const ruleTypeMapper = {
|
|
12
|
+
string: 'string',
|
|
13
|
+
date: 'date',
|
|
14
|
+
int: 'int',
|
|
15
|
+
float: 'decimal',
|
|
16
|
+
bool: 'boolean',
|
|
17
|
+
};
|
|
18
|
+
const dateSubTypeRuleMapper = {
|
|
19
|
+
datetime: 'date_format:Y-m-d H:i:s',
|
|
20
|
+
time: 'date_format:H:i:s',
|
|
21
|
+
date: 'date',
|
|
22
|
+
};
|
|
23
|
+
function phpType(type) {
|
|
24
|
+
return typeMapper[type];
|
|
25
|
+
}
|
|
26
|
+
exports.phpType = phpType;
|
|
27
|
+
function ruleType(column) {
|
|
28
|
+
let rule = ruleTypeMapper[column.type];
|
|
29
|
+
if (rule === 'decimal') {
|
|
30
|
+
rule = `${rule}:0,${column.scale}`;
|
|
31
|
+
}
|
|
32
|
+
if (column.unsigned) {
|
|
33
|
+
rule = `${rule}|min:0`;
|
|
34
|
+
}
|
|
35
|
+
return rule;
|
|
36
|
+
}
|
|
37
|
+
exports.ruleType = ruleType;
|
|
38
|
+
function dateRuleType(column) {
|
|
39
|
+
return dateSubTypeRuleMapper[column.subType || 'date'];
|
|
40
|
+
}
|
|
41
|
+
exports.dateRuleType = dateRuleType;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./template"), exports);
|
|
18
|
+
__exportStar(require("./configuration"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GeneratorForCollection, GeneratorForItem } from 'generathor';
|
|
2
|
+
import { Configuration } from './configuration';
|
|
3
|
+
import { Item } from 'generathor-db';
|
|
4
|
+
type GeneratorType = GeneratorForItem | GeneratorForCollection;
|
|
5
|
+
type Templates = Record<string, GeneratorType>;
|
|
6
|
+
export declare class LaravelGenerator {
|
|
7
|
+
private $configuration;
|
|
8
|
+
constructor(configuration?: Configuration);
|
|
9
|
+
private templateKey;
|
|
10
|
+
private templateFile;
|
|
11
|
+
private directory;
|
|
12
|
+
transformer(item: Item): void;
|
|
13
|
+
generators(): {
|
|
14
|
+
[x: string]: GeneratorType;
|
|
15
|
+
};
|
|
16
|
+
generatorsForItems(): Templates;
|
|
17
|
+
generatorsForCollections(): Templates;
|
|
18
|
+
generatorsForStaticFiles(): Templates;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LaravelGenerator = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const generathor_1 = require("generathor");
|
|
6
|
+
const configuration_1 = require("./configuration");
|
|
7
|
+
const laravel_1 = require("./transformers/item/laravel");
|
|
8
|
+
const menu_1 = require("./transformers/collection/menu");
|
|
9
|
+
const route_1 = require("./transformers/collection/route");
|
|
10
|
+
const attachRequest_1 = require("./transformers/collection/attachRequest");
|
|
11
|
+
const controller_1 = require("./transformers/collection/controller");
|
|
12
|
+
const attachForm_1 = require("./transformers/collection/attachForm");
|
|
13
|
+
const createRelationForm_1 = require("./transformers/collection/createRelationForm");
|
|
14
|
+
const filterRelationForm_1 = require("./transformers/collection/filterRelationForm");
|
|
15
|
+
const baseController_1 = require("./transformers/collection/baseController");
|
|
16
|
+
const belongsToRelation_1 = require("./transformers/collection/belongsToRelation");
|
|
17
|
+
const hasManyRelation_1 = require("./transformers/collection/hasManyRelation");
|
|
18
|
+
const handlebars_1 = require("./helpers/handlebars");
|
|
19
|
+
class LaravelGenerator {
|
|
20
|
+
constructor(configuration) {
|
|
21
|
+
if (!configuration) {
|
|
22
|
+
configuration = new configuration_1.Configuration({});
|
|
23
|
+
}
|
|
24
|
+
this.$configuration = configuration;
|
|
25
|
+
handlebars_1.HandlebarsHelper.configure();
|
|
26
|
+
}
|
|
27
|
+
templateKey(key) {
|
|
28
|
+
return `${this.$configuration.reference()}-${key}`;
|
|
29
|
+
}
|
|
30
|
+
templateFile(file) {
|
|
31
|
+
return (0, path_1.resolve)(__dirname, `../templates/${file}.handlebars`);
|
|
32
|
+
}
|
|
33
|
+
directory(path) {
|
|
34
|
+
return this.$configuration.directory() + path;
|
|
35
|
+
}
|
|
36
|
+
transformer(item) {
|
|
37
|
+
new laravel_1.Laravel(item, this.$configuration).transform();
|
|
38
|
+
}
|
|
39
|
+
generators() {
|
|
40
|
+
return {
|
|
41
|
+
...this.generatorsForItems(),
|
|
42
|
+
...this.generatorsForCollections(),
|
|
43
|
+
...this.generatorsForStaticFiles(),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
generatorsForItems() {
|
|
47
|
+
const templates = {};
|
|
48
|
+
templates[this.templateKey('parent-model')] = new generathor_1.GeneratorForItem({
|
|
49
|
+
template: this.templateFile('eloquent/parent'),
|
|
50
|
+
source: this.$configuration.source(),
|
|
51
|
+
directory: this.directory('/app/Models/Generathor'),
|
|
52
|
+
prepareItems: (items) => items.map((item) => item.laravel.eloquent),
|
|
53
|
+
fileName: (item) => item.model + '.php',
|
|
54
|
+
});
|
|
55
|
+
if (this.$configuration.createChildModel()) {
|
|
56
|
+
templates[this.templateKey('child-model')] = new generathor_1.GeneratorForItem({
|
|
57
|
+
template: this.templateFile('eloquent/child'),
|
|
58
|
+
source: this.$configuration.source(),
|
|
59
|
+
directory: this.directory('/app/Models'),
|
|
60
|
+
prepareItems: (items) => items.map((item) => item.laravel.eloquent),
|
|
61
|
+
fileName: (item) => item.model + '.php',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
templates[this.templateKey('filter-model')] = new generathor_1.GeneratorForItem({
|
|
65
|
+
template: this.templateFile('eloquent/filter'),
|
|
66
|
+
source: this.$configuration.source(),
|
|
67
|
+
directory: this.directory('/app/ModelFilters'),
|
|
68
|
+
prepareItems: (items) => items.map((item) => item.laravel.filter),
|
|
69
|
+
fileName: (item) => item.class + '.php',
|
|
70
|
+
});
|
|
71
|
+
if (this.$configuration.createEloquentModelsOnly()) {
|
|
72
|
+
return templates;
|
|
73
|
+
}
|
|
74
|
+
templates[this.templateKey('create-request')] = new generathor_1.GeneratorForItem({
|
|
75
|
+
template: this.templateFile('others/request'),
|
|
76
|
+
source: this.$configuration.source(),
|
|
77
|
+
directory: this.directory('/app/Http/Requests/Generathor'),
|
|
78
|
+
prepareItems: (items) => items.map((item) => item.laravel.requests.create),
|
|
79
|
+
fileName: (item) => item.class + '.php',
|
|
80
|
+
});
|
|
81
|
+
templates[this.templateKey('update-request')] = new generathor_1.GeneratorForItem({
|
|
82
|
+
template: this.templateFile('others/request'),
|
|
83
|
+
source: this.$configuration.source(),
|
|
84
|
+
directory: this.directory('/app/Http/Requests/Generathor'),
|
|
85
|
+
prepareItems: (items) => items.map((item) => item.laravel.requests.update),
|
|
86
|
+
fileName: (item) => item.class + '.php',
|
|
87
|
+
});
|
|
88
|
+
templates[this.templateKey('filter-request')] = new generathor_1.GeneratorForItem({
|
|
89
|
+
template: this.templateFile('others/request'),
|
|
90
|
+
source: this.$configuration.source(),
|
|
91
|
+
directory: this.directory('/app/Http/Requests/Generathor'),
|
|
92
|
+
prepareItems: (items) => items.map((item) => item.laravel.requests.filter),
|
|
93
|
+
fileName: (item) => item.class + '.php',
|
|
94
|
+
});
|
|
95
|
+
templates[this.templateKey('attach-request')] = new generathor_1.GeneratorForItem({
|
|
96
|
+
template: this.templateFile('others/request'),
|
|
97
|
+
source: this.$configuration.source(),
|
|
98
|
+
directory: this.directory('/app/Http/Requests/Generathor'),
|
|
99
|
+
prepareItems: (items) => new attachRequest_1.AttachRequest(items, this.$configuration).transform(),
|
|
100
|
+
fileName: (item) => item.class + '.php',
|
|
101
|
+
});
|
|
102
|
+
templates[this.templateKey('menu')] = new generathor_1.GeneratorForItem({
|
|
103
|
+
template: this.templateFile('views/menu'),
|
|
104
|
+
source: this.$configuration.source(),
|
|
105
|
+
directory: this.directory('/resources/views/generathor'),
|
|
106
|
+
prepareItems: (items) => new menu_1.Menu(items, this.$configuration).transform(),
|
|
107
|
+
fileName: () => 'menu.blade.php',
|
|
108
|
+
});
|
|
109
|
+
templates[this.templateKey('base-controller')] = new generathor_1.GeneratorForItem({
|
|
110
|
+
template: this.templateFile('others/base-controller'),
|
|
111
|
+
source: this.$configuration.source(),
|
|
112
|
+
directory: this.directory('/app/Http/Controllers/Generathor'),
|
|
113
|
+
prepareItems: (items) => new baseController_1.BaseController(items, this.$configuration).transform(),
|
|
114
|
+
fileName: () => 'Controller.php',
|
|
115
|
+
});
|
|
116
|
+
templates[this.templateKey('create-form')] = new generathor_1.GeneratorForItem({
|
|
117
|
+
template: this.templateFile('views/form'),
|
|
118
|
+
source: this.$configuration.source(),
|
|
119
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
120
|
+
prepareItems: (items) => items.map((item) => item.laravel.forms.create),
|
|
121
|
+
fileName: (item) => item.context + '/create-form.blade.php',
|
|
122
|
+
});
|
|
123
|
+
templates[this.templateKey('filter-form')] = new generathor_1.GeneratorForItem({
|
|
124
|
+
template: this.templateFile('views/form'),
|
|
125
|
+
source: this.$configuration.source(),
|
|
126
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
127
|
+
prepareItems: (items) => items.map((item) => item.laravel.forms.filter),
|
|
128
|
+
fileName: (item) => item.context + '/filter-form.blade.php',
|
|
129
|
+
});
|
|
130
|
+
templates[this.templateKey('update-form')] = new generathor_1.GeneratorForItem({
|
|
131
|
+
template: this.templateFile('views/form'),
|
|
132
|
+
source: this.$configuration.source(),
|
|
133
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
134
|
+
prepareItems: (items) => items.map((item) => item.laravel.forms.update),
|
|
135
|
+
fileName: (item) => item.context + '/update-form.blade.php',
|
|
136
|
+
});
|
|
137
|
+
templates[this.templateKey('attach-form')] = new generathor_1.GeneratorForItem({
|
|
138
|
+
template: this.templateFile('views/form'),
|
|
139
|
+
source: this.$configuration.source(),
|
|
140
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
141
|
+
prepareItems: (items) => new attachForm_1.AttachForm(items, this.$configuration).transform(),
|
|
142
|
+
fileName: (item) => `${item.context}/attach-${item.contextFile}-form.blade.php`,
|
|
143
|
+
});
|
|
144
|
+
templates[this.templateKey('create-relation-form')] = new generathor_1.GeneratorForItem({
|
|
145
|
+
template: this.templateFile('views/form'),
|
|
146
|
+
source: this.$configuration.source(),
|
|
147
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
148
|
+
prepareItems: (items) => new createRelationForm_1.CreateRelationForm(items, this.$configuration).transform(),
|
|
149
|
+
fileName: (item) => `${item.context}/create-${item.contextFile}-form.blade.php`,
|
|
150
|
+
});
|
|
151
|
+
templates[this.templateKey('filter-relation-form')] = new generathor_1.GeneratorForItem({
|
|
152
|
+
template: this.templateFile('views/form'),
|
|
153
|
+
source: this.$configuration.source(),
|
|
154
|
+
directory: this.directory('/resources/views/components/generathor'),
|
|
155
|
+
prepareItems: (items) => new filterRelationForm_1.FilterRelationForm(items, this.$configuration).transform(),
|
|
156
|
+
fileName: (item) => `${item.context}/filter-${item.contextFile}-form.blade.php`,
|
|
157
|
+
});
|
|
158
|
+
templates[this.templateKey('controller')] = new generathor_1.GeneratorForItem({
|
|
159
|
+
template: this.templateFile('others/controller'),
|
|
160
|
+
source: this.$configuration.source(),
|
|
161
|
+
directory: this.directory('/app/Http/Controllers/Generathor'),
|
|
162
|
+
prepareItems: (items) => new controller_1.Controller(items, this.$configuration).transform(),
|
|
163
|
+
fileName: (item) => item.class + '.php',
|
|
164
|
+
});
|
|
165
|
+
templates[this.templateKey('index-view')] = new generathor_1.GeneratorForItem({
|
|
166
|
+
template: this.templateFile('views/index'),
|
|
167
|
+
source: this.$configuration.source(),
|
|
168
|
+
directory: this.directory('/resources/views/generathor'),
|
|
169
|
+
prepareItems: (items) => items.map((item) => item.laravel.list),
|
|
170
|
+
fileName: (item) => item.context + '/index.blade.php',
|
|
171
|
+
});
|
|
172
|
+
templates[this.templateKey('edit-view')] = new generathor_1.GeneratorForItem({
|
|
173
|
+
template: this.templateFile('views/edit'),
|
|
174
|
+
source: this.$configuration.source(),
|
|
175
|
+
directory: this.directory('/resources/views/generathor'),
|
|
176
|
+
prepareItems: (items) => items.map((item) => item.laravel.edit),
|
|
177
|
+
fileName: (item) => item.context + '/edit.blade.php',
|
|
178
|
+
});
|
|
179
|
+
templates[this.templateKey('show-view')] = new generathor_1.GeneratorForItem({
|
|
180
|
+
template: this.templateFile('views/show'),
|
|
181
|
+
source: this.$configuration.source(),
|
|
182
|
+
directory: this.directory('/resources/views/generathor'),
|
|
183
|
+
prepareItems: (items) => items.map((item) => item.laravel.show),
|
|
184
|
+
fileName: (item) => item.context + '/show.blade.php',
|
|
185
|
+
});
|
|
186
|
+
templates[this.templateKey('relation-item-view')] = new generathor_1.GeneratorForItem({
|
|
187
|
+
template: this.templateFile('views/relation-item'),
|
|
188
|
+
source: this.$configuration.source(),
|
|
189
|
+
directory: this.directory('/resources/views/generathor'),
|
|
190
|
+
prepareItems: (items) => new belongsToRelation_1.BelongsToRelation(items, this.$configuration).transform(),
|
|
191
|
+
fileName: (item) => `${item.context}/${item.relationContext}.blade.php`,
|
|
192
|
+
});
|
|
193
|
+
templates[this.templateKey('relation-list-view')] = new generathor_1.GeneratorForItem({
|
|
194
|
+
template: this.templateFile('views/relation-list'),
|
|
195
|
+
source: this.$configuration.source(),
|
|
196
|
+
directory: this.directory('/resources/views/generathor'),
|
|
197
|
+
prepareItems: (items) => new hasManyRelation_1.HasManyRelation(items, this.$configuration).transform(),
|
|
198
|
+
fileName: (item) => `${item.context}/${item.relationContext}.blade.php`,
|
|
199
|
+
});
|
|
200
|
+
return templates;
|
|
201
|
+
}
|
|
202
|
+
generatorsForCollections() {
|
|
203
|
+
if (this.$configuration.createEloquentModelsOnly()) {
|
|
204
|
+
return {};
|
|
205
|
+
}
|
|
206
|
+
const templates = {};
|
|
207
|
+
templates[this.templateKey('routes')] = new generathor_1.GeneratorForCollection({
|
|
208
|
+
template: this.templateFile('others/routes'),
|
|
209
|
+
source: this.$configuration.source(),
|
|
210
|
+
file: this.directory('/routes/generathor.php'),
|
|
211
|
+
prepareItems: (items) => new route_1.Route(items, this.$configuration).transform(),
|
|
212
|
+
});
|
|
213
|
+
return templates;
|
|
214
|
+
}
|
|
215
|
+
generatorsForStaticFiles() {
|
|
216
|
+
const templates = {};
|
|
217
|
+
templates[this.templateKey('pk-trait')] = new generathor_1.GeneratorForCollection({
|
|
218
|
+
template: this.templateFile('others/pk-trait'),
|
|
219
|
+
source: this.$configuration.source(),
|
|
220
|
+
prepareItems: () => [],
|
|
221
|
+
file: this.directory('/app/Models/Generathor/GenerathorKey.php'),
|
|
222
|
+
});
|
|
223
|
+
if (this.$configuration.createEloquentModelsOnly()) {
|
|
224
|
+
return templates;
|
|
225
|
+
}
|
|
226
|
+
templates[this.templateKey('record-input')] = new generathor_1.GeneratorForCollection({
|
|
227
|
+
template: this.templateFile('views/record-input'),
|
|
228
|
+
source: this.$configuration.source(),
|
|
229
|
+
prepareItems: () => [],
|
|
230
|
+
file: this.directory('/resources/views/components/generathor/record-input.blade.php'),
|
|
231
|
+
});
|
|
232
|
+
templates[this.templateKey('breadcrumbs')] = new generathor_1.GeneratorForCollection({
|
|
233
|
+
template: this.templateFile('views/breadcrumbs'),
|
|
234
|
+
source: this.$configuration.source(),
|
|
235
|
+
prepareItems: () => [],
|
|
236
|
+
file: this.directory('/resources/views/components/generathor/breadcrumbs.blade.php'),
|
|
237
|
+
});
|
|
238
|
+
templates[this.templateKey('tabs')] = new generathor_1.GeneratorForCollection({
|
|
239
|
+
template: this.templateFile('views/tabs'),
|
|
240
|
+
source: this.$configuration.source(),
|
|
241
|
+
prepareItems: () => [],
|
|
242
|
+
file: this.directory('/resources/views/components/generathor/tabs.blade.php'),
|
|
243
|
+
});
|
|
244
|
+
templates[this.templateKey('modal')] = new generathor_1.GeneratorForCollection({
|
|
245
|
+
template: this.templateFile('views/modal'),
|
|
246
|
+
source: this.$configuration.source(),
|
|
247
|
+
prepareItems: () => [],
|
|
248
|
+
file: this.directory('/resources/views/components/generathor/modal.blade.php'),
|
|
249
|
+
});
|
|
250
|
+
templates[this.templateKey('loader')] = new generathor_1.GeneratorForCollection({
|
|
251
|
+
template: this.templateFile('views/loader'),
|
|
252
|
+
source: this.$configuration.source(),
|
|
253
|
+
prepareItems: () => [],
|
|
254
|
+
file: this.directory('/resources/views/components/generathor/loader.blade.php'),
|
|
255
|
+
});
|
|
256
|
+
const icons = [
|
|
257
|
+
'check-circle',
|
|
258
|
+
'chevron-right',
|
|
259
|
+
'computer',
|
|
260
|
+
'eye',
|
|
261
|
+
'funnel',
|
|
262
|
+
'home',
|
|
263
|
+
'pencil',
|
|
264
|
+
'plus',
|
|
265
|
+
'trash',
|
|
266
|
+
'x-circle',
|
|
267
|
+
'x',
|
|
268
|
+
'chevron-down',
|
|
269
|
+
'list-bullet',
|
|
270
|
+
'link',
|
|
271
|
+
'unlink',
|
|
272
|
+
];
|
|
273
|
+
for (const icon of icons) {
|
|
274
|
+
templates[this.templateKey(`icon-${icon}`)] = new generathor_1.GeneratorForCollection({
|
|
275
|
+
template: this.templateFile('views/icons/' + icon),
|
|
276
|
+
source: this.$configuration.source(),
|
|
277
|
+
prepareItems: () => [],
|
|
278
|
+
file: this.directory(`/resources/views/components/generathor/icon-${icon}.blade.php`),
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return templates;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.LaravelGenerator = LaravelGenerator;
|
|
@@ -0,0 +1,55 @@
|
|
|
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.AttachForm = void 0;
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
const naming_1 = __importDefault(require("../../helpers/naming"));
|
|
9
|
+
class AttachForm extends base_1.BaseTransformer {
|
|
10
|
+
transform() {
|
|
11
|
+
const map = this.mapByTable();
|
|
12
|
+
const result = [];
|
|
13
|
+
for (const item of this.$items) {
|
|
14
|
+
const context = naming_1.default.context(item.table);
|
|
15
|
+
for (const relation of item.relations) {
|
|
16
|
+
if (relation.type !== 'belongs-to') {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const itemRelated = map[relation.on.table];
|
|
20
|
+
const inputs = [];
|
|
21
|
+
relation.columns.forEach((column) => {
|
|
22
|
+
inputs.push({
|
|
23
|
+
type: 'record',
|
|
24
|
+
name: column,
|
|
25
|
+
label: naming_1.default.label(column),
|
|
26
|
+
data: {
|
|
27
|
+
context: naming_1.default.context(itemRelated.table),
|
|
28
|
+
relationName: naming_1.default.relationAttribute(relation, itemRelated.table),
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
const relationLabel = naming_1.default.capitalizedRelationAttribute(relation, itemRelated.table);
|
|
33
|
+
result.push({
|
|
34
|
+
context,
|
|
35
|
+
contextFile: naming_1.default.relationContext(relation, item.table),
|
|
36
|
+
record: null,
|
|
37
|
+
routeRecord: naming_1.default.recordName(item.table),
|
|
38
|
+
method: 'post',
|
|
39
|
+
prefix: '',
|
|
40
|
+
getOld: 'old',
|
|
41
|
+
errorBag: 'attach',
|
|
42
|
+
buttonLabel: 'Save',
|
|
43
|
+
buttonColor: 'green',
|
|
44
|
+
columns: '2',
|
|
45
|
+
route: `generathor.${context}.attach${relationLabel}`,
|
|
46
|
+
cancelLink: null,
|
|
47
|
+
inputs: inputs,
|
|
48
|
+
hiddenInputs: [],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.AttachForm = AttachForm;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.AttachRequest = void 0;
|
|
30
|
+
const base_1 = require("./base");
|
|
31
|
+
const th = __importStar(require("../../helpers/type"));
|
|
32
|
+
const naming_1 = __importDefault(require("../../helpers/naming"));
|
|
33
|
+
const ignoreCreateRulesFor = {
|
|
34
|
+
created_at: true,
|
|
35
|
+
updated_at: true,
|
|
36
|
+
};
|
|
37
|
+
class AttachRequest extends base_1.BaseTransformer {
|
|
38
|
+
transform() {
|
|
39
|
+
const result = [];
|
|
40
|
+
for (const item of this.$items) {
|
|
41
|
+
const model = naming_1.default.modelClass(item.table);
|
|
42
|
+
const columnRules = this.columnRules(item);
|
|
43
|
+
for (const relation of item.relations) {
|
|
44
|
+
if (relation.type !== 'belongs-to') {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const relatedModel = naming_1.default.capitalizedRelationAttribute(relation, item.table);
|
|
48
|
+
const rules = [];
|
|
49
|
+
relation.columns.forEach((columnName) => {
|
|
50
|
+
rules.push({
|
|
51
|
+
attribute: columnName,
|
|
52
|
+
rules: columnRules[columnName],
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
result.push({
|
|
56
|
+
namespace: 'App\\Http\\Requests\\Generathor',
|
|
57
|
+
class: `Attach${relatedModel}To${model}Request`,
|
|
58
|
+
rules: rules,
|
|
59
|
+
errorBag: 'attach',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
columnRules(item) {
|
|
66
|
+
const columnRules = {};
|
|
67
|
+
item.columns.forEach((column) => {
|
|
68
|
+
const rules = ['required'];
|
|
69
|
+
if (column.type === 'string' &&
|
|
70
|
+
column.enum &&
|
|
71
|
+
Array.isArray(column.enum)) {
|
|
72
|
+
const rule = 'in:' + column.enum.join(',');
|
|
73
|
+
rules.push(rule);
|
|
74
|
+
}
|
|
75
|
+
const ruleType = th.ruleType(column);
|
|
76
|
+
if (column.type !== 'date') {
|
|
77
|
+
rules.push(ruleType);
|
|
78
|
+
}
|
|
79
|
+
const dateRuleType = th.dateRuleType(column);
|
|
80
|
+
if (column.type === 'date' && dateRuleType) {
|
|
81
|
+
rules.push(dateRuleType);
|
|
82
|
+
}
|
|
83
|
+
if (!column.autoincrement) {
|
|
84
|
+
if (!ignoreCreateRulesFor[column.name]) {
|
|
85
|
+
columnRules[column.name] = rules.join('|');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return columnRules;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.AttachRequest = AttachRequest;
|