Skip to content

Commit 45b2f79

Browse files
committed
Add getPackFormats function
1 parent f3b1533 commit 45b2f79

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Next
4+
- Added function `getPackFormats(version: string): object` to retrieve both the resource and data pack formats of a given version.
5+
- Changed the default CLI command to show both pack formats if the type is unspecified instead of defaulting to the resource pack format.
6+
37
## 1.2.8
48
*2021-10-03*
59
- Changed CLI arguments `--help` and `--version` to override other arguments.

src/cli.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getPackFormat, getVersions, LATEST } from './index'
2-
const VERSION = require('../package.json').version;
1+
import { getPackFormat, getPackFormats, getVersions, LATEST } from './index'
2+
const VERSION = require('../package.json').version
33

44
const indent = (n: number): string => ' '.repeat(n * 4)
55
const log = function (arg: string, desc: string[], example: string): void {
@@ -33,9 +33,12 @@ if (ver) {
3333
else if (args.data) {
3434
console.log(`Data pack format of ${ver} is ${getPackFormat(ver, 'data')}`)
3535
}
36-
else {
36+
else if (args.resource) {
3737
console.log(`Resource pack format of ${ver} is ${getPackFormat(ver, 'resource')}`)
3838
}
39+
else {
40+
console.log(`Pack formats for ${ver} are`, getPackFormats(ver))
41+
}
3942
}
4043
else if (args.latest) {
4144
const type = args.data ? 'data' : args.resource ? 'resource' : ''
@@ -49,7 +52,7 @@ if (args.help) {
4952
console.log(`\n${indent(1)}pack-format arguments:`)
5053
log(
5154
'<version>',
52-
['Retrieve the pack format of any Minecraft version.', 'Defaults to resource pack format when applicable.'],
55+
['Retrieve the resource and data pack formats of any Minecraft version.'],
5356
'pack-format 1.16',
5457
)
5558
log(

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ function getPackFormat(version: string, type: PackType = 'resource'): FormatResu
9090
return undefined
9191
}
9292

93+
/**
94+
* @param version the version to look up
95+
* @returns an object containing the resource and data pack formats for a given version
96+
*/
97+
function getPackFormats(version: string): Record<PackType, FormatResult> {
98+
const resource = getPackFormat(version, 'resource')
99+
const data = getPackFormat(version, 'data')
100+
return { resource, data }
101+
}
102+
93103
/**
94104
* Retrieve a list of applicable versions for a given pack format
95105
* @param format the pack format to look up
@@ -129,6 +139,7 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul
129139
}
130140

131141
getPackFormat.getPackFormat = getPackFormat
142+
getPackFormat.getPackFormats = getPackFormats
132143
getPackFormat.getVersions = getVersions
133144
getPackFormat.LATEST = LATEST
134145

0 commit comments

Comments
 (0)