Skip to content

Commit

Permalink
copy files wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-urbanski committed Jun 5, 2024
1 parent e57f0c5 commit ca8f646
Show file tree
Hide file tree
Showing 8 changed files with 8,935 additions and 6,230 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@
"lint-staged": {
"src/**/*.js": "yarn lint --fix"
},
"bin": {
"create-client": "./lib/index.js"
},
"bin": "./lib/index.js",
"publishConfig": {
"access": "public"
}
Expand Down
81 changes: 58 additions & 23 deletions src/generators/AngularGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BaseGenerator from "./BaseGenerator.js";
import handlebars from "handlebars";
import hbhComparison from "handlebars-helpers/lib/comparison.js";
import hbhString from "handlebars-helpers/lib/string.js";
import chalk from "chalk";

export default class extends BaseGenerator {
constructor(params) {
Expand Down Expand Up @@ -58,6 +59,28 @@ export default class extends BaseGenerator {
handlebars.registerHelper("lowercase", hbhString.lowercase);
}

help(resource) {
const titleLc = resource.title.toLowerCase();

console.log(
'Code for the "%s" resource type has been generated!',
resource.title
);
console.log(
"Paste the following definitions in your application configuration (`client/src/index.js` by default):"
);
console.log(
chalk.green(`
// import reducers
import ${titleLc} from './reducers/${titleLc}/';
// Add the reducer
combineReducers({ ${titleLc}, /* ... */ }),
`)
);
}


generate(api, resource, dir) {
const lc = resource.title.toLowerCase();
const titleUcFirst =
Expand All @@ -67,6 +90,8 @@ export default class extends BaseGenerator {
const hasIsRelations = fields.some((field) => field.isRelations);
const hasDateField = fields.some((field) => field.type === "dateTime");

console.log(resource)

const context = {
title: resource.title,
name: resource.name,
Expand All @@ -86,43 +111,53 @@ export default class extends BaseGenerator {
[
`${dir}/assets`,
`${dir}/utils`,
`${dir}/app/components/${lc}`,
`${dir}/app/components/common`,
`${dir}/app/components/svg`,
`${dir}/app/components/${lc}/create`,
`${dir}/app/components/${lc}/edit`,
`${dir}/app/components/${lc}/list`,
`${dir}/app/components/${lc}/show`,
`${dir}/app/components/common/delete`,
`${dir}/app/components/common/form`,
`${dir}/app/components/common/header`,
`${dir}/app/components/common/sidebar`,
`${dir}/app/components/common/table`,
`${dir}/app/components/svg/list-svg`,
`${dir}/app/components/svg/menu`,
`${dir}/app/interface`,
`${dir}/app/router`,
`${dir}/app/service`,
].forEach((dir) => this.createDir(dir, false));

//CREATE FILE
[
`${dir}/app/components/svg/list-svg/list-svg.component.svg`,
`${dir}/app/components/svg/list-svg/list-svg.component.ts`,
`${dir}/app/components/svg/menu/menu.component.svg`,
`${dir}/app/components/svg/menu/menu.component.ts`,
`${dir}/app/components/common/delete/delete.component.html`,
`${dir}/app/components/common/delete/delete.component.ts`,
`${dir}/app/components/common/form/form.component.html`,
`${dir}/app/components/common/form/form.component.ts`,
`${dir}/app/components/common/header/header.component.html`,
`${dir}/app/components/common/header/header.component.ts`,
`${dir}/app/components/common/sidebar/sidebar.component.html`,
`${dir}/app/components/common/sidebar/sidebar.component.ts`,
`${dir}/app/components/common/table/table.component.html`,
`${dir}/app/app.component.html`,
`${dir}/app/app.component.ts`,
`${dir}/app/app.routes.ts`,
].forEach((file) => this.createFile(file, file, context, false));
"app/components/svg/list-svg/list-svg.component.svg",
"app/components/svg/list-svg/list-svg.component.ts",
"app/components/svg/menu/menu.component.svg",
"app/components/svg/menu/menu.component.ts",
"app/components/common/delete/delete.component.html",
"app/components/common/delete/delete.component.ts",
"app/components/common/form/form.component.html",
"app/components/common/form/form.component.ts",
"app/components/common/header/header.component.html",
"app/components/common/header/header.component.ts",
"app/components/common/sidebar/sidebar.component.html",
"app/components/common/sidebar/sidebar.component.ts",

"app/app.component.html",
"app/app.component.ts",
"app/app.routes.ts",
].forEach((file) =>
this.createFile(file, `${dir}/${file}`, context, false)
);

[
`app/components/%s/create/create.component.html",
"app/components/%s/create/create.component.html",
"app/components/%s/create/create.component.ts",
"app/components/%s/edit/edit.component.html",
/*"app/components/%s/edit/edit.component.html",
"app/components/%s/edit/edit.component.ts",
"app/components/%s/list/list.component.html",
"app/components/%s/list/list.component.ts",
"app/components/%s/show/show.component.html",
"app/components/%s/show/show.component.ts",`,
"app/components/%s/show/show.component.ts",*/
].forEach((file) => this.createFileFromPattern(file, dir, [lc], context));
}

Expand Down
4 changes: 3 additions & 1 deletion src/generators/BaseGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default class {
context,
templateValues = ["foo", "Foo"]
) {
console.log(dir);
this.createFile(
vsprintf(pattern, templateValues),
vsprintf(`${dir}/${pattern}`, values),
Expand All @@ -53,6 +52,9 @@ export default class {
}

createFile(template, dest, context = {}, warn = true) {
console.table(this.templates);
console.log("template ==>", template);
console.log("dest ==>", dest);
if (undefined === this.templates[template]) {
console.log(
`The template ${template} does not exists in the registered templates.`
Expand Down
16 changes: 8 additions & 8 deletions templates/angular/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {Routes} from '@angular/router';
import {ListComponent} from "./components/foo/list/list.component";
import {ShowComponent} from "./components/foo/show/show.component";
import {EditComponent} from "./components/foo/edit/edit.component";
import {CreateComponent} from "./components/foo/create/create.component";
import {ListComponent} from "./components/{{lc}}/list/list.component";
import {ShowComponent} from "./components/{{lc}}/show/show.component";
import {EditComponent} from "./components/{{lc}}/edit/edit.component";
import {CreateComponent} from "./components/{{lc}}/create/create.component";

export const routes: Routes = [
{
path: 'heroes',
path: '{{lc}}',
component: ListComponent
},
{
path: 'heroes/add',
path: '{{lc}}/add',
component: CreateComponent
},
{
path: 'heroes/:id',
path: '{{lc}}/:id',
component: ShowComponent,
},
{
path: 'heroes/:id/edit',
path: '{{lc}}/:id/edit',
component: EditComponent
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flex items-center justify-between">
<a [routerLink]="['/heroes']"
class="text-blue-600 hover:text-blue-800">
Back to list
Back to list {{lc}}
</a>
</div>
@if (isLoading()) {
Expand Down
6 changes: 3 additions & 3 deletions templates/angular/app/components/foo/edit/edit.component.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<div class="px-4 mt-4">
<div class="flex items-center justify-end">
<a [routerLink]="['/heroes']"
<a [routerLink]="['/{{lc}}']"
class="text-blue-600 hover:text-blue-800">
Back to list
</a>
</div>
@if (isLoading()) {
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
} @else {
<h1 class="text-3xl my-4">Edit {{ item()?.name }} {{ item()?.["@id"] }}</h1>
<h1 class="text-3xl my-4">Edit {{titleUcFirst}} {{ item()?.["@id"] }}</h1>

<form (ngSubmit)="onSubmit($event)">
<div class="bg-white px-6 py-8">
<label for="name"> name</label>
<label for="name">name</label>
<input id="name"
class="mt-1 w-full px-3 py-2 border rounded"
[ngModel]="item()?.name"
Expand Down
1 change: 0 additions & 1 deletion templates/angular/app/service/hero.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {HttpClient, HttpErrorResponse, HttpHeaders} from "@angular/common/http";
import {catchError, Observable, throwError} from "rxjs";
import {Injectable, Signal} from "@angular/core";
import {ApiList, ApiShow} from "../interface/api";
import {Hero} from "../interface/hero.model";
import {Foo} from "../interface/foo.model";

@Injectable({providedIn: 'root'})
Expand Down
Loading

0 comments on commit ca8f646

Please sign in to comment.