Skip to content

Commit

Permalink
chore: Remove docker on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe committed May 19, 2024
1 parent dc9da68 commit a699dfd
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 46 deletions.
38 changes: 3 additions & 35 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
Expand All @@ -26,40 +26,8 @@ jobs:
cache: "pnpm"
- name: install dependencies
run: pnpm install --frozen-lockfile

- run: cp .env.example .env
working-directory: examples/laravel10-app

- name: Setup Docker on macOS
uses: douglascamata/setup-docker-macos-action@v1-alpha
if: startsWith(matrix.os, 'macos')

- name: composer install
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/var/www/html" -w /var/www/html laravelsail/php81-composer:latest composer install --ignore-platform-reqs
working-directory: examples/laravel10-app

- name: start database
run: ./vendor/bin/sail up -d mysql
working-directory: examples/laravel10-app

- name: start laravel
run: ./vendor/bin/sail up -d
working-directory: examples/laravel10-app

- name: generate key
run: ./vendor/bin/sail artisan key:generate
working-directory: examples/laravel10-app

- name: migrate
run: ./vendor/bin/sail artisan migrate
working-directory: examples/laravel10-app

- name: npm install
run: ./vendor/bin/sail npm install
working-directory: examples/laravel10-app

- name: generate types
run: sh debug.sh
- name: run test
run: sh test.sh

- name: archive generated files
uses: actions/upload-artifact@v4
Expand Down
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"]}]
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"
}
}
}
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ try {
});
} catch {
console.log("Failed to generate types.");
if (fs.existsSync(tmpDir)) {
if (fs.existsSync(tmpDir) && process.env.KEEP_LARAVEL_JSON !== "true") {
// Clean up
fs.rmSync(tmpDir, { recursive: true });
}
Expand Down
37 changes: 29 additions & 8 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export async function generate(options: CLIOptions) {
const modelShowCommand = `php artisan model:show ${namespacedModel} --json > ${outputPath}`;

try {
execSync(modelShowCommand);
if (process.env.SKIP_ARTISAN_COMMAND !== "true") {
execSync(modelShowCommand);
} else {
console.log(`Skipping ${modelShowCommand}`);
}
const modelJson = JSON.parse(
fs.readFileSync(path.join(tmpDir, `${modelName}.json`), "utf8")
) as LaravelModelType;
Expand All @@ -72,9 +76,14 @@ export async function generate(options: CLIOptions) {
if (options.ziggy) {
const vendorOption = options.vendorRoutes ? "" : "--except-vendor";
const routeListCommand = `php artisan route:list ${vendorOption} --json > ${tmpDir}/route.json`;
execSync(routeListCommand);

if (process.env.SKIP_ARTISAN_COMMAND !== "true") {
execSync(routeListCommand);
} else {
console.log(`Skipping ${routeListCommand}`);
}
const routeJson = JSON.parse(
fs.readFileSync(`${tmpDir}/route.json`, "utf8")
fs.readFileSync(path.resolve(tmpDir, "route.json"), "utf8")
) as LaravelRouteListType[];

const routeSource = createRouteParamsSource(
Expand All @@ -83,13 +92,20 @@ export async function generate(options: CLIOptions) {
options
);

print(routeParamsFileName, routeSource, options.output ?? defaultOutputPath);
print(
routeParamsFileName,
routeSource,
options.output ?? defaultOutputPath
);

// Copy route.d.ts
if (!options.ignoreRouteDts) {
fs.copyFileSync(
path.resolve(__dirname, "..", "templates", indexDeclarationFileName),
path.resolve(options.output ?? defaultOutputPath, indexDeclarationFileName)
path.resolve(
options.output ?? defaultOutputPath,
indexDeclarationFileName
)
);
}
}
Expand All @@ -98,10 +114,15 @@ export async function generate(options: CLIOptions) {
// Generate types for form requests
const rules = parseFormRequests(options.formRequestPath, true);
const formRequestSource = createFormRequestTypes(rules);
print(formRequestsFileName, formRequestSource, options.output ?? defaultOutputPath);
print(
formRequestsFileName,
formRequestSource,
options.output ?? defaultOutputPath
);
}
if (fs.existsSync(tmpDir) && process.env.KEEP_LARAVEL_JSON !== "true") {
fs.rmSync(tmpDir, { recursive: true });
}

fs.rmSync(tmpDir, { recursive: true });
}

const createModelDirectory = (modelName: string) => {
Expand Down
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

pnpm run build
cd ./examples/laravel10-app
mv ../../dist ./
SKIP_ARTISAN_COMMAND=true KEEP_LARAVEL_JSON=true node ./dist/src/cli.js --ziggy --form-request
rm -rf ./dist

0 comments on commit a699dfd

Please sign in to comment.