index.ts 1.35 KB
import type { CAC } from "cac";

import { execaCommand, findMonorepoRoot } from "@venus/node-utils";

interface LintCommandOptions {
	/**
	 * Format lint problem.
	 */
	format?: boolean;
}

async function runLint({ format }: LintCommandOptions) {
	// process.env.FORCE_COLOR = '3';
	const root = findMonorepoRoot();

	if (format) {
		console.log("\n📝 Running Prettier...");
		await execaCommand(`prettier . --write --cache`, {
			stdio: "inherit",
			cwd: root,
		});
		console.log("\n🎨 Running Stylelint...");
		await execaCommand(`stylelint "**/*.{vue,css,less,scss,wxss}" --cache --fix --formatter verbose`, {
			stdio: "inherit",
			cwd: root,
		});
		console.log("\n🔍 Running ESLint...");
		await execaCommand(`eslint . --cache --fix`, {
			stdio: "inherit",
			cwd: root,
		});
		console.log("\n✅ Format completed!");
		return;
	}
	await Promise.all([
		execaCommand(`prettier . --ignore-unknown --check --cache`, {
			stdio: "inherit",
			cwd: root,
		}),
		execaCommand(`pnpm eslint . --cache`, {
			stdio: "inherit",
			cwd: root,
		}),
		execaCommand(`stylelint "**/*.{vue,css,less,scss,wxss}" --cache`, {
			stdio: "inherit",
			cwd: root,
		}),
	]);
}

function defineLintCommand(cac: CAC) {
	cac.command("lint")
		.usage("Batch execute project lint check.")
		.option("--format", "Format lint problem.")
		.action(runLint);
}

export { defineLintCommand };