UNPKG

@topgroup/diginext

Version:

A BUILD SERVER & CLI to deploy apps to any Kubernetes clusters.

267 lines 11.7 kB
/// <reference types="node" /> import type { AccessTokenInfo, IUser } from "../entities"; import type { AppConfig } from "../interfaces/AppConfig"; import type { KubeEnvironmentVariable } from "../interfaces/EnvironmentVariable"; import type { InputOptions } from "../interfaces/InputOptions"; import type { GitProviderType } from "../interfaces/SystemTypes"; import type { PullOrCloneGitRepoSSHOptions } from "../modules/git/git-interfaces"; export declare function nowStr(): string; /** * Delay/wait a specific miliseconds * @param i - waiting time in miliseconds * @param exec - callback function */ declare const wait: (i?: number, exec?: any) => Promise<unknown>; /** * Wait until a condition is matched * @param condition - Condition * @param interval - Re-check interval in seconds @default 10 * @param maxWaitingTime - Max waiting time in seconds @default 30 minutes (30 * 60 = 1.800 seconds) */ export declare function waitUntil(condition: Function, interval?: number, maxWaitTime?: number): Promise<boolean>; declare function logBitbucket(title: any, message: any, delay: any): Promise<void>; export declare const readJson: (filePath: any) => any; export type SaveJsonOptions = { overwrite?: boolean; beautify?: boolean; }; export declare const saveJson: (data: string | any, filePath: string, options?: SaveJsonOptions) => any; export declare const showDocs: (filePath: string) => Promise<string>; /** * Create temporary file with provided content * @param fileName - File name (include the extension) * @param content - Content of the file * @returns Path to the file */ export declare const createTmpFile: (fileName: string, content: string, options?: { recursive?: boolean; encoding?: BufferEncoding; }) => string; /** * Convert string-array-like to array * @example "1" -> ["1"] | "123,555,abc,def" -> ["123","555","abc","def"] */ export declare const stringToArray: (str: string, options?: { /** * Convert items to number if it's valid * @default false * @example "1,a,2" -> [1, "a", 2] */ typeTransform?: boolean; /** * @default "," */ divider?: string; }) => (string | number)[]; /** * Get full name of the environment, such as: `development`, `production` (instead of `dev`, `prod`) * @param {String} env * @returns {String} */ export declare const getLongEnv: (env: any) => any; /** * @param {String} filePath * @param {[{keyword:(RegExp|String), replacement:String}]} replacement=[] * @return {String} - New content */ export declare const replaceInFile: (filePath: any, replacement?: { keyword: RegExp | string; replacement: string; }[]) => Promise<string>; declare function toBase64(str: any): string; export declare function logVersion(): void; type ErrorCallback = (e: string) => void; export type CmdOptions = { isDebugging?: boolean; onProgress?: (msg: string) => void; }; export declare const progressCmd: (command: string, options?: CmdOptions) => Promise<string>; export declare function execCmd(cmd: string, errorMsgOrCallback?: string | ErrorCallback): Promise<string>; /** * Get current CLI version */ export declare function currentVersion(): string; /** * Get latest version of the CLI from NPM */ export declare function getLatestCliVersion(): Promise<string>; /** * Check if CLI version is latest or not, if not -> return FALSE */ export declare function shouldNotifyCliUpdate(): Promise<boolean>; declare function logBitbucketError(error: any, delay?: number, location?: string, shouldExit?: boolean): Promise<void>; export declare const parseRepoSlugFromUrl: (url: any) => any; export declare const deleteFolderRecursive: (dir: string) => Promise<void>; /** * Flatten the object into 1-level-object (with key paths) * @example {a: {b: [{c: 1}, {c: 2}]}, e: 3} -> {"a.b[0].c": 1, "a.b[1].c": 2, "e": 3} */ export declare function flattenObjectToPost(object?: any, initialPathPrefix?: string): any; /** * Flatten the object into 1-level-object (with key paths) * @example {a: {b: [{c: 1}, {c: 2}]}, e: 3} -> {"a.b.0.c": 1, "a.b.1.c": 2, "e": 3} */ export declare function flattenObjectPaths(object?: any, initialPathPrefix?: string): any; type SaveOpts = { /** * Absolute path to project directory */ directory?: string; /** * Set to `TRUE` will create new `dx.json` file if not existed. */ create?: boolean; ignoreIfNotExisted?: boolean; }; /** * Get object of project configuration from "dx.json" * @param {String} [directory] - Absolute path to project directory */ export declare const getAppConfig: (directory?: string) => AppConfig; /** * Save object of project configuration to "dx.json" * @param {Object} appConfig - Object data of the config * @param {SaveOpts} [options] - Save options * @param {String} [options.directory] - Absolute path to project directory @default process.cwd() * @param {Boolean} [options.create] - TRUE will create new file if not existed. @default false */ export declare const saveAppConfig: (appConfig: AppConfig, options?: SaveOpts) => AppConfig; /** * Update values of app config ("dx.json") * @param updatedData - updated data */ export declare const updateAppConfig: (updatedData: AppConfig, options?: SaveOpts) => AppConfig; /** * Get object of project configuration from "../../package.json" * @param {Object} [options] - Options * @param {String} [options.directory] - Absolute path to project directory * @param {Boolean} [options.ignoreIfNotExisted] - TRUE ignore the error if not existed. * @return {Object} */ export declare const getPackageConfig: (options: SaveOpts) => any; /** * Save object of project configuration to "package.json" * @param {Object} _config - Object data of the config * @param {SaveOpts} [options] - Options * @param {String} [options.directory] - Absolute path to project directory * @param {Boolean} [options.create] - TRUE will create new file if not existed. * @param {Boolean} [options.ignoreIfNotExisted] - TRUE ignore the error if not existed. */ export declare const savePackageConfig: (_config: any, options: SaveOpts) => void; /** * Process `npm install` or `yarn install` or `pnpm install` on current directory */ export declare const installPackages: () => Promise<any>; export declare const cloneGitRepo: (repoSSH: string, dir: string, options?: PullOrCloneGitRepoSSHOptions) => Promise<void>; export declare const pullOrCloneGitRepo: (repoSSH: string, dir: string, branch: string, options?: PullOrCloneGitRepoSSHOptions) => Promise<boolean>; /** * Get current remote SSH & URL */ export declare const getCurrentGitRepoData: (dir?: string, options?: { isDebugging: boolean; }) => Promise<{ repoSSH: any; repoURL: any; provider: "bitbucket" | "github"; slug: string; fullSlug: string; namespace: string; gitDomain: string; branch: string; }>; export declare const getGitProviderFromRepoSSH: (repoSSH: string) => GitProviderType; export declare const isUsingExpressjsFramework: (options: any) => boolean; export declare const isUsingNodejsFramework: (options: any) => boolean; export declare const isUsingDiginextFramework: (options: any) => Promise<boolean>; export declare const isUsingDiginestAPIFramework: (options: any) => Promise<boolean>; export declare const isUsingStaticHtmlFramework: (options: any) => Promise<boolean>; /** * Get current using framework of the project. * @return {("unknown"|"diginest"|"diginext"|"nodejs"|"expressjs"|"static")} */ export declare const getCurrentFramework: (options: any) => string; export declare const getImageFromYaml: (docs: any) => string; export declare const getReplicasFromYaml: (docs: any) => number; /** * Completely remove the first / of the string * @param {String} input * @returns {String} */ export declare const trimFirstSlash: (input: any) => any; /** * Convert {Object} to environment variables of Kuberketes container * @param {Object} object - Input raw object, **not containing any methods** */ export declare const objectToKubeEnvVars: (object: any) => KubeEnvironmentVariable[]; /** * Convert {Object} to .env content * @param {Object} object - Input raw object, **not containing any methods** * @returns {String} */ export declare const objectToDotenv: (object: any) => string; /** * Load ENV file (.env.*) and parse to array of K8S container environment variables */ export declare const loadEnvFileAsContainerEnvVars: (filePath: string) => KubeEnvironmentVariable[]; /** * Grab value of Kube ENV variables by name */ export declare const getValueOfKubeEnvVarsByName: (name: string, envVars: KubeEnvironmentVariable[]) => string; /** * Convert K8S container's ENV to .env content * @param {[{name,value}]} inputEnvs - Input raw object, **not containing any methods** * @returns {String} */ export declare const kubeEnvToDotenv: (inputEnvs: KubeEnvironmentVariable[]) => string; export declare const objectToDeploymentYaml: (deploymentCfg: any) => string; export declare const strToArray: (str: any, splitter?: string) => any[]; export declare const getDiginextEnvVars: (env: any, projectSlug: any, domains: any) => { NEXT_PUBLIC_ENV: string; NEXT_PUBLIC_CDN_BASE_PATH: string; NEXT_PUBLIC_BASE_PATH: any; NEXT_PUBLIC_BASE_URL: string; IRON_SESSION_SECRET: string; }; export declare const objToEnv: (obj?: {}) => string; export declare const sequentialExec: (array: any, func: any) => Promise<any>; interface ResolveApplicationFilePathOptions { targetDirectory?: string; env?: string; ignoreIfNotExisted?: boolean; msg?: string; } /** * Resolve a location path of the file within the application. */ export declare const resolveFilePath: (fileNamePrefix: string, options: ResolveApplicationFilePathOptions) => string; /** * Resolve a location path of the "Dockerfile". */ export declare const resolveDockerfilePath: (options: ResolveApplicationFilePathOptions) => string; /** * Resolve a location path of the DOTENV (`.env.*`) file. */ export declare const resolveEnvFilePath: (options: ResolveApplicationFilePathOptions) => string; /** * Execute an command within a Docker container * @deprecated */ export declare const cliContainerExec: (command: any, options: any) => Promise<string | false>; declare function logHelp(options?: InputOptions): Promise<void>; export declare const getIPFromDomain: (domain: any) => Promise<unknown>; export declare const getClusterIP: (options: any) => Promise<any>; export declare const getIngress: (ingName: string, namespace?: string, options?: {}) => Promise<any>; export declare const getIngressEndpoint: (ingName: string, namespace?: string, options?: {}) => Promise<any>; export declare const getIngressIP: (ingName: string, namespace?: string, index?: number, options?: {}) => Promise<any>; export declare const getCurrentDeployment: (deployName: string, namespace?: string, options?: {}) => Promise<any>; export declare const getCurrentImageName: (deployName: string, namespace?: string, options?: {}) => Promise<any>; export declare const getCurrentContainerEnvs: (deployName: string, namespace?: string, options?: {}) => Promise<any>; export { logBitbucket, logBitbucketError, logHelp, toBase64, wait }; export declare const extractWorkspaceSlugFromUrl: (url: string) => string; export declare const extractWorkspaceIdFromUser: (user: IUser) => string; export declare function getUnexpiredAccessToken(access_token: string): AccessTokenInfo; export declare const generateWorkspaceApiAccessToken: () => { name: `${string}-${string}-${string}-${string}-${string}`; value: string; }; //# sourceMappingURL=utils.d.ts.map