@stackbit/sdk
Version:
91 lines • 3.57 kB
TypeScript
export declare const EXCLUDED_LIST_FILES: string[];
export interface FileResult {
filePath: string;
isFile: boolean;
isDirectory: boolean;
}
export interface ListFilesOptions {
includePattern?: string | string[];
excludePattern?: string | string[];
}
export interface FileBrowserAdapterInterface {
listFiles(listFilesOptions: ListFilesOptions): Promise<FileResult[]>;
readFile(filePath: string): Promise<string>;
}
export interface FileSystemFileBrowserAdapterOptions {
dirPath: string;
}
export declare class FileSystemFileBrowserAdapter implements FileBrowserAdapterInterface {
private readonly dirPath;
constructor({ dirPath }: FileSystemFileBrowserAdapterOptions);
listFiles({ includePattern, excludePattern }: ListFilesOptions): Promise<FileResult[]>;
readFile(filePath: string): Promise<string>;
}
export interface GitHubFileBrowserAdapterBaseOptions {
branch: string;
auth?: string;
}
export interface GitHubFileBrowserAdapterOwnerRepoOptions {
owner: string;
repo: string;
}
export interface GitHubFileBrowserAdapterRepoUrlOptions {
repoUrl: string;
}
export type GitHubFileBrowserAdapterOptions = GitHubFileBrowserAdapterBaseOptions & (GitHubFileBrowserAdapterRepoUrlOptions | GitHubFileBrowserAdapterOwnerRepoOptions);
interface OctokitTreeNode {
path?: string;
mode?: string;
type?: string;
sha?: string;
size?: number;
url?: string;
}
export declare class GitHubFileBrowserAdapter implements FileBrowserAdapterInterface {
private readonly octokit;
private readonly owner;
private readonly repo;
private readonly branch;
constructor(options: GitHubFileBrowserAdapterBaseOptions & GitHubFileBrowserAdapterRepoUrlOptions);
constructor(options: GitHubFileBrowserAdapterBaseOptions & GitHubFileBrowserAdapterOwnerRepoOptions);
listFiles(listFilesOptions: ListFilesOptions): Promise<FileResult[]>;
listFilesRecursively(treeSha: string, listFilesOptions: ListFilesOptions, parentPath: string): Promise<OctokitTreeNode[]>;
readFile(filePath: string): Promise<string>;
parseGitHubUrl(repoUrl: string): GitHubFileBrowserAdapterOwnerRepoOptions | null;
}
export type GetFileBrowserOptions = {
fileBrowser: FileBrowser;
} | {
fileBrowserAdapter: FileBrowserAdapterInterface;
};
export declare function getFileBrowserFromOptions(options: GetFileBrowserOptions): FileBrowser;
export interface FileBrowserOptions {
fileBrowserAdapter: FileBrowserAdapterInterface;
}
export declare class FileBrowser {
private readonly fileBrowserAdapter;
private readonly filePathMap;
private readonly directoryPathsMap;
private readonly filePathsByFileName;
private readonly fileData;
private readonly filePaths;
private readonly fileTree;
private files;
constructor({ fileBrowserAdapter }: FileBrowserOptions);
listFiles({ includePattern, excludePattern }?: {
includePattern?: string | string[];
excludePattern?: string | string[];
}): Promise<void>;
filePathExists(filePath: string): boolean;
fileNameExists(fileName: string): boolean;
getFilePathsForFileName(fileName: string): string[];
directoryPathExists(dirPath: string): boolean;
findFiles(pattern: string | string[]): string[];
readFilesRecursively(dirPath: string, { filter, includeDirs }: {
filter?: (fileResult: FileResult) => boolean;
includeDirs?: boolean;
}): string[];
getFileData(filePath: string): Promise<any>;
}
export {};
//# sourceMappingURL=file-browser.d.ts.map