Skip to content

Commit ca8f646

Browse files
copy files wip
1 parent e57f0c5 commit ca8f646

File tree

8 files changed

+8935
-6230
lines changed

8 files changed

+8935
-6230
lines changed

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@
7272
"lint-staged": {
7373
"src/**/*.js": "yarn lint --fix"
7474
},
75-
"bin": {
76-
"create-client": "./lib/index.js"
77-
},
75+
"bin": "./lib/index.js",
7876
"publishConfig": {
7977
"access": "public"
8078
}

src/generators/AngularGenerator.js

+58-23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import BaseGenerator from "./BaseGenerator.js";
22
import handlebars from "handlebars";
33
import hbhComparison from "handlebars-helpers/lib/comparison.js";
44
import hbhString from "handlebars-helpers/lib/string.js";
5+
import chalk from "chalk";
56

67
export default class extends BaseGenerator {
78
constructor(params) {
@@ -58,6 +59,28 @@ export default class extends BaseGenerator {
5859
handlebars.registerHelper("lowercase", hbhString.lowercase);
5960
}
6061

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+
6184
generate(api, resource, dir) {
6285
const lc = resource.title.toLowerCase();
6386
const titleUcFirst =
@@ -67,6 +90,8 @@ export default class extends BaseGenerator {
6790
const hasIsRelations = fields.some((field) => field.isRelations);
6891
const hasDateField = fields.some((field) => field.type === "dateTime");
6992

93+
console.log(resource)
94+
7095
const context = {
7196
title: resource.title,
7297
name: resource.name,
@@ -86,43 +111,53 @@ export default class extends BaseGenerator {
86111
[
87112
`${dir}/assets`,
88113
`${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`,
92125
`${dir}/app/interface`,
93126
`${dir}/app/router`,
94127
`${dir}/app/service`,
95128
].forEach((dir) => this.createDir(dir, false));
96129

97130
//CREATE FILE
98131
[
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+
);
116151

117152
[
118-
`app/components/%s/create/create.component.html",
153+
"app/components/%s/create/create.component.html",
119154
"app/components/%s/create/create.component.ts",
120-
"app/components/%s/edit/edit.component.html",
155+
/*"app/components/%s/edit/edit.component.html",
121156
"app/components/%s/edit/edit.component.ts",
122157
"app/components/%s/list/list.component.html",
123158
"app/components/%s/list/list.component.ts",
124159
"app/components/%s/show/show.component.html",
125-
"app/components/%s/show/show.component.ts",`,
160+
"app/components/%s/show/show.component.ts",*/
126161
].forEach((file) => this.createFileFromPattern(file, dir, [lc], context));
127162
}
128163

src/generators/BaseGenerator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default class {
4444
context,
4545
templateValues = ["foo", "Foo"]
4646
) {
47-
console.log(dir);
4847
this.createFile(
4948
vsprintf(pattern, templateValues),
5049
vsprintf(`${dir}/${pattern}`, values),
@@ -53,6 +52,9 @@ export default class {
5352
}
5453

5554
createFile(template, dest, context = {}, warn = true) {
55+
console.table(this.templates);
56+
console.log("template ==>", template);
57+
console.log("dest ==>", dest);
5658
if (undefined === this.templates[template]) {
5759
console.log(
5860
`The template ${template} does not exists in the registered templates.`

templates/angular/app/app.routes.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import {Routes} from '@angular/router';
2-
import {ListComponent} from "./components/foo/list/list.component";
3-
import {ShowComponent} from "./components/foo/show/show.component";
4-
import {EditComponent} from "./components/foo/edit/edit.component";
5-
import {CreateComponent} from "./components/foo/create/create.component";
2+
import {ListComponent} from "./components/{{lc}}/list/list.component";
3+
import {ShowComponent} from "./components/{{lc}}/show/show.component";
4+
import {EditComponent} from "./components/{{lc}}/edit/edit.component";
5+
import {CreateComponent} from "./components/{{lc}}/create/create.component";
66

77
export const routes: Routes = [
88
{
9-
path: 'heroes',
9+
path: '{{lc}}',
1010
component: ListComponent
1111
},
1212
{
13-
path: 'heroes/add',
13+
path: '{{lc}}/add',
1414
component: CreateComponent
1515
},
1616
{
17-
path: 'heroes/:id',
17+
path: '{{lc}}/:id',
1818
component: ShowComponent,
1919
},
2020
{
21-
path: 'heroes/:id/edit',
21+
path: '{{lc}}/:id/edit',
2222
component: EditComponent
2323
},
2424
];

templates/angular/app/components/foo/create/create.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="flex items-center justify-between">
33
<a [routerLink]="['/heroes']"
44
class="text-blue-600 hover:text-blue-800">
5-
Back to list
5+
Back to list {{lc}}
66
</a>
77
</div>
88
@if (isLoading()) {

templates/angular/app/components/foo/edit/edit.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<div class="px-4 mt-4">
22
<div class="flex items-center justify-end">
3-
<a [routerLink]="['/heroes']"
3+
<a [routerLink]="['/{{lc}}']"
44
class="text-blue-600 hover:text-blue-800">
55
Back to list
66
</a>
77
</div>
88
@if (isLoading()) {
99
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
1010
} @else {
11-
<h1 class="text-3xl my-4">Edit {{ item()?.name }} {{ item()?.["@id"] }}</h1>
11+
<h1 class="text-3xl my-4">Edit {{titleUcFirst}} {{ item()?.["@id"] }}</h1>
1212

1313
<form (ngSubmit)="onSubmit($event)">
1414
<div class="bg-white px-6 py-8">
15-
<label for="name"> name</label>
15+
<label for="name">name</label>
1616
<input id="name"
1717
class="mt-1 w-full px-3 py-2 border rounded"
1818
[ngModel]="item()?.name"

templates/angular/app/service/hero.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";
22
import {catchError, Observable, throwError} from "rxjs";
33
import {Injectable, Signal} from "@angular/core";
44
import {ApiList, ApiShow} from "../interface/api";
5-
import {Hero} from "../interface/hero.model";
65
import {Foo} from "../interface/foo.model";
76

87
@Injectable({providedIn: 'root'})

0 commit comments

Comments
 (0)