From aba40161040fd45697078b2a90e79bba25114f0b Mon Sep 17 00:00:00 2001 From: Nixinova Date: Tue, 9 Feb 2021 19:11:26 +1300 Subject: [PATCH] 1.0.3 - Add help command - Split CLI usage into separate file - Refactor tests --- changelog.md | 9 +++++++-- cli.js | 14 ++++++++++++++ index.js | 7 ------- package.json | 7 ++----- readme.md | 25 ++++++++++++++++--------- test.js | 15 +++++++++++++-- 6 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 cli.js diff --git a/changelog.md b/changelog.md index bb1d754..b1d1fc1 100644 --- a/changelog.md +++ b/changelog.md @@ -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* diff --git a/cli.js b/cli.js new file mode 100644 index 0000000..7eed55b --- /dev/null +++ b/cli.js @@ -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 ` to retrieve the pack format of any Minecraft version.') diff --git a/index.js b/index.js index ad2e236..387a417 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -const VERSION = '1.0.2' class Snapshot { constructor(version) { this.version = version } @@ -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))) -} diff --git a/package.json b/package.json index 433c7fc..c554442 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/readme.md b/readme.md index e5942e7..97e7897 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,7 @@ +[![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. @@ -5,26 +9,29 @@ pack-format is a Node.js tool for retrieving the `pack_format` of any Minecraft ## 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 +`pack-format ` + +```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 ``` diff --git a/test.js b/test.js index c4cf420..432b894 100644 --- a/test.js +++ b/test.js @@ -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) @@ -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`)