Skip to content

Commit 1a2739f

Browse files
committed
1.2.4
- Update `LATEST` to `8` - Revamp CLI
1 parent a03eceb commit 1a2739f

File tree

6 files changed

+77
-25
lines changed

6 files changed

+77
-25
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+
## 1.2.4
4+
- Updated `LATEST` pack formats to `8`.
5+
- Changed CLI argument parsing to no longer require a fixed argument order.
6+
37
## 1.2.3
48
*2021-09-16*
59
- Updated to support 1.18 snapshots.

package-lock.json

Lines changed: 31 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pack-format",
3-
"version": "1.2.3",
3+
"version": "1.2.4",
44
"description": "Returns the pack_format of any Minecraft version, including snapshots",
55
"scripts": {
66
"prepublish": "tsc",
@@ -34,8 +34,12 @@
3434
"url": "https://github.com/Nixinova/pack-format/issues"
3535
},
3636
"license": "ISC",
37+
"dependencies": {
38+
"yargs-parser": "^20.2.9"
39+
},
3740
"devDependencies": {
3841
"@types/node": "ts4.4",
42+
"@types/yargs-parser": "ts4.4",
3943
"typescript": "~4.4.3"
4044
}
4145
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const packFormat = require('pack-format')
2929
packFormat('1.14.4') // 4
3030
packFormat('1.16.2-pre1', 'resource') // 5
3131
packFormat('20w45a', 'data') // 6
32-
packFormat.LATEST.data // 7
32+
packFormat.LATEST.data // 8
3333
```
3434

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

src/cli.ts

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import yargs from 'yargs-parser';
2+
13
import { getPackFormat, getVersions, LATEST } from './index'
24
import { version as VERSION } from '../package.json';
35

4-
const arg = (n: number): string => process.argv[n + 1]
56
const indent = (n: number): string => ' '.repeat(n * 4)
67
const log = function (arg: string, desc: string[], example: string): void {
78
console.log(`\n${indent(2)}pack-format ${arg}`)
@@ -10,33 +11,47 @@ const log = function (arg: string, desc: string[], example: string): void {
1011
console.log(`${indent(3)}Example: ${example}`)
1112
}
1213

13-
if (arg(1) && !arg(1).includes('h')) {
14-
const cmd = arg(1)
15-
if (/^-*v/.test(cmd)) {
16-
console.log(`The current version of pack-format is ${VERSION}`)
14+
const argOpts: yargs.Options = {
15+
alias: {
16+
help: ['h'],
17+
version: ['v'],
18+
resource: ['r'],
19+
data: ['d'],
20+
list: ['l'],
21+
latest: ['L'],
22+
},
23+
boolean: ['help', 'version', 'resource', 'data', 'list', 'latest'],
24+
}
25+
const args = yargs(process.argv.slice(2), argOpts)
26+
const ver = args._[0];
27+
28+
if (ver) {
29+
if (args.version) {
30+
console.log(`pack-format v${VERSION}`)
31+
}
32+
else if (args.list) {
33+
console.debug(ver, args)
34+
if (Number.isNaN(ver)) throw new Error(`'${ver}' is not a valid pack format`)
35+
if (Math.round(+ver) !== +ver) throw new Error(`'${ver}' is a version number, not a pack format`)
36+
const type = args.data ? 'data' : 'resource'
37+
console.log(getVersions(+ver, type))
1738
}
18-
else if (/^-*d/.test(cmd)) {
19-
const ver = arg(2)
39+
else if (args.data) {
2040
console.log(`Data pack format of ${ver} is ${getPackFormat(ver, 'data')}`)
2141
}
22-
else if (/^-*r/.test(cmd)) {
23-
const ver = arg(2)
42+
else if (args.resource) {
2443
console.log(`Resource pack format of ${ver} is ${getPackFormat(ver, 'resource')}`)
2544
}
26-
else if (/^-*l/.test(cmd)) {
27-
if (arg(3)) console.log(getVersions(+arg(3), /^-*d/.test(arg(2)) ? 'data' : 'resource'))
28-
else console.log(getVersions(+arg(2)))
29-
}
30-
else if (/^-*L/.test(cmd)) {
31-
const type = /^-*d/.test(arg(2)) ? 'data' : 'resource'
32-
if (arg(2)) console.log(`The latest ${type} pack version is ${LATEST[type]}.`)
33-
else console.log(`The latest pack version is ${LATEST.resource}.`)
34-
}
3545
else {
36-
console.log(`Pack format of ${cmd} is ${getPackFormat(cmd)}`)
46+
console.log(`Pack format of ${ver} is ${getPackFormat(ver)}`)
3747
}
3848
}
39-
else {
49+
else if (args.latest) {
50+
const type = args.data ? 'data' : args.resource ? 'resource' : ''
51+
if (type) console.log(`The latest ${type} pack version is ${LATEST[type]}.`)
52+
else console.log(`The latest pack version is ${LATEST.resource}.`)
53+
}
54+
if (args.help) {
4055
console.log(`\n${indent(1)}pack-format arguments:`)
4156
log(
4257
'<version>',

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Snapshot {
88
get id(): number { return (this.year - 10) * 52 + this.week }
99
}
1010

11-
const LATEST = { resource: 7, data: 7 }
11+
const LATEST = { resource: 8, data: 8 }
1212

1313
const RELEASES: Record<number, VersionName[]> = {
1414
1: ['1.6.x', '1.7.x', '1.8.x'],

0 commit comments

Comments
 (0)