Skip to content

Commit 9ea102a

Browse files
authored
chore: Add test workflow on CI (#34)
1 parent 6bbebed commit 9ea102a

File tree

15 files changed

+210
-26
lines changed

15 files changed

+210
-26
lines changed

.github/workflows/test.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: test-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
test:
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest, windows-latest]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: pnpm/action-setup@v3
24+
with:
25+
version: 9
26+
- name: Install Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: "pnpm"
31+
- name: Install dependencies
32+
run: pnpm install --frozen-lockfile
33+
- name: run test
34+
run: sh test.sh
35+
36+
- name: Archive generated files
37+
uses: actions/upload-artifact@v4
38+
with:
39+
name: generated-file-${{ matrix.os }}
40+
path: examples/laravel10-app/resources/js/types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"App\\Models\\Common\\History","database":"mysql","table":"histories","policy":null,"attributes":[{"name":"id","type":"bigint unsigned","increments":true,"nullable":false,"default":null,"unique":true,"fillable":false,"hidden":false,"appended":null,"cast":"int"},{"name":"log","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"created_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"},{"name":"updated_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"}],"relations":[],"observers":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"App\\Models\\Job","database":"mysql","table":"jobs","policy":null,"attributes":[{"name":"id","type":"bigint unsigned","increments":true,"nullable":false,"default":null,"unique":true,"fillable":false,"hidden":false,"appended":null,"cast":"int"},{"name":"queue","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"payload","type":"text","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"attempts","type":"boolean unsigned","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"reserved_at","type":"integer unsigned","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"available_at","type":"integer unsigned","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"created_at","type":"integer unsigned","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"}],"relations":[],"observers":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"App\\Models\\Post","database":"mysql","table":"posts","policy":null,"attributes":[{"name":"id","type":"bigint unsigned","increments":true,"nullable":false,"default":null,"unique":true,"fillable":false,"hidden":false,"appended":null,"cast":"int"},{"name":"title","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"body","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"type","type":"string","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"App\\Enums\\PostType"},{"name":"user_id","type":"bigint unsigned","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"created_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"},{"name":"updated_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"}],"relations":[{"name":"author","type":"BelongsTo","related":"App\\Models\\User"}],"observers":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"App\\Models\\User","database":"mysql","table":"users","policy":null,"attributes":[{"name":"id","type":"bigint unsigned","increments":true,"nullable":false,"default":null,"unique":true,"fillable":false,"hidden":false,"appended":null,"cast":"int"},{"name":"name","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":true,"hidden":false,"appended":null,"cast":null},{"name":"email","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":true,"fillable":true,"hidden":false,"appended":null,"cast":null},{"name":"gender","type":"string","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"App\\Enums\\GenderType"},{"name":"email_verified_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"},{"name":"password","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":true,"hidden":true,"appended":null,"cast":null},{"name":"bio","type":"text(65535)","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"remember_token","type":"string(100)","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":true,"appended":null,"cast":null},{"name":"created_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"},{"name":"updated_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"}],"relations":[{"name":"posts","type":"HasMany","related":"App\\Models\\Post"},{"name":"userContacts","type":"HasMany","related":"App\\Models\\UserContact"},{"name":"tokens","type":"MorphMany","related":"Laravel\\Sanctum\\PersonalAccessToken"},{"name":"notifications","type":"MorphMany","related":"Illuminate\\Notifications\\DatabaseNotification"}],"observers":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"class":"App\\Models\\UserContact","database":"mysql","table":"user_contacts","policy":null,"attributes":[{"name":"id","type":"bigint unsigned","increments":true,"nullable":false,"default":null,"unique":true,"fillable":false,"hidden":false,"appended":null,"cast":"int"},{"name":"phone_number","type":"string(255)","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"user_id","type":"bigint unsigned","increments":false,"nullable":false,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":null},{"name":"created_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"},{"name":"updated_at","type":"datetime","increments":false,"nullable":true,"default":null,"unique":false,"fillable":false,"hidden":false,"appended":null,"cast":"datetime"}],"relations":[{"name":"user","type":"BelongsTo","related":"App\\Models\\User"}],"observers":[]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"domain":null,"method":"GET|HEAD","uri":"\/","name":null,"action":"Closure","middleware":["web"]},{"domain":null,"method":"GET|HEAD","uri":"api\/user","name":null,"action":"Closure","middleware":["api","App\\Http\\Middleware\\Authenticate:sanctum"]},{"domain":null,"method":"GET|HEAD","uri":"confirm-password","name":"password.confirm","action":"App\\Http\\Controllers\\Auth\\ConfirmablePasswordController@show","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"POST","uri":"confirm-password","name":null,"action":"App\\Http\\Controllers\\Auth\\ConfirmablePasswordController@store","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"GET|HEAD","uri":"dashboard","name":"dashboard","action":"App\\Http\\Controllers\\DashboardController","middleware":["web","App\\Http\\Middleware\\Authenticate","Illuminate\\Auth\\Middleware\\EnsureEmailIsVerified"]},{"domain":null,"method":"POST","uri":"email\/verification-notification","name":"verification.send","action":"App\\Http\\Controllers\\Auth\\EmailVerificationNotificationController@store","middleware":["web","App\\Http\\Middleware\\Authenticate","Illuminate\\Routing\\Middleware\\ThrottleRequests:6,1"]},{"domain":null,"method":"GET|HEAD","uri":"forgot-password","name":"password.request","action":"App\\Http\\Controllers\\Auth\\PasswordResetLinkController@create","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"POST","uri":"forgot-password","name":"password.email","action":"App\\Http\\Controllers\\Auth\\PasswordResetLinkController@store","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"GET|HEAD","uri":"login","name":"login","action":"App\\Http\\Controllers\\Auth\\AuthenticatedSessionController@create","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"POST","uri":"login","name":null,"action":"App\\Http\\Controllers\\Auth\\AuthenticatedSessionController@store","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"POST","uri":"logout","name":"logout","action":"App\\Http\\Controllers\\Auth\\AuthenticatedSessionController@destroy","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"PUT","uri":"password","name":"password.update","action":"App\\Http\\Controllers\\Auth\\PasswordController@update","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"GET|HEAD","uri":"posts","name":"posts.index","action":"App\\Http\\Controllers\\PostsController@index","middleware":["web"]},{"domain":null,"method":"POST","uri":"posts","name":"posts.store","action":"App\\Http\\Controllers\\PostsController@store","middleware":["web"]},{"domain":null,"method":"GET|HEAD","uri":"posts\/create","name":"posts.create","action":"App\\Http\\Controllers\\PostsController@create","middleware":["web"]},{"domain":null,"method":"GET|HEAD","uri":"posts\/{post}","name":"posts.show","action":"App\\Http\\Controllers\\PostsController@show","middleware":["web"]},{"domain":null,"method":"PUT|PATCH","uri":"posts\/{post}","name":"posts.update","action":"App\\Http\\Controllers\\PostsController@update","middleware":["web"]},{"domain":null,"method":"DELETE","uri":"posts\/{post}","name":"posts.destroy","action":"App\\Http\\Controllers\\PostsController@destroy","middleware":["web"]},{"domain":null,"method":"GET|HEAD","uri":"posts\/{post}\/edit","name":"posts.edit","action":"App\\Http\\Controllers\\PostsController@edit","middleware":["web"]},{"domain":null,"method":"GET|HEAD","uri":"profile","name":"profile.edit","action":"App\\Http\\Controllers\\ProfileController@edit","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"PATCH","uri":"profile","name":"profile.update","action":"App\\Http\\Controllers\\ProfileController@update","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"DELETE","uri":"profile","name":"profile.destroy","action":"App\\Http\\Controllers\\ProfileController@destroy","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"GET|HEAD","uri":"register","name":"register","action":"App\\Http\\Controllers\\Auth\\RegisteredUserController@create","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"POST","uri":"register","name":null,"action":"App\\Http\\Controllers\\Auth\\RegisteredUserController@store","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"POST","uri":"reset-password","name":"password.store","action":"App\\Http\\Controllers\\Auth\\NewPasswordController@store","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"GET|HEAD","uri":"reset-password\/{token}","name":"password.reset","action":"App\\Http\\Controllers\\Auth\\NewPasswordController@create","middleware":["web","App\\Http\\Middleware\\RedirectIfAuthenticated"]},{"domain":null,"method":"GET|HEAD","uri":"verify-email","name":"verification.notice","action":"App\\Http\\Controllers\\Auth\\EmailVerificationPromptController@__invoke","middleware":["web","App\\Http\\Middleware\\Authenticate"]},{"domain":null,"method":"GET|HEAD","uri":"verify-email\/{id}\/{hash}","name":"verification.verify","action":"App\\Http\\Controllers\\Auth\\VerifyEmailController@__invoke","middleware":["web","App\\Http\\Middleware\\Authenticate","App\\Http\\Middleware\\ValidateSignature","Illuminate\\Routing\\Middleware\\ThrottleRequests:6,1"]}]

