Skip to content

Commit 041ed7f

Browse files
authored
fix: update generators (#72)
1 parent 0e67ac6 commit 041ed7f

File tree

8 files changed

+54
-30
lines changed

8 files changed

+54
-30
lines changed

apps/api-harmonization/src/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
Users,
2121
} from '@o2s/framework/modules';
2222

23-
// BLOCK IMPORT
2423
import { configuration } from '@o2s/api-harmonization/config/configuration';
2524

2625
import { ArticleDetailsBlockModule } from '@o2s/api-harmonization/blocks/article-details/article-details.module';
@@ -38,6 +37,7 @@ import { TicketListBlockModule } from '@o2s/api-harmonization/blocks/ticket-list
3837
import { TicketRecentBlockModule } from '@o2s/api-harmonization/blocks/ticket-recent/ticket-recent.module';
3938
import { UserAccountBlockModule } from '@o2s/api-harmonization/blocks/user-account/user-account.module';
4039

40+
// BLOCK IMPORT
4141
import { AppConfig } from './app.config';
4242
import { AppService } from './app.service';
4343
import { ContextHeadersMiddleware } from './middleware/context-headers.middleware';
@@ -89,7 +89,7 @@ import { RoutesModule } from './modules/routes/routes.module';
8989
TicketRecentBlockModule.register(AppConfig),
9090
ServiceListBlockModule.register(AppConfig),
9191
ServiceDetailsBlockModule.register(AppConfig),
92-
// COMPONENT REGISTER
92+
// BLOCK REGISTER
9393
],
9494
providers: [
9595
AppService,

apps/api-harmonization/turbo/generators/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
5050
type: 'modify',
5151
path: 'src/app.module.ts',
5252
pattern: /(\/\/ BLOCK IMPORT)/g,
53-
template: `import { {{ pascalCase name }}BlockModule } from '@o2s/api/blocks/{{kebabCase name}}/{{kebabCase name}}.module';\n// BLOCK IMPORT`,
53+
template: `import { {{ pascalCase name }}BlockModule } from '@o2s/api-harmonization/blocks/{{kebabCase name}}/{{kebabCase name}}.module';\n// BLOCK IMPORT`,
5454
},
5555
{
5656
type: 'modify',

apps/api-harmonization/turbo/generators/templates/block/controller.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Controller, Get, Query, UseInterceptors } from '@nestjs/common';
1+
import { Controller, Get, Headers, Query, UseInterceptors } from '@nestjs/common';
2+
import { LoggerService } from '@o2s/utils.logger';
23

34
import { Auth } from '@o2s/framework/modules';
4-
import { LoggerService } from '@o2s/utils.logger';
5+
6+
import { AppHeaders } from '@o2s/api-harmonization/utils/headers';
57

68
import { URL } from './';
79
import { Get{{ pascalCase name }}BlockQuery } from './{{ kebabCase name }}.request';
@@ -14,7 +16,7 @@ export class {{ pascalCase name }}Controller {
1416

1517
@Get()
1618
@Auth.Decorators.Roles({ roles: [Auth.Constants.Roles.USER, Auth.Constants.Roles.ADMIN] })
17-
get{{ pascalCase name }}Block(@Query() query: Get{{ pascalCase name }}BlockQuery) {
18-
return this.service.get{{ pascalCase name }}Block(query);
19+
get{{ pascalCase name }}Block(@Headers() headers: AppHeaders, @Query() query: Get{{ pascalCase name }}BlockQuery) {
20+
return this.service.get{{ pascalCase name }}Block(query, headers);
1921
}
2022
}

apps/api-harmonization/turbo/generators/templates/block/model.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CMS } from '../../models';
2-
32
import { Block } from '../../utils';
43

54
export class {{ pascalCase name }}Block extends Block.Block {

apps/api-harmonization/turbo/generators/templates/block/service.hbs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Injectable } from '@nestjs/common';
22
import { Observable, forkJoin, map } from 'rxjs';
33

4+
import { AppHeaders } from '@o2s/api-harmonization/utils/headers';
5+
46
import { CMS } from '../../models';
57

