UNPKG

@aws/cloudfront-hosting-toolkit

Version:

CloudFront Hosting Toolkit offers the convenience of a managed frontend hosting service while retaining full control over the hosting and deployment infrastructure to make it your own.

213 lines (211 loc) 12.6 kB
#!/usr/bin/env node import { HostingConfiguration, CommonAttributes } from "../shared/types"; /** * Retrieves the absolute path of the current working directory. * @returns The absolute path of the current working directory as a string. */ export declare function getCLIExecutionFolder(): string; /** * Detects the root folder of the CDK project based on the presence of 'package.json' * and the 'name' property in the project's package.json file. * The function checks the current directory and the 'cloudfront-hosting-toolkit' subdirectory to find the project root. * @returns The path to the root folder of the CloudFront Pages CDK project, if found, or the absolute path to the current directory if not found. */ export declare function getCLIInstallationFolder(): string; /** * Retrieves the file path of the build configuration used to construct the website before deployment. * The function combines the current working directory path and the relevant file names to construct the path. * @returns The absolute file path of the build configuration used for website construction. */ export declare function getBuildConfigFilePath(): string; export declare function getCffConfigFilePath(): string; /** * Retrieves the file path of the configuration file used for the deployment of the hosting infrastructure. * The function combines the current working directory path and the relevant file names to construct the path. * @returns The absolute file path of the deployment configuration file. */ export declare function getConfigFilePath(): string; /** * Retrieves the absolute path of the folder where the hosting infrastructure tool is located. * The function combines the current working directory path and the name of the tool folder to construct the path. * @returns The absolute path of the hosting infrastructure tool folder. */ export declare function getToolFolder(): string; export declare function getBuildConfigTemplatesFolder(): string; export declare function getCffTemplatesFolder(): string; export declare function getBuildConfigS3Folder(): string; /** * Calculates the main stack name based on the provided hosting configuration. * * The stack name is generated using the following criteria: * - If the configuration corresponds to a repository, the stack name will be derived * from the repository's name and the branch name. * - If the configuration corresponds to an S3 bucket, the stack name will use the bucket's name. * * The resultant stack name will: * - Begin with an alphabetic character. * - Contain only alphanumeric characters and hyphens. * - Be no longer than 128 characters. * - Not end with a hyphen. * * @param hostingConfiguration - The hosting configuration from which to derive the stack name. * @returns A sanitized stack name conforming to the above criteria. * @throws {Error} Throws an error if the provided repository URL is invalid. */ export declare function calculateMainStackName(hostingConfiguration: HostingConfiguration): string; /** * Constructs a main stack name based on repository owner, repository name, and branch name. * If the resulting stack name exceeds 128 characters, it truncates to fit within the limit. * The generated stack name: * - Begins with an alphabetic character. * - Contains only alphanumeric characters and hyphens. * - Is no longer than 128 characters. * * @param {string} repoOwner - The owner of the repository. * @param {string} repoName - The name of the repository. * @param {string} branchName - The name of the branch. * @returns {string} The sanitized stack name conforming to the criteria. */ export declare function calculateConnectionStackName(repoUrl: string, branchName: string): string; export declare function cleanPipelineNameStr(stackName: string): string; export declare function cleanBuildNameStr(stackName: string): string; export declare function cleanActionNameStr(stackName: string): string; export declare function calculateCodeStarConnectionStackName(repoUrl: string, branchName: string): string; /** * Parses the input repository URL to extract the repository owner and repository name. * The function supports both HTTPS and SSH GitHub repository URL formats. * @param url The repository URL to parse. * @returns An object with 'repoOwner' and 'repoName' properties if the URL matches the expected GitHub formats, */ export declare function parseRepositoryUrl(url: string): { repoOwner: string; repoName: string; }; export declare function getNiceFrameworkLabel<T>(key: string): T | string; /** * Retrieves a list of available hosting frameworks from the build_config_templates directory. * The function reads the hosting configuration template files with names starting with "hosting_" and ending with ".yml". * Each detected framework is added to a list as an object with 'title' and 'value' properties. * The 'title' represents the nice label for the framework, and the 'value' represents the framework name used internally. * The function also adds an "Exit" option to the list to allow users to exit the framework selection. * @returns An array of objects containing the available hosting frameworks, each with 'title' and 'value' properties. * If no frameworks are found, the array will be empty. */ export declare function frameworkList(): { title: string; value: string; }[]; /** * Checks if the provided string is a valid GitHub URL. * @param url The string to be checked for validity as a GitHub URL. * @returns true if the input is a valid GitHub URL, false otherwise. */ export declare function isValidGithubUrl(url: string): boolean; /** * Checks if the provided string is a valid domain name. * @param domainName The string to be checked for validity as a domain name. * @returns true if the input is a valid domain name, false otherwise. */ export declare function isValidDomainName(domainName: string): boolean; /** * Find the index of a given search string in an array of objects. * @param searchString The string to search for in the array. * @param existingConfig The array of objects to search through. * @returns The index of the first object in the array whose 'value' property contains the search string (case-insensitive). * If no match is found, returns 0. */ export declare function findIndex(searchString: string, existingConfig: { title: string; value: string; }[]): number; /** * Retrieves the GitHub repository URL from the local git repository configuration at the specified folderPath. * The function reads the '.git/config' file in the repository to extract the remote repository URL. * @param folderPath The path to the local git repository folder where the '.git' directory is located. * @returns The GitHub repository URL (if found and valid) or an empty string if the URL cannot be detected or the repository is not a valid git repository. * The repository URL is extracted from the remote repository configuration in the '.git/config' file. */ export declare function getGitRemote(): string; /** * Retrieves the GitHub branch associated with the local git repository configuration at the specified folderPath. * The function reads the '.git/config' file in the repository to extract the remote branch information. * @param folderPath The path to the local git repository folder where the '.git' directory is located. * @returns The GitHub branch name (if found) or undefined if the branch cannot be detected or the repository is not a valid git repository. * The branch name is extracted from the remote branch configuration in the '.git/config' file. */ export declare function getGitBranch(): string; /** * Detects the frontend framework utilized by examining the package.json file at the specified packagePath. * The function checks the presence of specific scripts and dependencies related to known frontend frameworks. * @param packagePath The path to the directory containing the package.json file to analyze. * @returns A Promise that resolves with the detected frontend framework (if found) or undefined if no recognized framework is detected. * If the package.json file is not found, it indicates that no frontend framework is used, and the return value will be FrontendFramework.NONE. */ export declare function detectFrontendFramework(packagePath: string): Promise<string>; /** * Reads and returns the configuration data from the build configuration file. * The build configuration file is expected to be in JSON format. * If the file is found and successfully read, its content is parsed and returned as an object. * If the file is not found or an error occurs during reading or parsing, an error message is logged, and the process exits with code 1. * @returns An object representing the configuration data read from the build configuration file. * @throws {Error} If the file is not found or cannot be read or parsed, an error is thrown. */ export declare function getConfigFileContent(): any; /** Loads the hosting configuration from a specified file path. The function first attempts to require and load the configuration from the given file path. If the configuration file is not found, it proceeds without an error but with an empty configuration object. The function then validates the loaded configuration object to ensure that it contains the required properties for a valid HostingConfiguration. Specifically, a valid configuration must either have 'repoUrl', 'branchName', and 'framework' properties, or 's3bucket' and 's3path' properties. @returns {HostingConfiguration} The loaded and validated hosting configuration. @throws {Error} Throws an error if the configuration format is invalid. */ export declare const loadHostingConfiguration: (configFile?: string) => Promise<HostingConfiguration>; export declare const doesHostingConfigurationFileExist: () => boolean; /** * Executes a command using the `spawn` function from the `child_process` module. * The command's progress and output are logged to a file and displayed as a progress bar. * @param command An object representing the command to be executed, containing `label` and `cmd` properties. * @param pwd The current working directory where the command should be executed. * @returns A Promise that resolves when the command is successfully executed, or rejects if it fails. * The function logs the command's output and progress to a file and displays a progress bar on the console. * If the command fails (exit code other than 0), an error is thrown with a detailed error message and the process exits with code 1. * The log file path is retrieved using `getLogFilePath()` function and is created or appended to as needed. * The progress bar is displayed using the `cli-progress` library. */ export declare function executeCommands(cmd: String, pwd: string): Promise<void>; /** * Generates an array of domain names with and without "www." based on the given domainName. * If the domainName starts with "www.", it returns an array with both the original domainName and the one without "www.". * If the domainName does not start with "www.", it returns an array with both the original domainName and the one with "www." added. * @param domainName The domain name to process. * @returns An array of strings containing the original domainName and an alternate version with "www." added or removed. */ export declare function getDomainNames(domainName: string): string[]; /** * Starts a prompt with cancellation handling. * * This function initiates a user prompt with the specified question and automatically * handles cancellation by exiting the Command-Line Interface (CLI) if the user cancels * the prompt. It is designed for use cases where graceful handling of cancellation * is desired. * * @param question The prompt question object to be displayed. * @returns A promise that resolves with the user's response to the prompt. */ export declare function startPrompt(question: any): Promise<any>; export declare function checkPipelineStatus(): Promise<void>; export declare function isRepoConfig(config: HostingConfiguration): config is { repoUrl: string; branchName: string; framework: string; } & CommonAttributes; export declare function isS3Config(config: HostingConfiguration): config is { s3bucket: string; s3path: string; } & CommonAttributes; export declare function isValidBucketName(bucketName: string): boolean | string; export declare function validateNoLeadingTrailingSlashes(inputString: string): boolean;