Skip to content

Commit ee256a2

Browse files
committed
refactor: enhance runWithRunner to accept command type and update related calls
1 parent 9a81449 commit ee256a2

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

booster/.husky/pre-push.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function runTests(): Promise<boolean> {
3535
if (await fs.pathExists('vendor/bin/pest')) {
3636
log.tool('PHPUnit', 'Running tests...')
3737
try {
38-
await runWithRunner(['composer', 'test:pest'])
38+
await runWithRunner(['composer', 'test:pest'], { type: 'php' })
3939
log.success('Tests passed')
4040
} catch {
4141
log.error('Tests failed')

booster/.husky/shared/core.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export async function initEnvironment(): Promise<void> {
6565
*/
6666
export interface RunOptions {
6767
quiet?: boolean
68+
type?: 'php' | 'node' | 'system'
6869
}
6970

7071
/**
@@ -76,17 +77,19 @@ export async function runWithRunner(
7677
command: string[],
7778
options: RunOptions = {},
7879
): Promise<ProcessOutput> {
79-
const { quiet = false } = options
80+
const { quiet = false, type = 'system' } = options
81+
82+
const finalCommand = await getExecCommand(command, type)
8083

8184
// Log command execution if not quiet
8285
if (!quiet) {
83-
const commandStr = command.join(' ')
86+
const commandStr = finalCommand.join(' ')
8487
log.info(`Executing: ${commandStr}`)
8588
}
8689

8790
return await $({
8891
stdio: quiet ? 'pipe' : 'inherit',
89-
})`${command}`
92+
})`${finalCommand}`
9093
}
9194

9295
/**

booster/.husky/shared/extras.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ export async function generateDeptracImage(): Promise<void> {
1212

1313
try {
1414
// Use graphviz-image formatter to generate PNG directly
15-
await runWithRunner([
16-
'./vendor/bin/deptrac',
17-
'--formatter=graphviz-image',
18-
'--output=deptrac.png',
19-
])
15+
await runWithRunner(
16+
['./vendor/bin/deptrac', '--formatter=graphviz-image', '--output=deptrac.png'],
17+
{ type: 'php' },
18+
)
2019
if (await fs.pathExists('./deptrac.png')) {
2120
await runWithRunner(['git', 'add', 'deptrac.png'], { quiet: true })
2221

@@ -45,7 +44,7 @@ export async function generateApiDocs(): Promise<void> {
4544
// Check if swagger-php is installed by looking for the binary
4645
// This avoids reading/parsing composer.lock
4746
if (await fs.pathExists('./vendor/bin/openapi')) {
48-
await runWithRunner(['composer', 'generate-api-spec'])
47+
await runWithRunner(['composer', 'generate-api-spec'], { type: 'php' })
4948

5049
const diffResult = await runWithRunner(['git', 'diff', '--name-only'], { quiet: true })
5150
const modifiedFiles = diffResult.toString().trim().split('\n')

booster/.husky/shared/workflow.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { $, which } from 'zx'
22
import {
33
ensureMutagenSync,
44
formatDuration,
5-
getExecCommand,
65
initEnvironment,
76
isDdevProject,
87
isSkipped,
@@ -111,8 +110,10 @@ export async function runQualityTools(files: string[], tools: ToolConfig[]): Pro
111110
for (const chunk of chunks) {
112111
await Promise.all(
113112
chunk.map(async (file) => {
114-
const cmd = await getExecCommand([tool.command, ...args, file], tool.type)
115-
return runWithRunner(cmd, { quiet: true })
113+
return runWithRunner([tool.command, ...args, file], {
114+
quiet: true,
115+
type: tool.type,
116+
})
116117
}),
117118
)
118119
}
@@ -122,8 +123,7 @@ export async function runQualityTools(files: string[], tools: ToolConfig[]): Pro
122123
if (tool.passFiles !== false) {
123124
cmdArgs.push(...filesToRun)
124125
}
125-
const cmd = await getExecCommand([tool.command, ...cmdArgs], tool.type)
126-
await runWithRunner(cmd)
126+
await runWithRunner([tool.command, ...cmdArgs], { type: tool.type })
127127
}
128128
})
129129

0 commit comments

Comments
 (0)