UNPKG

kratos-core

Version:

kratos-core is an open-source, elegant and battery-included Minecraft Launcher API module written in TypeScript in order to be the based of KratosLauncher

216 lines (215 loc) 7.83 kB
/// <reference types="node" /> /// <reference types="node" /> import { PathLike, WriteStream, WriteFileOptions } from "fs-extra"; import { VersionManifest, VersionPackage } from "./version"; import { version } from "."; export interface WorkspaceInterface { /** * Get the current directory * * @returns the path name of the directory */ getDirectory(): PathLike; /** * Make the sub-directory from current directory and resolve * the full path of generated directory. * * For instance, to make a sub-directory inside current directory, do as follows * ``` * * await makeDirectory(`subDir`); * ``` * * Note: Do not need to join parent directory * * @param path a sub directory path * @returns the full path of generated directory * */ makeDirectory(path: PathLike): Promise<string>; /** * Write a file as current directory, or sub-path. * * * * @param writePath a path to write a file * @param data a content of a file as buffer * @param options write file options * * @returns the generated path of the file */ writeAsFile(writePath: PathLike, data: Buffer, options?: WriteFileOptions): Promise<string>; } export declare class Workspace implements WorkspaceInterface { private readonly directory; constructor(directory: PathLike); getDirectory(): PathLike; makeDirectory(_path: PathLike): Promise<string>; private ensurePath; createWriter(_path: PathLike, options?: BufferEncoding): WriteStream; writeAsFile(writePath: PathLike, data: Buffer, options?: WriteFileOptions): Promise<string>; } export declare class LauncherWorkspace extends Workspace { private readonly assetWorkspace; private readonly versionWorkspace; private readonly libraryWorkspace; constructor(directory: PathLike); getAssetWorkspace(): AssetWorkspace; getVersionWorkspace(): VersionWorkspace; /** * Retrieves the instance of library workspace that initialed at constructor. * * @returns the instance of library workspace. */ getLibraryWorkspace(): LibraryWorkspace; } export declare class AssetWorkspace extends Workspace { private indexesWorkspace; constructor(directory: PathLike); /** * Retrieves sub-directory path for ./<launcher directory>/assets/objects * * @returns a path of sub-directory */ getObjectsPath(): string; /** * Creates a write stream using assets file path format. * An asset file is stored in `/<first 2 letter of hash>/<full hash>`. * * @param hash an asset hash property to set file name * @param options an options for create a write stream * @returns a writable stream from {@link createWriteStream} */ createAssetWriter(hash: string, options?: BufferEncoding): WriteStream; /** * Retrieves the instance of asset indexes workspace. * * Asset indexes workspace represents `assets/indexes` directory * in minecraft launcher. It contains all asset indexes (mapping) data * for the game to determine which asset must be used for the game. * * @returns the instance of asset indexes workspace */ getAssetIndexesWorkspace(): AssetIndexWorkspace; } export declare class VersionWorkspace extends Workspace { constructor(directory: PathLike); /** * Makes the version_manifest_v2.json file path from {@link LauncherWorkspace} * as a parent directory. * * @returns a relative manifest path from launcher workspace. */ getManifestPath(): string; /** * Checks whether or not the version_manifest_v2.json file is exists. * * @returns true if the version manifest file was exists, false otherwise. */ existsManifest(): Promise<boolean>; /** * Write a manifest file. * * @param buffer content to write into a file. * @param options a write file options, see {@link WriteFileOptions} * @returns a destination as path of the written file. * In this case is the full path of version_manifest_v2.json file. */ writeManifest(buffer: Buffer, options?: WriteFileOptions): Promise<string>; /** * Reads the version_manifest_v2.json and returns it. * * Either the manifest file is not found, * or the json file is invalid, an error will be throws. * * @returns the version manifest file as an object. */ readManifest(): Promise<VersionManifest>; /** * Makes a package directory path from directory. * @returns the package directory path, at `<launcher dir workspace>/versions/packages`. */ getPackageDirectory(): Promise<string>; private getPackageVersionFilePath; /** * Checks if the version package was stored in package directory. * * @param versionId the minecraft package version id. * @returns true if exists, false otherwise. */ hasPackageVersion(versionId: string): Promise<boolean>; /** * Writes a version package file. * * @param versionId the package version id * @param buffer the buffer to write * @param options an options for writing file, see {@link WriteFileOptions} */ writeVersionPackage(versionId: string, buffer: Buffer, options?: WriteFileOptions): Promise<void>; /** * Reads the version packages as JSON file. * * If the file was not found, an error will be thrown * * @param versionId the package version id * @returns the package version as json */ readVersionPackage(versionId: string): Promise<VersionPackage>; } declare class LibraryWorkspace extends Workspace { constructor(directory: PathLike); /** * Ensures the dirname of the library path to not be exists. * * For examples, if the library pathname is /a/b/c/d.jar, * the function will make a directory `/libraries/a/b/c` if * is not exists. Otherwise, silently do nothing. * * * @param pathname the path of library to ensure a directory */ ensureDirname(pathname: string): void; } declare class AssetIndexWorkspace extends Workspace { constructor(__: string); /** * * NOTE that the file name does not include any extension * * @param indexId * @returns */ getIndexFilePath(indexId: string): string; /** * Finds and retrieves if the asset index of the file from `assets/indexes` is exists. * Otherwise, an Error will be thrown. * * @param indexId the version asset index id, mostly from package info. * @returns the asset index object parsed locally on disk. */ getIndex(indexId: string): any; /** * Writes an asset index file into `assets/indexes/{indexId}`. * The file will be overwritten if it exists. * * @param indexId the version asset index id, mostly from package info. * @param assetIndex the asset index to write over the local disk file. */ writeIndex(indexId: string, assetIndex: version.AssetIndex): void; /** * Checks whether or not the index file is available on `assets/indexes/{indexId}`. * * @param indexId the version asset index id, mostly from package info. * @returns true if the file is exists, false otherwise. */ hasIndex(indexId: string): boolean; /** * Reveals all indexes file available on `assets/indexes/{indexId}`. * The `ignoreFiles` parameter works by using includes string function of JavaScript. * * @param ignoreFiles the filter to eliminate unnecessary files, as an array. * @returns the list of file name which was available on `assets/indexes/{indexId}` */ getAllIndexes(ignoreFiles?: string[]): string[]; } export {};