68
import { map{{ pascalCase name }} } from './{{ kebabCase name }}.mapper';
@@ -13,9 +15,12 @@ export class {{ pascalCase name }}Service {
1315
private readonly cmsService: CMS.Service,
1416
) {}
1517

16-
get{{ pascalCase name }}Block(query: Get{{ pascalCase name }}BlockQuery): Observable<{{ pascalCase name }}Block> {
17-
const cms = this.cmsService.get{{ pascalCase name }}Block(query);
18+
get{{ pascalCase name }}Block(
19+
query: Get{{ pascalCase name }}BlockQuery,
20+
headers: AppHeaders,
21+
): Observable<{{ pascalCase name }}Block> {
22+
const cms = this.cmsService.get{{ pascalCase name }}Block({ ...query, locale: headers['x-locale'] });
1823

19-
return forkJoin([cms]).pipe(map(([cms]) => map{{ pascalCase name }}(cms, query.locale)));
24+
return forkJoin([cms]).pipe(map(([cms]) => map{{ pascalCase name }}(cms, headers['x-locale'])));
2025
}
2126
}

apps/frontend/turbo/generators/templates/block/server.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import dynamic from 'next/dynamic';
12
import React from 'react';
23

34
import { sdk } from '@/api/sdk';
45

5-
import { {{ pascalCase name }}Pure } from './{{ pascalCase name }}.client';
66
import { {{ pascalCase name }}Props } from './{{ pascalCase name }}.types';
77

8+
9+
export const {{ pascalCase name }}Dynamic = dynamic(() =>
10+
import('./{{ pascalCase name }}.client').then((module) => module.{{ pascalCase name }}Pure),
11+
);
12+
813
export const {{ pascalCase name }}: React.FC<{{ pascalCase name }}Props> = async ({ id, accessToken, locale }) => {
914
const data = await sdk.blocks.get{{ pascalCase name }}(
1015
{

turbo/generators/config.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
1313
{
1414
type: 'checkbox',
1515
name: 'modules',
16-
choices: ['articles', 'cms', 'notifications', 'organizations', 'resources', 'tickets', 'users', 'cache'],
16+
choices: [
17+
'articles',
18+
'cms',
19+
'notifications',
20+
'organizations',
21+
'resources',
22+
'tickets',
23+
'users',
24+
'cache',
25+
],
1726
message: 'Choose which modules you want to be included in the integration.',
1827
validate: (input: string[]) => !!input.length,
1928
},
@@ -22,47 +31,47 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
2231
const actions: PlopTypes.ActionType[] = [
2332
{
2433
type: 'add',
25-
path: 'packages/api/integrations/{{kebabCase name}}/package.json',
34+
path: 'packages/integrations/{{kebabCase name}}/package.json',
2635
templateFile: 'templates/integration/package.hbs',
2736
},
2837
{
2938
type: 'add',
30-
path: 'packages/api/integrations/{{kebabCase name}}/tsconfig.json',
39+
path: 'packages/integrations/{{kebabCase name}}/tsconfig.json',
3140
templateFile: 'templates/integration/tsconfig.hbs',
3241
},
3342
{
3443
type: 'add',
35-
path: 'packages/api/integrations/{{kebabCase name}}/tsconfig.lint.json',
44+
path: 'packages/integrations/{{kebabCase name}}/tsconfig.lint.json',
3645
templateFile: 'templates/integration/tsconfig.lint.hbs',
3746
},
3847
{
3948
type: 'add',
40-
path: 'packages/api/integrations/{{kebabCase name}}/turbo.json',
49+
path: 'packages/integrations/{{kebabCase name}}/turbo.json',
4150
templateFile: 'templates/integration/turbo.hbs',
4251
},
4352
{
4453
type: 'add',
45-
path: 'packages/api/integrations/{{kebabCase name}}/.eslintrc.js',
54+
path: 'packages/integrations/{{kebabCase name}}/.eslintrc.js',
4655
templateFile: 'templates/integration/eslintrc.hbs',
4756
},
4857
{
4958
type: 'add',
50-
path: 'packages/api/integrations/{{kebabCase name}}/.gitignore',
59+
path: 'packages/integrations/{{kebabCase name}}/.gitignore',
5160
templateFile: 'templates/integration/gitignore.hbs',
5261
},
5362
{
5463
type: 'add',
55-
path: 'packages/api/integrations/{{kebabCase name}}/.prettierrc.mjs',
64+
path: 'packages/integrations/{{kebabCase name}}/.prettierrc.mjs',
5665
templateFile: 'templates/integration/prettierrc.hbs',
5766
},
5867
{
5968
type: 'add',
60-
path: 'packages/api/integrations/{{kebabCase name}}/src/integration.ts',
69+
path: 'packages/integrations/{{kebabCase name}}/src/integration.ts',
6170
templateFile: 'templates/integration/integration.hbs',
6271
},
6372
{
6473
type: 'add',
65-
path: 'packages/api/integrations/{{kebabCase name}}/src/modules/index.ts',
74+
path: 'packages/integrations/{{kebabCase name}}/src/modules/index.ts',
6675
template: '// MODULE_EXPORTS',
6776
},
6877
];
@@ -77,46 +86,46 @@ export default function generator(plop: PlopTypes.NodePlopAPI): void {
7786
actions.push(
7887
{
7988
type: 'add',
80-
path: `packages/api/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/index.ts`,
89+
path: `packages/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/index.ts`,
8190
templateFile: 'templates/integration/module-index.hbs',
8291
data: { module },
8392
},
8493
{
8594
type: 'add',
86-
path: `packages/api/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/{{kebabCase module}}.service.ts`,
95+
path: `packages/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/{{kebabCase module}}.service.ts`,
8796
templateFile: 'templates/integration/service.hbs',
8897
data: { module },
8998
},
9099
{
91100
type: 'add',
92-
path: `packages/api/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/{{kebabCase module}}.controller.ts`,
101+
path: `packages/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/{{kebabCase module}}.controller.ts`,
93102
templateFile: 'templates/integration/controller.hbs',
94103
data: { module },
95104
},
96105
{
97106
type: 'add',
98-
path: `packages/api/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/mappers/index.ts`,
107+
path: `packages/integrations/{{kebabCase name}}/src/modules/{{kebabCase module}}/mappers/index.ts`,
99108
templateFile: 'templates/integration/mappers-index.hbs',
100109
data: { module },
101110
},
102111
{
103112
type: 'modify',
104-
path: 'packages/api/integrations/{{kebabCase name}}/src/modules/index.ts',
113+
path: 'packages/integrations/{{kebabCase name}}/src/modules/index.ts',
105114
pattern: /(\/\/ MODULE_EXPORTS)/g,
106115
templateFile: 'templates/integration/modules-index.hbs',
107116
data: { module },
108117
},
109118
{
110119
type: 'modify',
111-
path: 'packages/api/integrations/{{kebabCase name}}/src/integration.ts',
120+
path: 'packages/integrations/{{kebabCase name}}/src/integration.ts',
112121
pattern: /(\/\/ MODULE_IMPORTS)/g,
113122
template:
114123
"import { Service as {{ pascalCase module }}Service } from './modules/{{kebabCase module}}';\n// MODULE_IMPORTS",
115124
data: { module },
116125
},
117126
{
118127
type: 'modify',
119-
path: 'packages/api/integrations/{{kebabCase name}}/src/integration.ts',
128+
path: 'packages/integrations/{{kebabCase name}}/src/integration.ts',
120129
pattern: /(\/\/ MODULE_EXPORTS)/g,
121130
template:
122131
' {{ camelCase module }}: {\n' +
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
import { {{pascalCase module}} } from '@o2s/framework/modules';
2+
13
export { {{pascalCase module}}Service as Service } from './{{kebabCase module}}.service';
2-
export { {{pascalCase module}}Controller as Controller } from './{{kebabCase module}}.controller';
4+
5+
export import Request = {{pascalCase module}}.Request;
6+
export import Model = {{pascalCase module}}.Model;

0 commit comments

Comments
 (0)