@@ -2,6 +2,7 @@ import BaseGenerator from "./BaseGenerator.js";
2
2
import handlebars from "handlebars" ;
3
3
import hbhComparison from "handlebars-helpers/lib/comparison.js" ;
4
4
import hbhString from "handlebars-helpers/lib/string.js" ;
5
+ import chalk from "chalk" ;
5
6
6
7
export default class extends BaseGenerator {
7
8
constructor ( params ) {
@@ -58,6 +59,28 @@ export default class extends BaseGenerator {
58
59
handlebars . registerHelper ( "lowercase" , hbhString . lowercase ) ;
59
60
}
60
61
62
+ help ( resource ) {
63
+ const titleLc = resource . title . toLowerCase ( ) ;
64
+
65
+ console . log (
66
+ 'Code for the "%s" resource type has been generated!' ,
67
+ resource . title
68
+ ) ;
69
+ console . log (
70
+ "Paste the following definitions in your application configuration (`client/src/index.js` by default):"
71
+ ) ;
72
+ console . log (
73
+ chalk . green ( `
74
+ // import reducers
75
+ import ${ titleLc } from './reducers/${ titleLc } /';
76
+
77
+ // Add the reducer
78
+ combineReducers({ ${ titleLc } , /* ... */ }),
79
+ ` )
80
+ ) ;
81
+ }
82
+
83
+
61
84
generate ( api , resource , dir ) {
62
85
const lc = resource . title . toLowerCase ( ) ;
63
86
const titleUcFirst =
@@ -67,6 +90,8 @@ export default class extends BaseGenerator {
67
90
const hasIsRelations = fields . some ( ( field ) => field . isRelations ) ;
68
91
const hasDateField = fields . some ( ( field ) => field . type === "dateTime" ) ;
69
92
93
+ console . log ( resource )
94
+
70
95
const context = {
71
96
title : resource . title ,
72
97
name : resource . name ,
@@ -86,43 +111,53 @@ export default class extends BaseGenerator {
86
111
[
87
112
`${ dir } /assets` ,
88
113
`${ dir } /utils` ,
89
- `${ dir } /app/components/${ lc } ` ,
90
- `${ dir } /app/components/common` ,
91
- `${ dir } /app/components/svg` ,
114
+ `${ dir } /app/components/${ lc } /create` ,
115
+ `${ dir } /app/components/${ lc } /edit` ,
116
+ `${ dir } /app/components/${ lc } /list` ,
117
+ `${ dir } /app/components/${ lc } /show` ,
118
+ `${ dir } /app/components/common/delete` ,
119
+ `${ dir } /app/components/common/form` ,
120
+ `${ dir } /app/components/common/header` ,
121
+ `${ dir } /app/components/common/sidebar` ,
122
+ `${ dir } /app/components/common/table` ,
123
+ `${ dir } /app/components/svg/list-svg` ,
124
+ `${ dir } /app/components/svg/menu` ,
92
125
`${ dir } /app/interface` ,
93
126
`${ dir } /app/router` ,
94
127
`${ dir } /app/service` ,
95
128
] . forEach ( ( dir ) => this . createDir ( dir , false ) ) ;
96
129
97
130
//CREATE FILE
98
131
[
99
- `${ dir } /app/components/svg/list-svg/list-svg.component.svg` ,
100
- `${ dir } /app/components/svg/list-svg/list-svg.component.ts` ,
101
- `${ dir } /app/components/svg/menu/menu.component.svg` ,
102
- `${ dir } /app/components/svg/menu/menu.component.ts` ,
103
- `${ dir } /app/components/common/delete/delete.component.html` ,
104
- `${ dir } /app/components/common/delete/delete.component.ts` ,
105
- `${ dir } /app/components/common/form/form.component.html` ,
106
- `${ dir } /app/components/common/form/form.component.ts` ,
107
- `${ dir } /app/components/common/header/header.component.html` ,
108
- `${ dir } /app/components/common/header/header.component.ts` ,
109
- `${ dir } /app/components/common/sidebar/sidebar.component.html` ,
110
- `${ dir } /app/components/common/sidebar/sidebar.component.ts` ,
111
- `${ dir } /app/components/common/table/table.component.html` ,
112
- `${ dir } /app/app.component.html` ,
113
- `${ dir } /app/app.component.ts` ,
114
- `${ dir } /app/app.routes.ts` ,
115
- ] . forEach ( ( file ) => this . createFile ( file , file , context , false ) ) ;
132
+ "app/components/svg/list-svg/list-svg.component.svg" ,
133
+ "app/components/svg/list-svg/list-svg.component.ts" ,
134
+ "app/components/svg/menu/menu.component.svg" ,
135
+ "app/components/svg/menu/menu.component.ts" ,
136
+ "app/components/common/delete/delete.component.html" ,
137
+ "app/components/common/delete/delete.component.ts" ,
138
+ "app/components/common/form/form.component.html" ,
139
+ "app/components/common/form/form.component.ts" ,
140
+ "app/components/common/header/header.component.html" ,
141
+ "app/components/common/header/header.component.ts" ,
142
+ "app/components/common/sidebar/sidebar.component.html" ,
143
+ "app/components/common/sidebar/sidebar.component.ts" ,
144
+
145
+ "app/app.component.html" ,
146
+ "app/app.component.ts" ,
147
+ "app/app.routes.ts" ,
148
+ ] . forEach ( ( file ) =>
149
+ this . createFile ( file , `${ dir } /${ file } ` , context , false )
150
+ ) ;
116
151
117
152
[
118
- ` app/components/%s/create/create.component.html",
153
+ " app/components/%s/create/create.component.html",
119
154
"app/components/%s/create/create.component.ts" ,
120
- "app/components/%s/edit/edit.component.html",
155
+ /* "app/components/%s/edit/edit.component.html",
121
156
"app/components/%s/edit/edit.component.ts",
122
157
"app/components/%s/list/list.component.html",
123
158
"app/components/%s/list/list.component.ts",
124
159
"app/components/%s/show/show.component.html",
125
- "app/components/%s/show/show.component.ts",` ,
160
+ "app/components/%s/show/show.component.ts",*/
126
161
] . forEach ( ( file ) => this . createFileFromPattern ( file , dir , [ lc ] , context ) ) ;
127
162
}
128
163
0 commit comments