Files
2026-07-31 13:12:54 -04:00

46 lines
1.7 KiB
JavaScript

import path from 'node:path';
import { readComposerJson, vendorBinExists } from './composer.js';
/**
* Shared behaviour for Composer-based PHP frameworks (Laravel, CodeIgniter).
* Subclasses only need to override the bits that actually differ: the CLI
* used for scaffolding/migrations (artisan vs spark), the dev-server "ready"
* line, and which test runner is used.
*/
export class PhpFrameworkAdapter {
root;
packageManager = 'composer';
composerJson;
constructor(root) {
this.root = root;
this.composerJson = readComposerJson(root);
}
installCommand() {
return { command: 'composer', args: ['install'], cwd: this.root };
}
buildCommand() {
return { command: 'composer', args: ['install', '--no-dev', '--optimize-autoloader'], cwd: this.root };
}
testCommand(extraArgs = []) {
if (vendorBinExists(this.root, 'pest')) {
return { command: this.vendorBin('pest'), args: extraArgs, cwd: this.root };
}
if (vendorBinExists(this.root, 'phpunit')) {
return { command: this.vendorBin('phpunit'), args: extraArgs, cwd: this.root };
}
return null;
}
lintCommand(fix = false) {
if (vendorBinExists(this.root, 'pint')) {
return { command: this.vendorBin('pint'), args: fix ? [] : ['--test'], cwd: this.root };
}
if (vendorBinExists(this.root, 'phpcs')) {
return { command: this.vendorBin(fix ? 'phpcbf' : 'phpcs'), args: [], cwd: this.root };
}
return null;
}
vendorBin(bin) {
const suffix = process.platform === 'win32' ? '.bat' : '';
return path.join(this.root, 'vendor', 'bin', `${bin}${suffix}`);
}
}
//# sourceMappingURL=phpBase.js.map