Skip to content

Commit 181d2df

Browse files
committed
Add version & snapshot to LATEST
1 parent 03050a3 commit 181d2df

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Next
4+
- Added `release` and `snapshot` to exported object `LATEST` which denotes the latest known released versions.
45
- Added basic message when no arguments are given.
56
- Changed output of `getVersions` to return `null` instead of `''` when a version is not present.
67
- Changed output of `getVersions` to replace '`.x`' with the actual game version.

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const packFormat = require('pack-format')
3131
packFormat('1.14.4') // 4
3232
packFormat('1.16.2-pre1', 'resource') // 5
3333
packFormat('20w45a', 'data') // 6
34-
packFormat.LATEST.data // 39
34+
packFormat.LATEST.data // 58
35+
packFormat.LATEST.version // 1.21.2
3536
```
3637

3738
Retrieve a list of versions corresponding to a specific `pack_format`, again optionally specifying resource/data pack version.

src/cli.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { FormatResult } from './types'
33
const VERSION = require('../package.json').version
44

55
const indent = (n: number): string => ' '.repeat(n * 4)
6-
const log = function (arg: string, desc: string[], example: string): void {
7-
console.log(`\n${indent(1)}pack-format ${arg}`)
6+
const log = function ([argFull, argShort]: string[], desc: string[], example: string): void {
7+
console.log('\n')
8+
console.log(`${indent(1)}${argFull}`)
9+
if (argShort)
10+
console.log(`${indent(1)}${argShort}`)
811
for (let i in desc)
912
console.log(indent(2) + desc[i])
1013
console.log(`${indent(3)}Example: ${example}`)
@@ -25,28 +28,42 @@ const ver = args._[0]
2528
// Print the help message
2629
if (args.help) {
2730
log(
28-
'<version>',
31+
[
32+
'<version>',
33+
],
2934
['Retrieve the resource and data pack formats of any Minecraft version.'],
3035
'pack-format 1.16',
3136
)
3237
log(
33-
'(--data|-d) <version>',
38+
[
39+
'--data <version>',
40+
'-d <version>',
41+
],
3442
['Retrieve the data pack format only of the version.'],
3543
'pack-format --data 20w45a',
3644
)
3745
log(
38-
'(--resource|-r) <version>',
46+
[
47+
'--resource <version>',
48+
'-r <version>',
49+
],
3950
['Retrieve the resource pack format only of the version.'],
4051
'pack-format --resource 20w45a',
4152
)
4253
log(
43-
'(--list|-l) [(--data|-d)|(--resource|-r)] <pack_format>',
54+
[
55+
'--list [--data|--resource] <pack_format>',
56+
'-l [-d|-r] <pack_format>',
57+
],
4458
['Retrieve a list of versions attached to a specific pack format.', 'Defaults to --resource.'],
4559
'pack-format --list --data 6',
4660
)
4761
log(
48-
'(--latest|-L) [(--data|-d)|(--resource|-r)]',
49-
['Retrieve the latest pack formats.'],
62+
[
63+
'--latest [--data|--resource]',
64+
'-L [-d|-r]',
65+
],
66+
['Retrieve the latest pack formats or version information.'],
5067
'pack-format --latest --resource',
5168
)
5269
}
@@ -90,6 +107,7 @@ else if (args.latest) {
90107
if (!args.data) {
91108
console.log(`The latest resource pack format version is ${LATEST.resource}.`)
92109
}
110+
console.log(`Data is known up to release ${LATEST.version} / snapshot ${LATEST.snapshot}.`)
93111
}
94112
// Print the pack format of a given version
95113
else if (ver) {

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,18 @@ const SPECIAL: Record<PackType, Record<number, string[]>> = {
123123
},
124124
}
125125

126+
// Find latest release & snapshot version (the one before the placeholder version that has data 'undefined')
127+
const LATEST_REL = Object.keys(START_RELEASES).reverse().find(ver => !!START_RELEASES[ver as VersionName].data)
128+
const LATEST_SNAP = Object.keys(START_SNAPSHOTS).reverse().find(ver => !!START_SNAPSHOTS[ver as VersionName].data)
129+
126130
const maxFormat = (type: 'resource' | 'data') => Math.max(...Object.values(START_SNAPSHOTS).map(release => release[type] ?? 0));
127-
const LATEST = { resource: maxFormat('resource'), data: maxFormat('data') };
131+
132+
const LATEST = {
133+
resource: maxFormat('resource'),
134+
data: maxFormat('data'),
135+
version: LATEST_REL,
136+
snapshot: LATEST_SNAP,
137+
}
128138

129139
/**
130140
* @param version the version to look up

0 commit comments

Comments
 (0)