diff --git a/docs/parser/README.md b/docs/parser/README.md index 15ed179..af6f816 100644 --- a/docs/parser/README.md +++ b/docs/parser/README.md @@ -14,7 +14,6 @@ ## Interfaces - [Metafile](interfaces/Metafile.md) -- [Option](interfaces/Option.md) - [PackwizIndex](interfaces/PackwizIndex.md) - [PackwizVersions](interfaces/PackwizVersions.md) diff --git a/docs/parser/classes/IndexFileEntry.md b/docs/parser/classes/IndexFileEntry.md index 7ea4059..61c02ac 100644 --- a/docs/parser/classes/IndexFileEntry.md +++ b/docs/parser/classes/IndexFileEntry.md @@ -6,7 +6,7 @@ # Class: IndexFileEntry -Defined in: parser.ts:30 +Defined in: parser.ts:29 Represents a file entry in the Packwiz index. @@ -16,7 +16,9 @@ Represents a file entry in the Packwiz index. > **new IndexFileEntry**(`file`, `hash`, `hashFormat`, `alias`?, `metafile`?, `preserve`?): [`IndexFileEntry`](IndexFileEntry.md) -Defined in: parser.ts:31 +Defined in: parser.ts:39 + +Creates a new IndexFileEntry instance. #### Parameters @@ -24,26 +26,38 @@ Defined in: parser.ts:31 [`Resource`](../../resource/classes/Resource.md) +The Resource instance representing the file. + ##### hash `string` +The hash of the file. + ##### hashFormat [`HashFormat`](../../enums/hash-format/enumerations/HashFormat.md) +The format of the hash. + ##### alias? `string` +An optional alias for the file that will be downloaded by this file. + ##### metafile? `boolean` = `false` +Whether the file is a metafile. + ##### preserve? `boolean` = `false` +Whether to preserve the file downloaded by this file if it is modified by an end user. + #### Returns [`IndexFileEntry`](IndexFileEntry.md) @@ -54,7 +68,9 @@ Defined in: parser.ts:31 > `readonly` `optional` **alias**: `string` -Defined in: parser.ts:35 +Defined in: parser.ts:43 + +An optional alias for the file that will be downloaded by this file. *** @@ -62,7 +78,9 @@ Defined in: parser.ts:35 > `readonly` **file**: [`Resource`](../../resource/classes/Resource.md) -Defined in: parser.ts:32 +Defined in: parser.ts:40 + +The Resource instance representing the file. *** @@ -70,7 +88,9 @@ Defined in: parser.ts:32 > `readonly` **hash**: `string` -Defined in: parser.ts:33 +Defined in: parser.ts:41 + +The hash of the file. *** @@ -78,7 +98,9 @@ Defined in: parser.ts:33 > `readonly` **hashFormat**: [`HashFormat`](../../enums/hash-format/enumerations/HashFormat.md) -Defined in: parser.ts:34 +Defined in: parser.ts:42 + +The format of the hash. *** @@ -86,7 +108,9 @@ Defined in: parser.ts:34 > `readonly` **metafile**: `boolean` = `false` -Defined in: parser.ts:36 +Defined in: parser.ts:44 + +Whether the file is a metafile. *** @@ -94,7 +118,9 @@ Defined in: parser.ts:36 > `readonly` **preserve**: `boolean` = `false` -Defined in: parser.ts:37 +Defined in: parser.ts:45 + +Whether to preserve the file downloaded by this file if it is modified by an end user. ## Methods @@ -102,8 +128,12 @@ Defined in: parser.ts:37 > **parse**(): `Promise`\<[`Metafile`](../interfaces/Metafile.md)\> -Defined in: parser.ts:47 +Defined in: parser.ts:59 + +Parses the TOML file and returns its contents. #### Returns `Promise`\<[`Metafile`](../interfaces/Metafile.md)\> + +The parsed file as a structured object. diff --git a/docs/parser/classes/Packwiz.md b/docs/parser/classes/Packwiz.md index ea32562..bd91118 100644 --- a/docs/parser/classes/Packwiz.md +++ b/docs/parser/classes/Packwiz.md @@ -6,7 +6,41 @@ # Class: Packwiz -Defined in: parser.ts:130 +Defined in: parser.ts:159 + +A class representing a Packwiz TOML file. + +## Param + +The location of the TOML file. + +## Param + +The index of the TOML file. + +## Param + +The name of the pack. + +## Param + +The packwiz version of the TOML file. + +## Param + +The authors of the pack. + +## Param + +The description of the pack. + +## Param + +The version of the pack. + +## Param + +The Minecraft / modloader versions that the pack uses. ## Constructors @@ -14,7 +48,7 @@ Defined in: parser.ts:130 > **new Packwiz**(`location`, `index`, `name`, `packFormat`, `authors`, `description`, `version`, `versions`): [`Packwiz`](Packwiz.md) -Defined in: parser.ts:131 +Defined in: parser.ts:160 #### Parameters @@ -60,7 +94,7 @@ Defined in: parser.ts:131 > `readonly` **authors**: `string`[] -Defined in: parser.ts:136 +Defined in: parser.ts:165 *** @@ -68,7 +102,7 @@ Defined in: parser.ts:136 > `readonly` **description**: `string` -Defined in: parser.ts:137 +Defined in: parser.ts:166 *** @@ -76,7 +110,7 @@ Defined in: parser.ts:137 > `readonly` **index**: [`PackwizIndex`](../interfaces/PackwizIndex.md) -Defined in: parser.ts:133 +Defined in: parser.ts:162 *** @@ -84,7 +118,7 @@ Defined in: parser.ts:133 > `readonly` **location**: [`Resource`](../../resource/classes/Resource.md) -Defined in: parser.ts:132 +Defined in: parser.ts:161 *** @@ -92,7 +126,7 @@ Defined in: parser.ts:132 > `readonly` **name**: `string` -Defined in: parser.ts:134 +Defined in: parser.ts:163 *** @@ -100,7 +134,7 @@ Defined in: parser.ts:134 > `readonly` **packFormat**: `string` = `"packwiz:1.0.0"` -Defined in: parser.ts:135 +Defined in: parser.ts:164 *** @@ -108,7 +142,7 @@ Defined in: parser.ts:135 > `readonly` **version**: `string` -Defined in: parser.ts:138 +Defined in: parser.ts:167 *** @@ -116,4 +150,4 @@ Defined in: parser.ts:138 > `readonly` **versions**: [`PackwizVersions`](../interfaces/PackwizVersions.md) -Defined in: parser.ts:139 +Defined in: parser.ts:168 diff --git a/docs/parser/functions/parsePackwiz.md b/docs/parser/functions/parsePackwiz.md index 9201e81..0928385 100644 --- a/docs/parser/functions/parsePackwiz.md +++ b/docs/parser/functions/parsePackwiz.md @@ -8,7 +8,7 @@ > **parsePackwiz**(`filePath`): `Promise`\<[`Packwiz`](../classes/Packwiz.md)\> -Defined in: parser.ts:161 +Defined in: parser.ts:190 Parses a packwiz.toml file and returns its contents. diff --git a/docs/parser/interfaces/Metafile.md b/docs/parser/interfaces/Metafile.md index fb87089..8a86d10 100644 --- a/docs/parser/interfaces/Metafile.md +++ b/docs/parser/interfaces/Metafile.md @@ -6,15 +6,41 @@ # Interface: Metafile -Defined in: parser.ts:13 +Defined in: parser.ts:16 + +The structure of a Packwiz metafile. ## Properties +### description? + +> `optional` **description**: `string` + +Defined in: parser.ts:23 + +*** + ### filename > **filename**: `string` -Defined in: parser.ts:15 +Defined in: parser.ts:18 + +*** + +### isDefault + +> **isDefault**: `boolean` + +Defined in: parser.ts:22 + +*** + +### isOptional + +> **isOptional**: `boolean` + +Defined in: parser.ts:21 *** @@ -22,15 +48,7 @@ Defined in: parser.ts:15 > **name**: `string` -Defined in: parser.ts:14 - -*** - -### option - -> **option**: [`Option`](Option.md) - -Defined in: parser.ts:18 +Defined in: parser.ts:17 *** @@ -38,7 +56,7 @@ Defined in: parser.ts:18 > **provider**: [`UrlProvider`](../../provider/classes/UrlProvider.md) -Defined in: parser.ts:17 +Defined in: parser.ts:20 *** @@ -46,4 +64,4 @@ Defined in: parser.ts:17 > **side**: [`Side`](../../enums/side/enumerations/Side.md) -Defined in: parser.ts:16 +Defined in: parser.ts:19 diff --git a/docs/parser/interfaces/Option.md b/docs/parser/interfaces/Option.md deleted file mode 100644 index b46f413..0000000 --- a/docs/parser/interfaces/Option.md +++ /dev/null @@ -1,33 +0,0 @@ -[**packwizjs**](../../README.md) - -*** - -[packwizjs](../../modules.md) / [parser](../README.md) / Option - -# Interface: Option - -Defined in: parser.ts:21 - -## Properties - -### default? - -> `optional` **default**: `boolean` - -Defined in: parser.ts:23 - -*** - -### description? - -> `optional` **description**: `string` - -Defined in: parser.ts:24 - -*** - -### optional - -> **optional**: `boolean` - -Defined in: parser.ts:22 diff --git a/docs/parser/interfaces/PackwizIndex.md b/docs/parser/interfaces/PackwizIndex.md index 694407b..15fe736 100644 --- a/docs/parser/interfaces/PackwizIndex.md +++ b/docs/parser/interfaces/PackwizIndex.md @@ -6,7 +6,7 @@ # Interface: PackwizIndex -Defined in: parser.ts:114 +Defined in: parser.ts:128 Represents the structure of a Packwiz index file, as well as providing its location. @@ -16,7 +16,7 @@ Represents the structure of a Packwiz index file, as well as providing its locat > **files**: [`IndexFileEntry`](../classes/IndexFileEntry.md)[] -Defined in: parser.ts:118 +Defined in: parser.ts:132 *** @@ -24,7 +24,7 @@ Defined in: parser.ts:118 > **hash**: `string` -Defined in: parser.ts:116 +Defined in: parser.ts:130 *** @@ -32,7 +32,7 @@ Defined in: parser.ts:116 > **hashFormat**: [`HashFormat`](../../enums/hash-format/enumerations/HashFormat.md) -Defined in: parser.ts:117 +Defined in: parser.ts:131 *** @@ -40,4 +40,4 @@ Defined in: parser.ts:117 > **location**: [`Resource`](../../resource/classes/Resource.md) -Defined in: parser.ts:115 +Defined in: parser.ts:129 diff --git a/docs/parser/interfaces/PackwizVersions.md b/docs/parser/interfaces/PackwizVersions.md index d5b5f92..84a350a 100644 --- a/docs/parser/interfaces/PackwizVersions.md +++ b/docs/parser/interfaces/PackwizVersions.md @@ -6,7 +6,10 @@ # Interface: PackwizVersions -Defined in: parser.ts:121 +Defined in: parser.ts:139 + +Represents modloaders present in the pack. +If any of these are not undefined, applications using this information should install the specific version of the modlaoder listed. ## Properties @@ -14,7 +17,7 @@ Defined in: parser.ts:121 > `optional` **fabric**: `string` -Defined in: parser.ts:123 +Defined in: parser.ts:141 *** @@ -22,7 +25,7 @@ Defined in: parser.ts:123 > `optional` **forge**: `string` -Defined in: parser.ts:124 +Defined in: parser.ts:142 *** @@ -30,7 +33,7 @@ Defined in: parser.ts:124 > `optional` **liteloader**: `string` -Defined in: parser.ts:127 +Defined in: parser.ts:145 *** @@ -38,7 +41,7 @@ Defined in: parser.ts:127 > **minecraft**: `string` -Defined in: parser.ts:122 +Defined in: parser.ts:140 *** @@ -46,7 +49,7 @@ Defined in: parser.ts:122 > `optional` **neoforge**: `string` -Defined in: parser.ts:125 +Defined in: parser.ts:143 *** @@ -54,4 +57,4 @@ Defined in: parser.ts:125 > `optional` **quilt**: `string` -Defined in: parser.ts:126 +Defined in: parser.ts:144 diff --git a/src/parser.ts b/src/parser.ts index 316ee52..6ce777b 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -10,17 +10,16 @@ import { HashFormat, isValidHashFormat } from "./enums/hash-format"; import { isValidSide, type Side } from "./enums/side"; import * as semver from "semver"; +/** + * The structure of a Packwiz metafile. + */ export interface Metafile { name: string; filename: string; side: Side; provider: UrlProvider; - option: Option; -} - -export interface Option { - optional: boolean; - default?: boolean; + isOptional: boolean; + isDefault: boolean; description?: string; } @@ -28,6 +27,15 @@ export interface Option { * Represents a file entry in the Packwiz index. */ export class IndexFileEntry { + /** + * Creates a new IndexFileEntry instance. + * @param file - The Resource instance representing the file. + * @param hash - The hash of the file. + * @param hashFormat - The format of the hash. + * @param alias - An optional alias for the file that will be downloaded by this file. + * @param metafile - Whether the file is a metafile. + * @param preserve - Whether to preserve the file downloaded by this file if it is modified by an end user. + */ constructor( readonly file: Resource, readonly hash: string, @@ -44,6 +52,10 @@ export class IndexFileEntry { this.preserve = preserve; } + /** + * Parses the TOML file and returns its contents. + * @returns The parsed file as a structured object. + */ async parse(): Promise { if (this.metafile === false) { throw new Error( @@ -59,16 +71,18 @@ export class IndexFileEntry { filename: parsed.filename, side: side, provider: this.parseProvider(parsed), - option: { - optional: parsed.option?.optional || false, - default: parsed.option?.default, - description: parsed.option?.description, - }, + isOptional: parsed.option?.optional || false, + isDefault: parsed.option?.default || true, + description: parsed.option?.description, }; return metafile; } + /** + * Parse the provider from the TOML file. + * @returns The parsed provider. + */ private parseProvider(parsed: any): UrlProvider { if (parsed.update?.modrinth) { return new ModrinthProvider( @@ -118,6 +132,10 @@ export interface PackwizIndex { files: IndexFileEntry[]; } +/** + * Represents modloaders present in the pack. + * If any of these are not undefined, applications using this information should install the specific version of the modlaoder listed. + */ export interface PackwizVersions { minecraft: string; fabric?: string; @@ -127,6 +145,17 @@ export interface PackwizVersions { liteloader?: string; } +/** + * A class representing a Packwiz TOML file. + * @param location - The location of the TOML file. + * @param index - The index of the TOML file. + * @param name - The name of the pack. + * @param packFormat - The packwiz version of the TOML file. + * @param authors - The authors of the pack. + * @param description - The description of the pack. + * @param version - The version of the pack. + * @param versions - The Minecraft / modloader versions that the pack uses. + */ export class Packwiz { constructor( readonly location: Resource,