From 63659416c33c3d23563a539025194e6c14bb3caf Mon Sep 17 00:00:00 2001 From: extremeheat Date: Mon, 28 Dec 2020 21:50:08 -0500 Subject: [PATCH] update --- .gitignore | 4 +++- README.md | 9 +++++++++ index.js | 4 ++-- package.json | 4 +++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 952d30b..610ae61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules/ package-lock.json *.nbt -*.dat \ No newline at end of file +*.dat +*.json +!package.json \ No newline at end of file diff --git a/README.md b/README.md index 7a00992..d7e513b 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,15 @@ A simple command line Node.js tool to read and write NBT files to JSON and back. Uses `prismarine-nbt` for serialization and deserialization, see https://github.com/PrismarineJS/prismarine-nbt for more info on schema. +### Usage + +via npx: +`npx nbt-dump --help` + +via npm: +`npm install -g nbt-dump` +`nbt-dump --help` + ```sh usage, feel free to use natural language: Parse an NBT file to JSON: diff --git a/index.js b/index.js index e6d0b7a..3e24251 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node const fs = require('fs') const nbt = require('prismarine-nbt') @@ -38,7 +39,6 @@ function main(args, argsStr) { if (files.length == 2) return write(...files, getFmt()) } else { if (!files.length) files = [args[0], args[0] + '.json'] - // if (files.length == 1) files.push(files[0] + '.json') return read(files[0], files[1], getFmt()) } @@ -69,11 +69,11 @@ async function read(inpf, outf, fmt) { const buffer = await fs.promises.readFile(inpf) const { result, type } = await nbt.parse(buffer, fmt) + if (!fmt) console.log(`(as ${type} endian)`) if (outf) { const json = JSON.stringify(result, (k, v) => typeof v === 'bigint' ? v.toString() : v) fs.writeFileSync(outf, json) } else { - if (!fmt) console.log(`(as ${type} endian)`) console.log(nbt.simplify(result)) } diff --git a/package.json b/package.json index 3982de0..622ed21 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "1.0.0", "description": "Read and write Minecraft Named Binary Tag files in big, little and little-varint encoding", "main": "index.js", - "bin": "index.js", + "bin": { + "nbt-dump": "./index.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" },