Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
- Add help command
- Split CLI usage into separate file
- Refactor tests
  • Loading branch information
Nixinova committed Feb 9, 2021
1 parent a67810a commit aba4016
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 25 deletions.
9 changes: 7 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

## 1.0.3
*2021-02-09*
- Added a help message, given by using `pack-format` without any arguments or by using flag `--help`/`-h`.
- Refactored command-line code and tests.

## 1.0.2
*2021-01-23*
- Fixed the command-line tool overflowing into dependencies.
- Fixed a crash occurring when using `pack-format --version`.
- Fixed the command-line tool overflowing into dependents.
- Fixed a crash occurring when using flag `--version`/`-v`.

## 1.0.1
*2021-01-23*
Expand Down
14 changes: 14 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!usr/bin/env node
const VERSION = '1.0.3'

const getPackFormat = require('./index.js')

const arg = n => process.argv[n + 1]

if (arg(1) && !arg(1).includes('-h'))
if (arg(1).includes('-v'))
console.log(`The current version of pack-format is ${VERSION}`)
else
console.log(`Pack format of ${arg(1)} is ${getPackFormat(arg(1))}`)
else
console.log('Type `pack-format <version>` to retrieve the pack format of any Minecraft version.')
7 changes: 0 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
const VERSION = '1.0.2'

class Snapshot {
constructor(version) { this.version = version }
Expand Down Expand Up @@ -63,9 +62,3 @@ function getPackFormat(version) {
}

module.exports = getPackFormat

const arg = n => process.argv[n + 1]
if (arg(1) && arg(0).includes('pack-format')) {
if (arg(1).includes('-v')) console.log('The current version of pack-format is ' + VERSION)
else console.log('Pack format of ' + arg(1) + ' is ' + getPackFormat(arg(1)))
}
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack-format",
"version": "1.0.2",
"version": "1.0.3",
"description": "Returns the pack_format of any Minecraft version, including snapshots",
"scripts": {
"test": "node test"
Expand All @@ -11,12 +11,9 @@
"datapack",
"pack_format"
],
"files": [
"index.js"
],
"main": "index.js",
"bin": {
"pack-format": "index.js"
"pack-format": "cli.js"
},
"repository": {
"type": "git",
Expand Down
25 changes: 16 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
[![Latest version](https://img.shields.io/github/v/release/Nixinova/pack-format?label=latest&style=flat-square)](https://github.com/Nixinova/pack-format/releases)
[![npm downloads](https://img.shields.io/npm/dt/pack-format?style=flat-square)](https://www.npmjs.com/package/pack-format)
[![Last updated](https://img.shields.io/github/release-date-pre/Nixinova/pack-format?label=updated&style=flat-square)](https://github.com/Nixinova/pack-format/releases)

# pack-format

pack-format is a Node.js tool for retrieving the `pack_format` of any Minecraft version, including snapshots.

## About

`pack_format` is a version number used in both resource packs and data packs for labeling compatible versions.
It was added in version 1.6, and as such using this tool on any version prior to that will just return `undefined`.
It was added in Minecraft version 1.6, and as such using this tool on any version prior to that will just return `undefined`.

## Install

Using npm, type `npm install pack-format` to use for a Node.js project, or `npm install -g pack-format` to use from the command line.
Using npm, open your command prompt and type `npm install pack-format` to use for a Node.js project or `npm install -g pack-format` to use from the command line.

## Usage

### Node

```js
const getPackFormat = require('pack-format')
console.log( getPackFormat('1.14.3') ) // 4
console.log( getPackFormat('1.16.2-pre1') ) // 5
console.log( getPackFormat('15w42a') ) // 2
console.log( getPackFormat('1.4.7') ) // undefined
const packFormat = require('pack-format')
packFormat('1.14.4') // 4
packFormat('1.16.2-pre1') // 5
```

### Command line

```
pack-format <version>
`pack-format <version>`

```cmd
> pack-format 1.14.4
Pack format of 1.14.4 is 4
> pack-format 1.16.2-pre1
Pack format of 1.16.2-pre1 is 5
```
15 changes: 13 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
const packFormat = require('./')
const test = (ver, expected) =>
console.log(`Pack format of ${ver} is ${packFormat(ver)} ${packFormat(ver) == expected ? '(pass)' : '(fail)'}`)

let total = 0, passed = 0, failed = 0
const test = (input, expected) => {
let ver = packFormat(input)
let pass = ver == expected
if (pass) passed++
else failed++
total++
console.log(`${pass ? '+' : '-'} Pack format of ${input} is ${ver}`)
}

test('1.1', null)
test('1.6', 1)
test('1.9', 2)
test('1.16.1', 5)
test('1.16.3', 6)
Expand All @@ -11,3 +20,5 @@ test('1.30', null)
test('11w50a', null)
test('20w30a', 6)
test('99w99a', null)

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

0 comments on commit aba4016

Please sign in to comment.