|
9 | 9 | * - API Documentation generation |
10 | 10 | */ |
11 | 11 | import { $, fs } from 'zx' |
12 | | -import { GitHook, log, runHook, runWithRunner } from './shared/index.ts' |
| 12 | +import { GitHook, isSkipped, log, runHook, runWithRunner, generateApiDocs } from './shared/index.ts' |
13 | 13 |
|
14 | 14 | const SKIP_COMMIT_MSG = 'chore: update API documentation' |
15 | 15 |
|
@@ -45,40 +45,14 @@ async function runTests(): Promise<boolean> { |
45 | 45 | } |
46 | 46 |
|
47 | 47 | async function handleApiDocs(): Promise<boolean> { |
48 | | - log.tool('API Documentation', 'Generating OpenAPI specification...') |
49 | | - try { |
50 | | - if (!(await fs.pathExists('vendor/zircote/swagger-php'))) { |
51 | | - log.info('swagger-php not installed -> skipping API docs.') |
52 | | - return true |
53 | | - } |
54 | | - |
55 | | - await runWithRunner(['composer', 'generate-api-spec']) |
56 | | - |
57 | | - // Check if openapi.yml changed |
58 | | - const diff = await $`git diff --name-only` |
59 | | - if (!diff.stdout.includes('documentation/openapi.yml')) { |
60 | | - log.success('API documentation check passed (no changes)') |
61 | | - return true |
62 | | - } |
63 | | - |
64 | | - log.info('API spec changed, regenerating HTML...') |
65 | | - await runWithRunner(['pnpm', 'generate:api-doc:html']) |
66 | | - |
67 | | - // Check for changes in documentation files |
68 | | - const status = await $`git status --porcelain documentation/openapi.html documentation/openapi.yml` |
69 | | - if (status.stdout.trim() !== '') { |
70 | | - log.info('API documentation is outdated. Updating and committing...') |
71 | | - |
72 | | - await $`git add documentation/openapi.html documentation/openapi.yml` |
73 | | - // Skip pre-commit (linting) but run commit-msg (ticket appending) |
74 | | - await $`SKIP_PRECOMMIT=1 git commit -m ${SKIP_COMMIT_MSG}` |
75 | | - |
76 | | - log.success('API documentation updated and committed.') |
77 | | - log.warn('The new documentation commit was created AFTER the push started.') |
78 | | - log.warn('Your code has been pushed, but you must run "git push" AGAIN to send the documentation update.') |
79 | | - return true |
80 | | - } |
| 48 | + // Allow skipping API docs generation explicitly via env var |
| 49 | + if (isSkipped('api_docs')) { |
| 50 | + log.info('Skipping API docs generation (SKIP_API_DOCS environment variable set)') |
| 51 | + return true |
| 52 | + } |
81 | 53 |
|
| 54 | + try { |
| 55 | + await generateApiDocs() |
82 | 56 | return true |
83 | 57 | } catch (e) { |
84 | 58 | log.error('API spec generation failed') |
|
0 commit comments