Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

resourcepacker

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resourcepacker - npm Package Compare versions

Comparing version 1.0.0-pre2 to 1.0.0-pre3

7

changelog.md
# Changelog
## 1.0.0-pre3
*2020-07-18*
- **Breaking:** Changed configuration file from `.rpkr` (in a custom format) to `.rpkr.json` (in a JSON format).
- Added support for automatic langugage generation by setting the values of language codes in the `.rpkr.json` configuration file.
- Removed support for custom variables in the configuration file.
## 1.0.0-pre2

@@ -9,2 +15,3 @@ *2020-07-16*

- Pack version is automatically generated from the value of `mcver`.
- Added support for custom variables in the `.rpkr` configuration file.

@@ -11,0 +18,0 @@ ## 1.0.0-pre1

98

index.js
#!/usr/bin/env node
const RPKR_VERSION = '1.0.0-pre3';
const fs = require('fs');
const copyfiles = require('copyfiles');
const jsonformat = require('json-format');
const log = str => console.log('<resourcepacker> ' + str);
const RPKR_VERSION = '1.0.0-pre2';
const CONFIG = { name: process.cwd().split(/\/|\\/).slice(-1), packver: '1.0.0', mcver: '1.16.x', mcsnap: '', description: '' };
const RPKR_DEFAULT = `
name: ${CONFIG.name}
packver: ${CONFIG.packver}
mcver: ${CONFIG.mcver}
mcsnap: ${CONFIG.mcsnap}
description: ${CONFIG.description}
files:
pack.png
pack.mcmeta
assets/**/*.png
assets/**/*.mcmeta
assets/**/*.json
assets/**/*.lang
assets/**/*.txt
assets/**/*.fsh
assets/**/*.bin
`.trim();
const CONFIG = {
name: process.cwd().split(/\/|\\/).slice(-1)[0],
packver: '1.0.0', mcver: '1.16.x', mcsnap: null,
description: null, languages: null,
files: [
"pack.png",
"pack.mcmeta",
"assets/**/*.png",
"assets/**/*.mcmeta",
"assets/**/*.json",
"assets/**/*.lang",
"assets/**/*.txt",
"assets/**/*.fsh",
"assets/**/*.bin"
]
};
const PACK_FORMATS = { '1.6,1.7,1.8': 1, '1.9,1.10': 2, '1.11,1.12': 3, '1.13,1.14': 4, '1.15,1.16': 5 };
const PACKVERS = { '1.6,1.7,1.8': 1, '1.9,1.10': 2, '1.11,1.12': 3, '1.13,1.14': 4, '1.15,1.16': 5 };
function init() {
fs.writeFile('.rpkr', RPKR_DEFAULT, err => {
if (err) throw "FSWriteError: Cannot write to .rpkr configuration file";
else log("Successfully created config file .rpkr with default settings")
fs.writeFile('.rpkr.json', jsonformat(CONFIG), err => {
if (err) throw "FSWriteError: Cannot write to .rpkr.json configuration file";
else log("Successfully created config file .rpkr.json with default settings");
});

@@ -36,36 +35,39 @@ }

function package(output) {
fs.readFile('.rpkr', 'utf8', (err, contents) => {
let hasError = false;
fs.readFile('.rpkr.json', 'utf8', (err, contents) => {
if (err) init();
let config = err ? CONFIG : JSON.parse(contents);
let { files, name, packver, mcver, mcsnap, description, languages } = config;
let outputFolder = output || `${name} ${packver} (${mcsnap || mcver})`;
let rpkrData = RPKR_DEFAULT.split('\n'), config = CONFIG;
if (err) init(); else rpkrData = contents.split('\n');
for (let param of rpkrData) {
let parts = param.split(':');
if (!parts[1]) break;
let key = parts[0];
let val = parts[1].slice(1).trim();
config[key] = val;
}
config.globs = rpkrData.slice(rpkrData.indexOf('files:') + 1);
let { globs, name, packver, mcver, mcsnap, description } = config;
let outputFolder = output || `${name} ${packver} (${mcsnap || mcver})`
log(`Packaging version ${packver} of '${name}'...`);
copyfiles(
[...globs, outputFolder], {},
[...files, outputFolder], {},
(err) => {
const success = x => {
log(`${x ? 'Uns' : 'S'}uccessfully packaged version ${packver} of '${name}' for Minecraft ${mcver}`);
log(`${x == null ? 'Uns' : 'S'}uccessfully packaged version ${packver} of '${name}' for Minecraft ${mcver}`);
}
if (err) hasError = true, log('Error: ' + err), success(false);
if (err) log('Error: ' + err), success(false);
else if (description) {
let packver = 0, mcverMajor = mcver.replace(/^(\d\.\d+).*/, '$1');
for (let key in PACKVERS) { if (key.includes(mcverMajor)) packver = PACKVERS[key]; }
let packFormat = 0, mcverMajor = mcver.replace(/^(\d\.\d+).*/, '$1');
for (let key in PACK_FORMATS) {
if (key.includes(mcverMajor)) packFormat = PACK_FORMATS[key];
}
for (let item in config) {
description = description.replace(/&(?=\w)/g, '§').replace(RegExp('<' + item + '>', 'g'), config[item]);
}
const mcmetaContent = `{\n "pack": {\n "pack_format": ${packver},\n "description": ${JSON.stringify(description)}\n }\n}`;
fs.writeFile(outputFolder + '/pack.mcmeta', mcmetaContent, err => {
if (err) hasError = true, log("FSWriteError: Could not create automatic pack.mcmeta file"), success(false);
let mcmetaContent = { "pack": { "pack_format": packFormat, "description": description } };
if (languages) {
mcmetaContent.language = {};
for (let lang in languages) {
const matchRegex = /^\s*(.*?)\s*\((.*?)\)\s*/i;
let [, name, region] = languages[lang].match(matchRegex);
mcmetaContent.language[lang] = { "name": name, "region": region};
}
}
fs.writeFile(outputFolder + '/pack.mcmeta', jsonformat(mcmetaContent, { type: 'space' }), err => {
if (err) log("FSWriteError: Could not create automatic pack.mcmeta file"), success(false);
else log("Created automatic pack.mcmeta file"), success();

@@ -72,0 +74,0 @@ });

{
"name": "resourcepacker",
"version": "1.0.0-pre2",
"version": "1.0.0-pre3",
"description": "Easily and cleanly packages Minecraft resource packs from a messy working directory",
"keywords": [
"minecraft",
"resource pack"
"resourcepack"
],

@@ -26,4 +26,5 @@ "files": [

"dependencies": {
"copyfiles": "^2.3.0"
"copyfiles": "^2.3.0",
"json-format": "^1.0.1"
}
}

@@ -0,1 +1,6 @@

[![Latest version](https://img.shields.io/github/v/release/Nixinova/resourcepacker?label=latest&style=flat-square&include_prereleases)](https://github.com/Nixinova/resourcepacker/releases)
[![npm version](https://img.shields.io/npm/v/resourcepacker?style=flat-square)](https://www.npmjs.com/package/resourcepacker)
[![npm downloads](https://img.shields.io/npm/dt/resourcepacker?style=flat-square)](https://www.npmjs.com/package/resourcepacker)
[![Last updated](https://img.shields.io/github/release-date-pre/Nixinova/resourcepacker?label=updated&style=flat-square)](https://github.com/Nixinova/resourcepacker/releases)
# resourcepacker

@@ -7,11 +12,11 @@

Install resourcepacker on npm by typing **`npm install -g resourcepacker`** in the command prompt. You must have Node.js installed.
Install [resourcepacker on npm](https://www.npmjs.com/package/resourcepacker) by typing **`npm install -g resourcepacker`** in the command prompt. You must have Node.js installed.
After installing resourcepacker, type **`rpkr init`** to ready your directory with a configuration file (`.rpkr`). For information on how to use this configuration file, please see the **Configuration** section below.
After installing resourcepacker, type **`rpkr init`** to ready your directory with a configuration file (`.rpkr.json`). For information on how to use this configuration file, please see the **Configuration** section below.
To package a resource pack, simply type **`rpkr pack`** and your resource pack will be packaged into an output folder. You can control which directory the files are outputted to by placing the output folder name in quotes after this command; for example, `rpkr pack "My Pack 1.16"` outputs to folder "My Pack 1.16". If the output folder is not set, it defaults to the format `name packver (mcver)`, where each value comes from the `.rpkr` file.
To package a resource pack, simply type **`rpkr pack`** and your resource pack will be packaged into an output folder. You can control which directory the files are outputted to by placing the output folder name in quotes after this command; for example, `rpkr pack "My Pack 1.16"` outputs to folder "My Pack 1.16". If the output folder is not set, it defaults to the format "`name` `packver` (`mcver`)", where each value comes from the `.rpkr.json` file.
## Configuration
The `.rpkr` configuration file can be edited to fine tune the output of your resource pack. Comments can be added using a hash (`#`).
The `.rpkr.json` configuration file can be edited to fine tune the output of your resource pack. Comments can be added using a hash (`#`).

@@ -23,16 +28,20 @@ ### Parameters

* `mcver`: The Minecraft version your resource pack is made for. Defaults to "1.16.x".
* `mcsnap`: The Minecraft development version your resource pack is made for. Blank by default.
* `description`: The content in the description field of the automatic `pack.mcmeta` file. Blank by default. Only generates an automatic `pack.mcmeta` when set. More information below
* *`custom variables`*: Optional. Can contain any content. Can be used in the `description` field by surrounding the variable name in angle brackets (`<>`).
* `files`: File globs that will be passed through into your output folder. Must be the last named parameter as it is followed by newline-separated globs. More information below.
* `mcsnap` (optional): The Minecraft development version your resource pack is made for. Blank by default.
* `description` (optional): The content in the description field of the automatic `pack.mcmeta` file. Only generates an automatic `pack.mcmeta` when set. More information below.
* `languages` (optional): A list of languages to add to the automatically-generated `pack.mcmeta` file.
* `files`: File globs that will be passed through into your output folder. More information below.
#### Description
The `description` parameter, when set, will be the contents of the `description` key of an automatically-generated `pack.mcmeta` file. An automatic `pack.mcmeta` file is only created when this parameter is set. Other parameters in `.rpkr` can be referenced by placing the parameter name in angle brackets (`<>`). Color codes can be declared using either ampersands (`&`) or section signs (`§`) followed by a hexidecimal digit. The value of the `pack_version` key in `pack.mcmeta` is determined by the value of `mcver`.
The `description` parameter, when set, will be the contents of the `description` key of an automatically-generated `pack.mcmeta` file. An automatic `pack.mcmeta` file is only created when this parameter is set. Other parameters in `.rpkr.json` can be referenced by placing the parameter name in angle brackets (`<>`). Color codes can be declared using either ampersands (`&`) or section signs (`§`) followed by a hexidecimal digit. The value of the `pack_version` key in `pack.mcmeta` is determined by the value of `mcver`.
For example, a `description` of `&b<name> &l<packver>` sets the `description` key of `pack.mcmeta` to the value of the `name` parameter in aqua followed by the contents of the `packver` parameter in bold.
#### Languages
The `languages` parameter is an object where each key is the language code your pack is adding or modifying (which much match a language file inside `assets/minecraft/lang`) with the value being the name of the language in the format "`language` (`variant`)". For example, if your resource pack modifies British English, use `"en_gb": "English (United Kingdom)"`. Multiple custom languages can be added.
#### Files
By default, the following globs (file path formats) are found in the `.rpkr` configuration file, below "`files:`". You can add or remove any globs as you see fit; for example, if you have a `readme.txt` file in the root directory that you want outputted, place `readme.txt` on its own line.
You can add or remove any globs (file path formats) as you see fit to the `.rpkr.json` configuration file under the "`files`" array; for example, if you have a `readme.txt` file in the root directory that you want outputted, add `readme.txt` to the array. Use "`**`" to specify any number of nested subfolders (including zero) and "`*`" to specify any string of characters (excluding slashes). By default, the following globs are specified in the `files` array:

@@ -51,7 +60,3 @@ ```

Key:
* `*`: Any string of characters, excluding slashes.
* `**`: Any string of characters, including slashes.
## Try it out
Clone [this repository](https://github.com/Nixinova/resourcepacker.git), `cd` into that directory, and then type **`node index.js pack`** to pack the contents of this repository into a clean output folder. You'll see that out of all of the messy files in this folder, only the `assets`, `pack.png`, and `pack.mcmeta` files are outputted.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc