Skip to content

Commit 07fce3c

Browse files
committed
fix(cli): recourse generation and schema types
1 parent ef99970 commit 07fce3c

14 files changed

+135
-80
lines changed

.github/workflows/cli.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CLI tests
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out frontend
13+
uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 22
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Generate resources and fields
20+
run: npm run generate:resource -- --name=Department
21+
- run: npm run generate:resource -- --name=People
22+
- run: npm run generate:field -- --name=Department --property=name --kind=primitive --type=string --isOptional=false --isShowInTable=true
23+
- run: npm run generate:field -- --name=People --property=profilePicture --kind=reference --referenceType=toOne --type=File --isOptional=true --isShowInTable=true
24+
- run: npm run generate:field -- --name=People --property=firstName --kind=primitive --type=string --isOptional=false --isShowInTable=true
25+
- run: npm run generate:field -- --name=People --property=lastName --kind=primitive --type=string --isOptional=false --isShowInTable=true
26+
- run: npm run generate:field -- --name=People --property=department --kind=reference --referenceType=toOne --type=Department --isOptional=true --isShowInTable=true --propertyForSelect=name
27+
- run: npm run generate:field -- --name=People --property=isActive --kind=primitive --type=boolean --isOptional=false --isShowInTable=true
28+
- run: npm run generate:field -- --name=People --property=birthDate --kind=primitive --type=Date --isOptional=true --isShowInTable=true
29+
- run: npm run generate:field -- --name=People --property=hireDate --kind=primitive --type=Date --isOptional=false --isShowInTable=true
30+
- run: npm run generate:field -- --name=People --property=salary --kind=primitive --type=number --isOptional=false --isShowInTable=true
31+
- name: Build
32+
run: npm run build

.github/workflows/e2e.yml

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,52 @@
11
name: E2E tests
22
on:
33
push:
4-
branches: [ main ]
4+
branches: [main]
55
pull_request:
6-
branches: [ main ]
6+
branches: [main]
77
jobs:
88
test:
99
timeout-minutes: 60
1010
runs-on: ubuntu-latest
1111
steps:
12-
- name: Check out backend
13-
uses: actions/checkout@v4
14-
with:
15-
repository: brocoders/nestjs-boilerplate
16-
# Use token for private repository
17-
# token: ${{ secrets.CI_PAT }}
18-
path: backend
19-
- run: cd backend && cp env-example-document .env
20-
- run: cd backend && sed -i 's/APP_PORT=3000/APP_PORT=3001/g' .env
21-
- run: cd backend && sed -i 's/BACKEND_DOMAIN=http:\/\/localhost:3000/BACKEND_DOMAIN=http:\/\/localhost:3001/g' .env
22-
- name: Run backend
23-
# print output of the command to file and store it as artifact
24-
run: cd backend && docker compose -f docker-compose.document.yaml up > ${{ runner.temp }}/backend.log 2>&1 &
25-
- run: cd backend && sed -i 's/\r//g' wait-for-it.sh
26-
- run: cd backend && ./wait-for-it.sh localhost:3001 -- echo "Backend is up"
12+
- name: Check out backend
13+
uses: actions/checkout@v4
14+
with:
15+
repository: brocoders/nestjs-boilerplate
16+
# Use token for private repository
17+
# token: ${{ secrets.CI_PAT }}
18+
path: backend
19+
- run: cd backend && cp env-example-document .env
20+
- run: cd backend && sed -i 's/APP_PORT=3000/APP_PORT=3001/g' .env
21+
- run: cd backend && sed -i 's/BACKEND_DOMAIN=http:\/\/localhost:3000/BACKEND_DOMAIN=http:\/\/localhost:3001/g' .env
22+
- name: Run backend
23+
# print output of the command to file and store it as artifact
24+
run: cd backend && docker compose -f docker-compose.document.yaml up > ${{ runner.temp }}/backend.log 2>&1 &
25+
- run: cd backend && sed -i 's/\r//g' wait-for-it.sh
26+
- run: cd backend && ./wait-for-it.sh localhost:3001 -- echo "Backend is up"
2727

28-
- uses: actions/checkout@v4
29-
- uses: actions/setup-node@v4
30-
with:
31-
node-version: 22
32-
- name: Install dependencies
33-
run: npm ci
34-
- name: Run lint
35-
run: npm run lint
36-
- name: Install Playwright Browsers
37-
run: npx playwright install --with-deps
38-
- name: Run Playwright tests
39-
run: npx playwright test
40-
- uses: actions/upload-artifact@v4
41-
if: ${{ !cancelled() }}
42-
with:
43-
name: playwright-report
44-
path: playwright-report/
45-
retention-days: 30
46-
- uses: actions/upload-artifact@v4
47-
if: ${{ !cancelled() }}
48-
with:
49-
name: backend-log
50-
path: ${{ runner.temp }}/backend.log
51-
retention-days: 30
28+
- name: Check out frontend
29+
uses: actions/checkout@v4
30+
- uses: actions/setup-node@v4
31+
with:
32+
node-version: 22
33+
- name: Install dependencies
34+
run: npm ci
35+
- name: Run lint
36+
run: npm run lint
37+
- name: Install Playwright Browsers
38+
run: npx playwright install --with-deps
39+
- name: Run Playwright tests
40+
run: npx playwright test
41+
- uses: actions/upload-artifact@v4
42+
if: ${{ !cancelled() }}
43+
with:
44+
name: playwright-report
45+
path: playwright-report/
46+
retention-days: 30
47+
- uses: actions/upload-artifact@v4
48+
if: ${{ !cancelled() }}
49+
with:
50+
name: backend-log
51+
path: ${{ runner.temp }}/backend.log
52+
retention-days: 30

.hygen/generate/field/create/field-component-reference.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before: \<create\-component\-reference\-field \/\>
99
function <%= h.inflection.camelize(property, false) %>Field() {
1010
const { t } = useTranslation("admin-panel-<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>-create");
1111
const { data, hasNextPage, isFetchingNextPage, fetchNextPage } =
12-
useGet<%= h.inflection.transform(type, ['pluralize']) %>Query();
12+
useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery();
1313
1414
const options = useMemo(
1515
() => (data?.pages.flatMap((page) => page?.data ?? []).filter(Boolean) ?? []),

.hygen/generate/field/create/field-property-type.ejs.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ after: type CreateFormData
66

77
<% if (kind === 'primitive') { -%>
88
<% if (type === 'string') { -%>
9-
<%= property %><% if (isOptional) { -%>?<% } -%>: string;
9+
<%= property %>: string;
1010
<% } else if (type === 'number') { -%>
11-
<%= property %><% if (isOptional) { -%>?<% } -%>: string;
11+
<%= property %>: string;
1212
<% } else if (type === 'boolean') { -%>
13-
<%= property %><% if (isOptional) { -%>?<% } -%>: boolean;
13+
<%= property %>: boolean;
1414
<% } else if (type === 'Date') { -%>
15-
<%= property %><% if (isOptional) { -%>?<% } -%>: Date | null;
15+
<%= property %>: Date | null;
1616
<% } -%>
1717
<% } else if (kind === 'reference') { -%>
1818
<% if (referenceType === 'toMany') { -%>
@@ -23,9 +23,9 @@ after: type CreateFormData
2323
<% } -%>
2424
<% } else { -%>
2525
<% if (type === 'File') { -%>
26-
<%= property %><% if (isOptional) { -%>?<% } -%>: FileEntity | null;
26+
<%= property %>: FileEntity | null;
2727
<% } else { -%>
28-
<%= property %><% if (isOptional) { -%>?<% } -%>: <%= type %> | null;
28+
<%= property %>: <%= type %> | null;
2929
<% } -%>
3030
<% } -%>
3131
<% } -%>

.hygen/generate/field/create/field-property-validation.ejs.t

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@ before: \<create\-form\-validation\-schema \/\>
1010
.string()
1111
<% if (!isOptional) { -%>
1212
.required(t("inputs.<%= property %>.validation.required"))
13+
<% } else { -%>
14+
.defined()
1315
<% } -%>
1416
,
1517
<% } else if (type === 'number') { -%>
1618
<%= property %>: yup
1719
.string()
1820
<% if (!isOptional) { -%>
1921
.required(t("inputs.<%= property %>.validation.required"))
22+
<% } else { -%>
23+
.defined()
2024
<% } -%>
2125
,
2226
<% } else if (type === 'boolean') { -%>
23-
<%= property %>: yup.boolean(),
27+
<%= property %>: yup.boolean().defined(),
2428
<% } else if (type === 'Date') { -%>
2529
<%= property %>: yup
2630
.date()
2731
<% if (!isOptional) { -%>
2832
.required(t("inputs.<%= property %>.validation.required"))
2933
<% } -%>
30-
.nullable(),
34+
.nullable()
35+
<% if (isOptional) { -%>
36+
.defined()
37+
<% } -%>,
3138
<% } -%>
3239
<% } else if (kind === 'reference') { -%>
3340
<% if (referenceType === 'toMany') { -%>
@@ -57,6 +64,9 @@ before: \<create\-form\-validation\-schema \/\>
5764
<% if (!isOptional) { -%>
5865
.required(t("inputs.<%= property %>.validation.required"))
5966
<% } -%>
60-
.nullable(),
67+
.nullable()
68+
<% if (isOptional) { -%>
69+
.defined()
70+
<% } -%>,
6171
<% } -%>
6272
<% } -%>

.hygen/generate/field/create/import-type-query.ejs.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
inject: true
33
to: src/app/[language]/admin-panel/<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>/create/page-content.tsx
44
at_line: 2
5-
skip_if: import { useGet<%= h.inflection.transform(type, ['pluralize']) %>Query }
5+
skip_if: import { useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery }
66
---
77

88
<% if (kind === 'reference') { -%>
99
<% if (type !== 'File') { -%>
10-
import { useGet<%= h.inflection.transform(type, ['pluralize']) %>Query } from "@/app/[language]/admin-panel/<%= h.inflection.transform(type, ['pluralize', 'underscore', 'dasherize']) %>/queries/queries";
10+
import { useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery } from "@/app/[language]/admin-panel/<%= h.inflection.transform(type, ['pluralize', 'underscore', 'dasherize']) %>/queries/queries";
1111
<% } -%>
1212
<% } -%>

.hygen/generate/field/edit/field-component-reference.ejs.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ before: \<edit\-component\-reference\-field \/\>
99
function <%= h.inflection.camelize(property, false) %>Field() {
1010
const { t } = useTranslation("admin-panel-<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>-edit");
1111
const { data, hasNextPage, isFetchingNextPage, fetchNextPage } =
12-
useGet<%= h.inflection.transform(type, ['pluralize']) %>Query();
12+
useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery();
1313
1414
const options = useMemo(
1515
() => (data?.pages.flatMap((page) => page?.data ?? []).filter(Boolean) ?? []),

.hygen/generate/field/edit/field-property-type.ejs.t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ after: type EditFormData
66

77
<% if (kind === 'primitive') { -%>
88
<% if (type === 'string') { -%>
9-
<%= property %><% if (isOptional) { -%>?<% } -%>: string;
9+
<%= property %>: string;
1010
<% } else if (type === 'number') { -%>
11-
<%= property %><% if (isOptional) { -%>?<% } -%>: string;
11+
<%= property %>: string;
1212
<% } else if (type === 'boolean') { -%>
13-
<%= property %><% if (isOptional) { -%>?<% } -%>: boolean;
13+
<%= property %>: boolean;
1414
<% } else if (type === 'Date') { -%>
15-
<%= property %><% if (isOptional) { -%>?<% } -%>: Date | null;
15+
<%= property %>: Date | null;
1616
<% } -%>
1717
<% } else if (kind === 'reference') { -%>
1818
<% if (referenceType === 'toMany') { -%>
@@ -23,9 +23,9 @@ after: type EditFormData
2323
<% } -%>
2424
<% } else { -%>
2525
<% if (type === 'File') { -%>
26-
<%= property %><% if (isOptional) { -%>?<% } -%>: FileEntity | null;
26+
<%= property %>: FileEntity | null;
2727
<% } else { -%>
28-
<%= property %><% if (isOptional) { -%>?<% } -%>: <%= type %> | null;
28+
<%= property %>: <%= type %> | null;
2929
<% } -%>
3030
<% } -%>
3131
<% } -%>

.hygen/generate/field/edit/field-property-validation.ejs.t

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,31 @@ before: \<edit\-form\-validation\-schema \/\>
1010
.string()
1111
<% if (!isOptional) { -%>
1212
.required(t("inputs.<%= property %>.validation.required"))
13+
<% } else { -%>
14+
.defined()
1315
<% } -%>
1416
,
1517
<% } else if (type === 'number') { -%>
1618
<%= property %>: yup
1719
.string()
1820
<% if (!isOptional) { -%>
1921
.required(t("inputs.<%= property %>.validation.required"))
22+
<% } else { -%>
23+
.defined()
2024
<% } -%>
2125
,
2226
<% } else if (type === 'boolean') { -%>
23-
<%= property %>: yup.boolean(),
27+
<%= property %>: yup.boolean().defined(),
2428
<% } else if (type === 'Date') { -%>
2529
<%= property %>: yup
2630
.date()
2731
<% if (!isOptional) { -%>
2832
.required(t("inputs.<%= property %>.validation.required"))
2933
<% } -%>
30-
.nullable(),
34+
.nullable()
35+
<% if (isOptional) { -%>
36+
.defined()
37+
<% } -%>,
3138
<% } -%>
3239
<% } else if (kind === 'reference') { -%>
3340
<% if (referenceType === 'toMany') { -%>
@@ -57,6 +64,9 @@ before: \<edit\-form\-validation\-schema \/\>
5764
<% if (!isOptional) { -%>
5865
.required(t("inputs.<%= property %>.validation.required"))
5966
<% } -%>
60-
.nullable(),
67+
.nullable()
68+
<% if (isOptional) { -%>
69+
.defined()
70+
<% } -%>,
6171
<% } -%>
6272
<% } -%>

.hygen/generate/field/edit/import-type-query.ejs.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
inject: true
33
to: src/app/[language]/admin-panel/<%= h.inflection.transform(name, ['pluralize', 'underscore', 'dasherize']) %>/edit/[id]/page-content.tsx
44
at_line: 2
5-
skip_if: import { useGet<%= h.inflection.transform(type, ['pluralize']) %>Query }
5+
skip_if: import { useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery }
66
---
77

88
<% if (kind === 'reference') { -%>
99
<% if (type !== 'File') { -%>
10-
import { useGet<%= h.inflection.transform(type, ['pluralize']) %>Query } from "@/app/[language]/admin-panel/<%= h.inflection.transform(type, ['pluralize', 'underscore', 'dasherize']) %>/queries/queries";
10+
import { useGet<%= h.inflection.transform(type, ['pluralize']) %>ListQuery } from "@/app/[language]/admin-panel/<%= h.inflection.transform(type, ['pluralize', 'underscore', 'dasherize']) %>/queries/queries";
1111
<% } -%>
1212
<% } -%>

0 commit comments

Comments
 (0)