UNPKG

@elsikora/setup-wizard

Version:

Setup Wizard - CLI scaffolding utility

145 lines (144 loc) 6.29 kB
import type { IModuleService } from "../../infrastructure/interface/module-service.interface"; import type { ICliInterfaceService } from "../interface/cli-interface-service.interface"; import type { ICommandService } from "../interface/command-service.interface"; import type { IConfigService } from "../interface/config-service.interface"; import type { IFileSystemService } from "../interface/file-system-service.interface"; import type { IModuleSetupResult } from "../interface/module-setup-result.interface"; import { PackageJsonService } from "./package-json.service"; /** * Service for setting up and managing ESLint configuration. * Handles the detection, installation, and configuration of ESLint features. */ export declare class EslintModuleService implements IModuleService { /** CLI interface service for user interaction */ readonly CLI_INTERFACE_SERVICE: ICliInterfaceService; /** Command service for executing shell commands */ readonly COMMAND_SERVICE: ICommandService; /** Configuration service for managing app settings */ readonly CONFIG_SERVICE: IConfigService; /** File system service for file operations */ readonly FILE_SYSTEM_SERVICE: IFileSystemService; /** Service for managing package.json */ readonly PACKAGE_JSON_SERVICE: PackageJsonService; /** Cached ESLint configuration */ private config; /** Frameworks detected in the project */ private detectedFrameworks; /** Service for framework detection and configuration */ private readonly FRAMEWORK_SERVICE; /** ESLint features selected by the user */ private selectedFeatures; /** * Initializes a new instance of the ESLintModuleService. * @param cliInterfaceService - Service for CLI user interactions * @param fileSystemService - Service for file system operations * @param configService - Service for managing app configuration */ constructor(cliInterfaceService: ICliInterfaceService, fileSystemService: IFileSystemService, configService: IConfigService); /** * Checks if the installed ESLint version meets the minimum requirements. * Offers to update ESLint if the version is too old. * @returns Promise resolving to true if ESLint version is acceptable, false otherwise */ checkEslintVersion(): Promise<boolean>; /** * Handles existing ESLint setup. * Checks for existing configuration and asks if user wants to remove it. * @returns Promise resolving to true if setup should proceed, false otherwise */ handleExistingSetup(): Promise<boolean>; /** * Installs and configures ESLint. * Guides the user through the setup process including feature selection. * @returns Promise resolving to the module setup result */ install(): Promise<IModuleSetupResult>; /** * Determines if ESLint should be installed. * Asks the user if they want to set up ESLint for their project. * Uses the saved config value as default if it exists. * @returns Promise resolving to true if ESLint should be installed, false otherwise */ shouldInstall(): Promise<boolean>; /** * Collects all required npm dependencies for selected ESLint features. * @returns Array of package names to install */ private collectDependencies; /** * Creates the ESLint configuration file. * Generates a configuration with the selected features and ignore paths. */ private createConfig; /** * Detects frameworks used in the project. * Identifies frameworks like React, Angular, TypeScript, etc. */ private detectFrameworks; /** * Detects ESLint features that should be installed based on project dependencies. * Examines package.json and detected frameworks to determine appropriate features. * @returns Promise resolving to an array of detected ESLint features */ private detectInstalledFeatures; /** * Displays a summary of the ESLint setup results. * Shows detected frameworks, selected features, and generated scripts. */ private displaySetupSummary; /** * Finds existing ESLint configuration files. * @returns Promise resolving to an array of file paths for existing configuration files */ private findExistingConfigFiles; /** * Generates the ESLint command for linting. * Creates a command string targeting appropriate directories based on detected frameworks. * @returns The eslint command string */ private generateLintCommand; /** * Generates the ESLint command for fixing linting issues. * Creates a command string with the --fix flag targeting appropriate directories. * @returns The eslint fix command string */ private generateLintFixCommand; /** * Generates the list of paths to ignore in the ESLint configuration. * @returns Array of ignore patterns for ESLint */ private generateLintIgnorePaths; /** * Gets the patterns of files and directories to ignore during linting. * Combines framework-specific ignore patterns with general ones. * @returns Array of ignore patterns */ private getIgnorePatterns; /** * Prompts the user to select which ESLint features to enable. * Presents detected features and saved features as initial selections. * @param savedFeatures - Previously saved ESLint features * @returns Promise resolving to an array of selected ESLint features */ private selectFeatures; /** * Sets up npm scripts for ESLint. * Adds scripts for linting, fixing, watching, and type checking. */ private setupScripts; /** * Sets up the selected ESLint features. * Installs dependencies, creates config files, and sets up scripts. */ private setupSelectedFeatures; /** * Uninstalls existing ESLint configuration packages. */ private uninstallExistingConfig; /** * Validates if the selected features are compatible with the detected frameworks. * Checks if TypeScript features are selected only when TypeScript is detected. * @returns Boolean indicating whether the feature selection is valid */ private validateFeatureSelection; }