import { TreeLike } from '@rxap/workspace-utilities'; import 'colors'; export type SerializedSchematic = Record | Array>; /** * Retrieves a serialized schematic from a specified directory within a tree-like structure. * * This function searches for files within a given path in the tree structure that match * schematic-related file patterns (specifically YAML or JSON files prefixed with 'schematics' or 'schematic'). * It reads the content of the first matching file and returns it as a serialized schematic object. * If no matching files are found, the function returns null. * * @param {TreeLike} tree - The tree-like structure containing the files. * @param {string} path - The path within the tree where the search should be performed. * @returns {SerializedSchematic | null} - The serialized schematic object if a matching file is found; otherwise, null. */ export declare function GetSerializedSchematicFromFile(tree: TreeLike, path: string): SerializedSchematic | null; /** * Writes a serialized schematic to a file, replacing the existing file if the content has changed. * This function first retrieves any existing serialized schematic from the specified path. If the * existing content differs from the new data provided, it deletes the old file and writes the new * content. If the data is an array, it filters out any empty objects before serialization. * * @param tree The file system tree abstraction used for file operations. * @param path The directory path where the schematic file is located. * @param data The serialized schematic data to be written. This can be either a single object or an array of objects. * @throws {Error} Throws an error if the file cannot be written to the specified directory. */ export declare function WriteSerializedSchematicFile(tree: TreeLike, path: string, data: SerializedSchematic): void; /** * Checks if a specified directory within a tree-like structure contains any schematic files in serialized formats. * * This function searches through the children of a specified path within a tree-like structure for files * with specific serialized file extensions (`.yaml`, `.yml`, `.json`). It specifically looks for files * that start with 'schematics' or 'schematic'. If any such file is found, the function returns true, * indicating the presence of a serialized schematic file. * * @param {TreeLike} tree - The tree-like structure containing directories and files. * @param {string} path - The path within the tree where the search should be conducted. * @returns {boolean} - Returns true if at least one serialized schematic file is found, otherwise false. */ export declare function HasSerializedSchematicFile(tree: TreeLike, path: string): boolean; /** * Deletes specific serialized schematic files from a given directory within a tree-like structure. * * This function iterates over the children of a specified path within the tree structure, identifying * and deleting files that are serialized schematic files (specifically YAML or JSON files) that start * with 'schematics' or 'schematic'. The function is designed to work with a tree-like data structure * that supports basic file operations through a `TreeAdapter`. * * @param {TreeLike} tree - The tree-like structure containing the files. * @param {string} path - The path within the tree where the files are located. * * @remarks * The function uses a `TreeAdapter` to interface with the tree structure, which must be compatible * with the TreeLike interface. This adapter facilitates operations like listing children of a node * and deleting nodes. The function specifically targets files with extensions '.yaml', '.yml', or '.json' * and file names that begin with 'schematics' or 'schematic'. * * @example * // Assuming `projectTree` is a TreeLike object representing a project's file structure: * DeleteSerializedSchematicFile(projectTree, '/path/to/directory'); */ export declare function DeleteSerializedSchematicFile(tree: TreeLike, path: string): void; export interface UpdateSerializedSchematicFileOptions { /** * true - create the file if it does not exist */ coerce?: boolean; } export declare function UpdateSerializedSchematicFile(tree: TreeLike, path: string, updater: (data: SerializedSchematic) => SerializedSchematic, options?: UpdateSerializedSchematicFileOptions): void; export declare function UpdateSerializedSchematicFile(tree: TreeLike, path: string, updater: (data: SerializedSchematic) => Promise, options?: UpdateSerializedSchematicFileOptions): Promise; /** * Generates and updates a serialized schematic file with new schematic data. * * This function is designed to serialize and store schematic configuration data into a specified file within a given tree-like structure. It first cleans and prepares the schematic options by removing specific properties and undefined values. Then, it updates the existing serialized file with the new schematic data or appends it if not already present. * * @param {TreeLike} tree - The tree-like structure where the file is located. * @param {string} path - The file path within the tree where the schematic data should be serialized. * @param {string} packageName - The name of the package to which the schematic belongs. * @param {string} schematicName - The name of the schematic. * @param {Record | any} [options={}] - Optional parameters for the schematic, provided as a key-value map. * * The function performs the following operations: * 1. Removes specified properties from the options object that are not necessary for serialization. * 2. Cleans up nested objects within the options to ensure they do not contain undefined values or empty objects. * 3. Checks if the schematic data already exists in the file: * - If it exists and is the only entry, it replaces it with the new data. * - If it exists among multiple entries, it updates the specific entry. * - If it does not exist, it adds the new data to the existing array or creates a new array if the file was empty. * 4. Utilizes a coercion strategy when updating the file to ensure data integrity. * * Note: This function relies on external functions `DeleteUndefinedProperties`, `DeleteProperties`, and `UpdateSerializedSchematicFile` to manipulate and store data. */ export declare function GenerateSerializedSchematicFile(tree: TreeLike, path: string, packageName: string, schematicName: string, options?: Record | any): void;