init project
This commit is contained in:
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
import { z } from 'zod';
|
||||
import { config } from '../../config.js';
|
||||
import { detectProject, resolvePackage } from '../../lib/frameworks/detect.js';
|
||||
import { resolveTarget } from '../../lib/frameworks/resolve.js';
|
||||
import { runCommand } from '../../lib/runCommand.js';
|
||||
import { errorResult, jsonResult, packageSchema, targetSchema, toErrorMessage } from '../shared.js';
|
||||
export function registerRunLintTool(server) {
|
||||
server.registerTool('run_lint', {
|
||||
title: 'Run Lint / Format',
|
||||
description: "Run the project's linter/formatter: ESLint/Prettier for React, Laravel Pint/PHP-CS-Fixer for Laravel, or PHP_CodeSniffer/PHP-CS-Fixer for CodeIgniter (whichever is configured). Returns diagnostics. Optional `package` scopes to a monorepo package.",
|
||||
inputSchema: {
|
||||
target: targetSchema,
|
||||
package: packageSchema,
|
||||
fix: z.boolean().optional().default(false).describe('Apply auto-fixes instead of only reporting.'),
|
||||
},
|
||||
}, async ({ target, package: packageName, fix }) => {
|
||||
try {
|
||||
const root = packageName
|
||||
? resolvePackage(config.workspaceRoot, packageName).pkg.absolutePath
|
||||
: config.workspaceRoot;
|
||||
const detected = detectProject(root);
|
||||
const { adapter, target: resolvedTarget } = resolveTarget(detected, target);
|
||||
const cmd = adapter.lintCommand(fix);
|
||||
if (!cmd) {
|
||||
return jsonResult({
|
||||
target: resolvedTarget,
|
||||
package: packageName ?? null,
|
||||
adapter: adapter.label,
|
||||
ran: false,
|
||||
message: 'No lint/format command configured for this project.',
|
||||
});
|
||||
}
|
||||
const result = await runCommand(cmd.command, cmd.args, { cwd: cmd.cwd });
|
||||
return jsonResult({
|
||||
target: resolvedTarget,
|
||||
package: packageName ?? null,
|
||||
adapter: adapter.label,
|
||||
ran: true,
|
||||
exitCode: result.exitCode,
|
||||
timedOut: result.timedOut,
|
||||
failed: result.failed,
|
||||
output: result.output,
|
||||
cwd: result.cwd,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
return errorResult(toErrorMessage(error));
|
||||
}
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=runLint.js.map
|
||||
Reference in New Issue
Block a user