examples/laravel10-app/docker-compose.yml

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# For more information: https://laravel.com/docs/sail
2-
version: '3'
32
services:
43
laravel.test:
54
build:

examples/laravel10-app/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"dev": "vite",
55
"build": "vite build",
66
"type:check": "vue-tsc --noEmit",
7-
"typegen": "node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --ziggy --form-request",
7+
"typegen": "KEEP_LARAVEL_JSON=true node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --ziggy --form-request",
88
"typegen:laravel-enum": "node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --enum-path 'app/LaravelEnums' --laravel-enum"
99
},
1010
"devDependencies": {
@@ -25,4 +25,4 @@
2525
"vue-tsc": "^1.2.0",
2626
"ziggy-js": "^1.5.0"
2727
}
28-
}
28+
}

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"dependencies": {
3535
"@7nohe/laravel-zodgen": "^0.1.6",
3636
"commander": "^12.0.0",
37+
"consola": "^3.2.3",
3738
"glob": "^10.3.12",
3839
"php-parser": "^3.1.5",
3940
"typescript": "^5.4.5"

pnpm-lock.yaml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {
1010
} from "./constants";
1111
import fs from "fs";
1212
import { defaultFormRequestPath } from "@7nohe/laravel-zodgen";
13+
import { consola } from "consola";
14+
import { colors } from "consola/utils";
15+
import path from "path";
1316

1417
export type CLIOptions = {
1518
output: string;
@@ -46,15 +49,23 @@ program
4649

4750
const options = program.opts<CLIOptions>();
4851

49-
console.log(`Generating types...`);
52+
consola.box(`${colors.bgBlueBright(`Laravel Typegen v${packageJson.version}`)}
53+
54+
[Options]
55+
${Object.entries(options)
56+
.map(([key, value]) => `${key}: ${value}`)
57+
.join("\n")}
58+
`);
5059

5160
try {
5261
generate(options).then(() => {
53-
console.log(`Types generated successfully!!`);
62+
consola.success(
63+
`Done! Generated types are available in ${path.resolve(options.output)}`
64+
);
5465
});
5566
} catch {
56-
console.log("Failed to generate types.");
57-
if (fs.existsSync(tmpDir)) {
67+
consola.error("Failed to generate types.");
68+
if (fs.existsSync(tmpDir) && process.env.KEEP_LARAVEL_JSON !== "true") {
5869
// Clean up
5970
fs.rmSync(tmpDir, { recursive: true });
6071
}

src/constants.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export const defaultOutputPath = 'resources/js/types';
2-
export const defaultModelPath = 'app/Models';
3-
export const defaultEnumPath = 'app/Enums';
4-
export const modelFileName = 'model.ts';
5-
export const routeParamsFileName = 'param.ts';
6-
export const formRequestsFileName = 'formRequests.ts';
7-
export const indexDeclarationFileName = 'route.d.ts';
8-
export const tmpDir = "./.laravel-typegen-tmp";
1+
export const defaultOutputPath = "resources/js/types";
2+
export const defaultModelPath = "app/Models";
3+
export const defaultEnumPath = "app/Enums";
4+
export const modelFileName = "model.ts";
5+
export const routeParamsFileName = "param.ts";
6+
export const formRequestsFileName = "formRequests.ts";
7+
export const indexDeclarationFileName = "route.d.ts";
8+
export const tmpDir = ".laravel-typegen-tmp";

0 commit comments

Comments
 (0)