Skip to content

Commit 5122395

Browse files
committed
1.2.2
- Add support for 1.18-experimental and combat tests
1 parent a380eca commit 5122395

File tree

10 files changed

+80
-35
lines changed

10 files changed

+80
-35
lines changed

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI Testing
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [16.x, 14.x, 12.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Test Node.js v${{ matrix.node-version }}
20+
uses: actions/setup-node@v2
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: npm ci
24+
- run: npm test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
*.js
33
*.d.ts
4+
!bin/*

bin/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('../src/cli.js');

changelog.md

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

3+
## 1.2.2
4+
*2021-07-23*
5+
- Added support for Combat Test snapshots.
6+
- Updated to support 1.18 experimental snapshots.
7+
38
## 1.2.1
49
*2021-04-06*
510
- Added constant `LATEST` which returns the latest `pack_format` for both resource and data pack formats.

package-lock.json

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

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "pack-format",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Returns the pack_format of any Minecraft version, including snapshots",
55
"scripts": {
66
"prepublish": "tsc",
7-
"test": "node test"
7+
"test": "tsc && node test/test"
88
},
99
"keywords": [
1010
"minecraft",
@@ -14,9 +14,10 @@
1414
],
1515
"main": "src/index.js",
1616
"bin": {
17-
"pack-format": "src/cli.js"
17+
"pack-format": "bin/index.js"
1818
},
1919
"files": [
20+
"bin/*.js",
2021
"src/*.js",
2122
"src/*.d.ts"
2223
],
@@ -30,7 +31,7 @@
3031
},
3132
"license": "ISC",
3233
"devDependencies": {
33-
"@types/node": "^14.14.31",
34-
"typescript": "~4.2.3"
34+
"@types/node": "ts4.3",
35+
"typescript": "~4.3.5"
3536
}
3637
}

src/cli.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#!/usr/bin/env node
2-
3-
const VERSION: string = '1.2.1'
4-
51
import { getPackFormat, getVersions, LATEST } from './index'
2+
const VERSION: string = require('../package.json').version
63

74
const arg = (n: number): string => process.argv[n + 1]
85
const indent = (n: number): string => ' '.repeat(n * 4)

src/index.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@ class Snapshot {
88
get id(): number { return (this.year - 10) * 52 + this.week }
99
}
1010

11+
const LATEST = { resource: 7, data: 7 }
12+
1113
const RELEASES: Record<number, VersionName[]> = {
1214
1: ['1.6.x', '1.7.x', '1.8.x'],
1315
2: ['1.9.x', '1.10.x'],
1416
3: ['1.11.x', '1.12.x'],
1517
4: ['1.13.x', '1.14.x'],
1618
5: ['1.15.x', '1.16.0', '1.16.1'],
1719
6: ['1.16.x'],
18-
7: ['1.17.x'],
20+
7: ['1.17.x', '1.18.0'],
21+
}
22+
23+
const SPECIAL: Record<number, string[]> = {
24+
4: ['combat1', 'combat2', 'combat3'],
25+
5: ['combat4', 'combat5'],
26+
6: ['combat6', 'combat7a', 'combat7b', 'combat8a', 'combat8b', 'combat8c'],
1927
}
2028

21-
const d = new Date()
22-
const fauxCurrentSnapshot = (d.getFullYear() - 2000) + 'w' + ((d.getMonth() + 1) * 5).toString().padStart(2, '0') + 'a' as SnapshotName
23-
const START_SNAPSHOTS: Record<SnapshotName | string, Record<PackType, FormatResult>> = {
29+
const d = new Date(), year = d.getFullYear() - 2000, maxWeek = (d.getMonth() + 1) * 5
30+
const fauxCurrentSnapshot: SnapshotName = `${year}w${maxWeek.toString().padStart(2, '0')}a`
31+
const START_SNAPSHOTS: Record<SnapshotName, Record<PackType, FormatResult>> = {
2432
'13w24a': { resource: 1, data: undefined },
2533
'15w31a': { resource: 2, data: undefined },
2634
'16w32a': { resource: 3, data: undefined },
@@ -31,19 +39,23 @@ const START_SNAPSHOTS: Record<SnapshotName | string, Record<PackType, FormatResu
3139
[fauxCurrentSnapshot]: { resource: undefined, data: undefined },
3240
}
3341

34-
const LATEST = { resource: 7, data: 7 }
35-
3642
function getPackFormat(version: string, type: PackType = 'resource'): FormatResult {
3743
if (!version) return undefined
3844
version = version.toString().toLowerCase().trim()
3945

46+
// Special //
47+
for (const format in SPECIAL) {
48+
if (SPECIAL[format].includes(version)) return +format;
49+
}
50+
4051
// Snapshot //
4152

4253
if (/^\d\d[w]\d\d[a-z]$/.test(version)) {
4354
const snapshot = new Snapshot(version)
4455
let ver: FormatResult
45-
for (let testSnap of Object.keys(START_SNAPSHOTS)) {
56+
for (const testSnap in START_SNAPSHOTS) {
4657
if (snapshot.id >= (new Snapshot(testSnap)).id) {
58+
// @ts-ignore: #45159
4759
ver = START_SNAPSHOTS[testSnap][type]
4860
}
4961
}
@@ -58,14 +70,14 @@ function getPackFormat(version: string, type: PackType = 'resource'): FormatResu
5870
if (version.includes('1.16.2-pre')) return 5
5971
else version = version.replace(/-.+$/, '')
6072
}
61-
if (version.match(/^\d+\.\d+$/)) version += '.0'
73+
if (/^\d+\.\d+$/.test(version)) version += '.0'
6274

63-
for (let i in RELEASES) {
64-
if (+i < 4 && type === 'data') continue
65-
for (let testVer of RELEASES[i]) {
75+
for (const format in RELEASES) {
76+
if (+format < 4 && type === 'data') continue
77+
for (let testVer of RELEASES[format]) {
6678
const matchExact = testVer === version
6779
const matchMinor = testVer.includes('x') && version.includes(testVer.replace('.x', ''))
68-
if (matchExact || matchMinor) return +i
80+
if (matchExact || matchMinor) return +format
6981
}
7082
}
7183

@@ -84,6 +96,7 @@ function getVersions(format: number, type: PackType = 'resource'): VersionsResul
8496

8597
const startSnaps: string[] = Object.keys(START_SNAPSHOTS)
8698
for (const snap in START_SNAPSHOTS) {
99+
// @ts-ignore: #45159
87100
if (START_SNAPSHOTS[snap][type] === format) {
88101
let maxSnap = snap as SnapshotName
89102
let i = 1

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type VersionName = `1.${number}.${number | 'x'}`
2-
export type SnapshotName = `${number}w${number}${string}`
2+
export type SnapshotName = `${number}w${string}${string}`
33

44
export type PackType = 'resource' | 'data'
55
export type PackMap = Record<PackType, FormatResult>

test/test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function testVersions([input, type]: [number, PackType?], expected: VersionsResu
2323
if (pass) passed++
2424
else failed++
2525
total++
26-
const cleanObj = (obj: VersionsResult) => JSON.stringify(obj).replace(/"(?!")/g, '')
26+
const cleanObj = (obj: VersionsResult) => JSON.stringify(obj).replace(/"([^"]*?)":/g, '$1:')
2727
console.log(
2828
(pass ? ' ' : '! ')
2929
+ `Versions with ${type ? type + ' ' : ''}pack format ${input}: ${cleanObj(obj)}`
@@ -53,9 +53,11 @@ testPackFormat(['20w45a'], 7)
5353
testPackFormat(['20w45a', 'resource'], 7)
5454
testPackFormat(['20w45a', 'data'], 6)
5555
testPackFormat(['20w46a', 'data'], 7)
56+
testPackFormat(['combat3'], 4)
57+
testPackFormat(['1.18-exp1'], 7)
5658

5759
testVersions([3, 'data'], { releases: { min: '', max: '' }, snapshots: { min: '', max: '' } })
5860
testVersions([6, 'resource'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '', max: '' } })
59-
testVersions([7], { releases: { min: '1.17.x', max: '1.17.x' }, snapshots: { min: '20w45a', max: '21w14a' } })
61+
testVersions([6, 'data'], { releases: { min: '1.16.x', max: '1.16.x' }, snapshots: { min: '20w45a', max: '20w45a' } })
6062

6163
console.log(`\nRan ${total} tests | ${passed} passed | ${failed} failed`)

0 commit comments

Comments
 (0)