@elsikora/setup-wizard
Version:
Setup Wizard - CLI scaffolding utility
141 lines • 6.67 kB
TypeScript
import type { IPackageJson } from "../../domain/interface/package-json.interface";
import type { ICommandService } from "../interface/command-service.interface";
import type { IFileSystemService } from "../interface/file-system-service.interface";
import { EPackageJsonDependencyType } from "../../domain/enum/package-json-dependency-type.enum";
import { EPackageJsonDependencyVersionFlag } from "../../domain/enum/package-json-dependency-version-flag.enum";
/**
* Service for managing package.json operations.
* Handles reading, writing, and manipulating package.json file contents.
*/
export declare class PackageJsonService {
readonly fileSystemService: IFileSystemService;
readonly commandService: ICommandService;
/** Command service for executing npm commands */
readonly COMMAND_SERVICE: ICommandService;
/** File system service for reading and writing files */
readonly FILE_SYSTEM_SERVICE: IFileSystemService;
/**
* Initializes a new instance of the PackageJsonService.
* @param fileSystemService - Service for file system operations
* @param commandService - Service for executing commands
*/
constructor(fileSystemService: IFileSystemService, commandService: ICommandService);
/**
* Adds a dependency to the package.json file.
* @param name - The name of the dependency
* @param version - The version string of the dependency
* @param type - The type of dependency (prod, dev, peer, etc.), defaults to PROD
* @returns Promise that resolves when the dependency is added
*/
addDependency(name: string, version: string, type?: EPackageJsonDependencyType): Promise<void>;
/**
* Adds a script to the package.json file.
* @param name - The name of the script
* @param command - The command to execute for the script
* @returns Promise that resolves when the script is added
*/
addScript(name: string, command: string): Promise<void>;
/**
* Checks if the package.json file exists.
* @returns Promise that resolves to true if the file exists, false otherwise
*/
exists(): Promise<boolean>;
/**
* Gets the contents of the package.json file.
* @returns Promise that resolves to the parsed package.json contents
*/
get(): Promise<IPackageJson>;
/**
* Gets the dependencies of a specified type from the package.json file.
* @param type - The type of dependencies to get, defaults to PROD
* @returns Promise that resolves to a record of dependency names and versions
*/
getDependencies(type?: EPackageJsonDependencyType): Promise<Record<string, string>>;
/**
* Gets detailed version information for an installed dependency.
* Parses the version string to extract version parts and flags.
* @param name - The name of the dependency
* @param type - The type of dependency to check, defaults to ANY
* @returns Promise that resolves to detailed version information or undefined if not found
*/
getInstalledDependencyVersion(name: string, type?: EPackageJsonDependencyType): Promise<{
flag: EPackageJsonDependencyVersionFlag;
isPrerelease: boolean;
majorVersion: number;
minorVersion: number;
patchVersion: number;
prereleaseChannel?: string;
version: string;
} | undefined>;
/**
* Gets a specific property from the package.json file.
* @param property - The property key to get
* @returns Promise that resolves to the property value
*/
getProperty<K extends keyof IPackageJson>(property: K): Promise<IPackageJson[K]>;
/**
* Installs packages using npm.
* @param packages - The package(s) to install (string or array of strings)
* @param version - Optional version to install (only works with single package)
* @param type - The type of dependency to install as, defaults to PROD
* @returns Promise that resolves when installation is complete
*/
installPackages(packages: Array<string> | string, version?: string, type?: EPackageJsonDependencyType): Promise<void>;
/**
* Checks if a dependency exists in the package.json file.
* @param name - The name of the dependency to check
* @param type - The type of dependency to check, defaults to ANY
* @returns Promise that resolves to true if the dependency exists, false otherwise
*/
isExistsDependency(name: string, type?: EPackageJsonDependencyType): Promise<boolean>;
/**
* Merges partial package.json data with the existing file.
* @param partial - The partial package.json data to merge
* @returns Promise that resolves when the merge is complete
*/
merge(partial: Partial<IPackageJson>): Promise<void>;
/**
* Removes a dependency from the package.json file.
* @param name - The name of the dependency to remove
* @param type - The type of dependency to remove, defaults to PROD
* @returns Promise that resolves when the dependency is removed
*/
removeDependency(name: string, type?: EPackageJsonDependencyType): Promise<void>;
/**
* Removes a script from the package.json file.
* @param name - The name of the script to remove
* @returns Promise that resolves when the script is removed
*/
removeScript(name: string): Promise<void>;
/**
* Writes the package.json file with the provided content.
* @param packageJson - The package.json content to write
* @returns Promise that resolves when the file is written
*/
set(packageJson: IPackageJson): Promise<void>;
/**
* Sets a specific property in the package.json file.
* @param property - The property key to set
* @param value - The value to set for the property
* @returns Promise that resolves when the property is set
*/
setProperty<K extends keyof IPackageJson>(property: K, value: IPackageJson[K]): Promise<void>;
/**
* Uninstalls packages using npm.
* @param packages - The package(s) to uninstall (string or array of strings)
* @returns Promise that resolves when uninstallation is complete
*/
uninstallPackages(packages: Array<string> | string): Promise<void>;
/**
* Validates the package.json file for required fields.
* @returns Promise that resolves to an array of missing field names
*/
validate(): Promise<Array<string>>;
/**
* Gets the npm flag for a dependency type.
* @param type - The type of dependency
* @returns The corresponding npm flag string
*/
private getDependencyTypeFlag;
}
//# sourceMappingURL=package-json.service.d.ts.map