Skip to content

Commit

Permalink
chore: Add test workflow on CI (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe authored May 25, 2024
1 parent 6bbebed commit 9ea102a
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 26 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: test

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: run test
run: sh test.sh

- name: Archive generated files
uses: actions/upload-artifact@v4
with:
name: generated-file-${{ matrix.os }}
path: examples/laravel10-app/resources/js/types
1 change: 1 addition & 0 deletions examples/laravel10-app/.laravel-typegen-tmp/History.json
Original file line number Diff line number Diff line change
@@ -0,0 +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":[]}
1 change: 1 addition & 0 deletions examples/laravel10-app/.laravel-typegen-tmp/Job.json
Original file line number Diff line number Diff line change
@@ -0,0 +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":[]}
1 change: 1 addition & 0 deletions examples/laravel10-app/.laravel-typegen-tmp/Post.json
Original file line number Diff line number Diff line change
@@ -0,0 +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":[]}
1 change: 1 addition & 0 deletions examples/laravel10-app/.laravel-typegen-tmp/User.json
Original file line number Diff line number Diff line change
@@ -0,0 +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 number Diff line number Diff line change
@@ -0,0 +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":[]}
1 change: 1 addition & 0 deletions examples/laravel10-app/.laravel-typegen-tmp/route.json
Original file line number Diff line number Diff line change
@@ -0,0 +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"]}]
1 change: 0 additions & 1 deletion examples/laravel10-app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
Expand Down
4 changes: 2 additions & 2 deletions examples/laravel10-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dev": "vite",
"build": "vite build",
"type:check": "vue-tsc --noEmit",
"typegen": "node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --ziggy --form-request",
"typegen": "KEEP_LARAVEL_JSON=true node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --ziggy --form-request",
"typegen:laravel-enum": "node node_modules/@7nohe/laravel-typegen/dist/src/cli.js --enum-path 'app/LaravelEnums' --laravel-enum"
},
"devDependencies": {
Expand All @@ -25,4 +25,4 @@
"vue-tsc": "^1.2.0",
"ziggy-js": "^1.5.0"
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dependencies": {
"@7nohe/laravel-zodgen": "^0.1.6",
"commander": "^12.0.0",
"consola": "^3.2.3",
"glob": "^10.3.12",
"php-parser": "^3.1.5",
"typescript": "^5.4.5"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
} from "./constants";
import fs from "fs";
import { defaultFormRequestPath } from "@7nohe/laravel-zodgen";
import { consola } from "consola";
import { colors } from "consola/utils";
import path from "path";

export type CLIOptions = {
output: string;
Expand Down Expand Up @@ -46,15 +49,23 @@ program

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

console.log(`Generating types...`);
consola.box(`${colors.bgBlueBright(`Laravel Typegen v${packageJson.version}`)}
[Options]
${Object.entries(options)
.map(([key, value]) => `${key}: ${value}`)
.join("\n")}
`);

try {
generate(options).then(() => {
console.log(`Types generated successfully!!`);
consola.success(
`Done! Generated types are available in ${path.resolve(options.output)}`
);
});
} catch {
console.log("Failed to generate types.");
if (fs.existsSync(tmpDir)) {
consola.error("Failed to generate types.");
if (fs.existsSync(tmpDir) && process.env.KEEP_LARAVEL_JSON !== "true") {
// Clean up
fs.rmSync(tmpDir, { recursive: true });
}
Expand Down
16 changes: 8 additions & 8 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const defaultOutputPath = 'resources/js/types';
export const defaultModelPath = 'app/Models';
export const defaultEnumPath = 'app/Enums';
export const modelFileName = 'model.ts';
export const routeParamsFileName = 'param.ts';
export const formRequestsFileName = 'formRequests.ts';
export const indexDeclarationFileName = 'route.d.ts';
export const tmpDir = "./.laravel-typegen-tmp";
export const defaultOutputPath = "resources/js/types";
export const defaultModelPath = "app/Models";
export const defaultEnumPath = "app/Enums";
export const modelFileName = "model.ts";
export const routeParamsFileName = "param.ts";
export const formRequestsFileName = "formRequests.ts";
export const indexDeclarationFileName = "route.d.ts";
export const tmpDir = ".laravel-typegen-tmp";
Loading

0 comments on commit 9ea102a

Please sign in to comment.