/** * The main class * @module */ /// import * as tar from 'tar'; export type Typo = [original: string, correction: string]; export interface ListItem { filePath: string; conflict: boolean; } export interface GithubExtractorOptions { /** * E.g. "octocat" in https://github.com/octocat/Spoon-Knife */ owner: string; /** * E.g. "Spoon-Knife" in https://github.com/octocat/Spoon-Knife */ repo: string; /** * The github repo branch to get. Defaults to main then master. */ branch?: string; /** * Whether to ignore casing in paths. Default is false so SomePath/someFile.js will be * different to SOMEPATH/somefile.js. * @default false */ caseInsensitive?: boolean; } export interface ListStreamOptions { /** * The stream to write the repo paths to for visual output as the list is being created. * by default it will write to the console. * @default process.stdout */ outputStream?: NodeJS.WritableStream; /** * Whether to use ascii escape characters to highlight conflicts when writing to the * outputStream. * @default true */ highlightConflicts?: boolean; /** * A prefix to add to output. Default is nothing. */ prefix?: string; /** * Suffix to add to the output. Defaults to a new line */ suffix?: string; } export interface ListOptions { /** * The destination directory for the repo's files. Used to detect conflicts * and must be set if any conflict option is set. */ dest?: string; /** * Only list repo files in conflict with dest * @default false */ conflictsOnly?: boolean; /** * Options for the stream to write the repo paths to for visual output as the list is being created. By default it writes to the console. */ streamOptions?: ListStreamOptions; /** * Must match every regular expression if given. */ match?: RegExp; } export interface DownloadToOptions { /** * Destination to download the files into. Warning: it will overwrite any existing files * by default unless extractOptions are set. */ dest: string; /** * Will only download these paths. * @example * ["README.md", ".github/workflows/ci.yml"] */ selectedPaths?: string[]; /** * Must match every regular expression if given. If {@link selectedPaths} is given, it * will operate on selected only. */ match?: RegExp; /** * Pass through options for the tar.extract stream. Not very important * but here for completeness. See {@link ExtractOptions} */ extractOptions?: any; /** * Callback for when a file is written. Useful for logging or other operations. */ onFileWritten?: (entry: tar.ReadEntry) => void; } /** * The main class */ export declare class GithubExtractor { branch: GithubExtractorOptions["branch"]; caseInsensitive: GithubExtractorOptions["caseInsensitive"]; owner: GithubExtractorOptions["owner"]; repo: GithubExtractorOptions["repo"]; protected debug: boolean; private requestFn; /** * @param options - Main class constructor options. */ constructor({ owner, repo, caseInsensitive, branch }: GithubExtractorOptions); protected stripRepoName(tarPath: string): string; protected normalizeTarPath(tarPath: string): string; protected normalizeFilePath(filePath: string): string; protected normalizePathSet(filePathSet: Set): Set; protected handleBadResponseCode(res: Awaited>): Promise; protected makeRequest(url: string): Promise<{ statusCode: number; headers: import("undici/types/header.js").IncomingHttpHeaders; body: import("undici/types/readable.js").default & import("undici").Dispatcher.BodyMixin; controller: AbortController; url: string; }>; protected getTarBody(): Promise<{ statusCode: number; headers: import("undici/types/header.js").IncomingHttpHeaders; body: import("undici/types/readable.js").default & import("undici").Dispatcher.BodyMixin; controller: AbortController; url: string; }>; protected handleTypos({ pathList, selectedSet }: { pathList: string[]; selectedSet: Set; }): Typo[]; /** * Download a repo to a certain location (`dest`) * * @param options * * @returns - An empty array if all `selectedPaths` were found / there were no `selectedPaths` * given OR an array of possible typos if some of the `selectedPaths` were not found. * * @example * * Basic usage: * ```typescript * await ghe.downloadTo({ dest: "some/path" }); * ``` * To only download some paths: \ * Do not prefix path with repo name. It will stop downloading once it has the file * (this can make getting a single file from a large repo very fast). * * ```typescript * // Save just `boo.jpg`: * await ghe.downloadTo({ dest: "some/path", selectedPaths: ["someFolder/boo.jpg"] }); * * // just the `README.md` file: * await ghe.downloadTo({ dest: "some/path", selectedPaths: ["README.md"] }); * * ``` */ downloadTo({ dest, selectedPaths, extractOptions, match, onFileWritten }: DownloadToOptions): Promise; /** * Get a set of the contents of a directory, sorted using using string.localeCompare (with * directories listed first). * all paths are converted to posix and are relative to the given dir. * @param dir * @param recursive - default true * @returns */ getLocalDirSet(dir: string, recursive?: boolean): Promise>; protected writeListStream({ listItem, streamOptions: { outputStream, highlightConflicts, prefix, suffix, }, }: { listItem: ListItem; streamOptions: ListStreamOptions; }): void; /** * Returns a list of files in the repo and writes to (by default) stdout (console.log). Supply * an object with options to change defaults. * * @param options * * @example * ```typescript * const fullList = await ghe.list(); * * // List a repo non recursively to only show the top-level items: * const topLevel = await ghe.list({ recursive: false }); * * // Show any conflicts that might arise if downloading to `dest`: * const conflicts = await ghe.list({ dest: "some/path", conflictsOnly: true }); * * ``` */ list({ dest, conflictsOnly, streamOptions, match }?: ListOptions): Promise; } //# sourceMappingURL=GithubExtractor.d.mts.map