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-pre1 to 1.0.0-pre2

12

changelog.md
# Changelog
## 1.0.0-pre2
*2020-07-16*
- Added `description` property to `.rpkr`, which creates an automatic `pack.mcmeta` file if set.
- Can contain references to other parameters in the `.rpkr` file (including custom ones) by enclosing the parameter name in angle brackets (`<>`).
- Ampersands (`&`) are automatically converted to section signs (`§`) to become color codes.
- Pack version is automatically generated from the value of `mcver`.
## 1.0.0-pre1
*2020-07-16*
- Initial release, containing the following features:
- Creation and reading of `.rpkr` configuration files with keys `name`, `packver`, `mcver`, `snapver`, and `files`.
- Packaging into either a pre-set (using `.rpkr`) or user-specified output folder.
- Supports the creation and reading of `.rpkr` configuration files with keys `name`, `packver`, `mcver`, `snapver`, and `files`.
- Supports packaging into either a pre-set (using `.rpkr`) or user-specified output folder.
#!/usr/bin/env node
const fs = require('fs');
const copyfiles = require('copyfiles');
const log = str => console.log('<resourcepacker> ' + str);
const RPKR_VERSION = '1.0.0-pre1';
const CONFIG = { name: process.cwd().split(/\/|\\/).slice(-1), packver: '1.0.0', mcver: '1.16.x', mcsnap: '' }
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 = `

@@ -12,2 +13,3 @@ name: ${CONFIG.name}

mcsnap: ${CONFIG.mcsnap}
description: ${CONFIG.description}
files:

@@ -25,6 +27,8 @@ pack.png

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 console.log("Created config file .rpkr with default settings")
else log("Successfully created config file .rpkr with default settings")
});

@@ -35,23 +39,40 @@ }

fs.readFile('.rpkr', 'utf8', (err, contents) => {
let hasError = false;
let rpkrContent = RPKR_DEFAULT, config = CONFIG;
if (err) init(); else rpkrContent = contents;
let rpkrData = RPKR_DEFAULT.split('\n'), config = CONFIG;
if (err) init(); else rpkrData = contents.split('\n');
let args = rpkrContent.split(/\s*\r?\n/);
config.globs = args.slice(args.indexOf('files:') + 1);
const matchRegex = key => RegExp('^' + key + ':\\s*')
const setConfig = (arg, ...keys) => {
for (let key of keys) if (arg.match(matchRegex(key))) config[key] = arg.replace(matchRegex(key), '');
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;
}
args.filter(arg => {
arg = arg.replace(/\s*#.*$/, '');
setConfig(arg, 'name', 'packver', 'mcver', 'mcsnap')
});
config.globs = rpkrData.slice(rpkrData.indexOf('files:') + 1);
let { globs, name, packver, mcver, mcsnap } = config;
console.log(`Packaging version ${packver} of '${name}'...`);
let { globs, name, packver, mcver, mcsnap, description } = config;
let outputFolder = output || `${name} ${packver} (${mcsnap || mcver})`
log(`Packaging version ${packver} of '${name}'...`);
copyfiles(
[...globs, output || `${name} ${packver} (${mcsnap || mcver})`],
{},
err => console.log(err || `Successfully packaged '${name}' version ${packver} for Minecraft ${mcver}`)
[...globs, outputFolder], {},
(err) => {
const success = x => {
log(`${x ? 'Uns' : 'S'}uccessfully packaged version ${packver} of '${name}' for Minecraft ${mcver}`);
}
if (err) hasError = true, 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]; }
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);
else log("Created automatic pack.mcmeta file"), success();
});
}
else success();
}
);

@@ -64,3 +85,3 @@

if (arg(1).includes('h')) {
console.log(`
log(`
rpkr help Display this help message

@@ -72,5 +93,5 @@ rpkr init Initialize this directory with an rpkr configuration file

}
else if (arg(1).includes('v')) console.log('Current version: ' + RPKR_VERSION);
else if (arg(1).includes('v')) log('Current version: ' + RPKR_VERSION);
else if (arg(1) === 'init') init();
else if (arg(1) === 'pack') package(arg(2));
else console.log('Unknown command; type `rpkr help` for help');
else log('Unknown command; type `rpkr help` for help');
{
"name": "resourcepacker",
"version": "1.0.0-pre1",
"description": "Easily and cleanly packs Minecraft resource packs from a messy working directory",
"version": "1.0.0-pre2",
"description": "Easily and cleanly packages Minecraft resource packs from a messy working directory",
"keywords": [

@@ -6,0 +6,0 @@ "minecraft",

@@ -23,8 +23,16 @@ # resourcepacker

* `mcsnap`: The Minecraft development version your resource pack is made for. Blank by default.
* `files`: File globs that will be passed through into your output folder. More information below.
* `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.
### Files
#### Description
By default, the following globs (file path formats) are found in the `.rpkr` configuration file. You can add or remove and globs that you like; for example, if you have a `readme.txt` file in the root directory that you want outputted, place `readme.txt` on its own line.
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`.
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.
#### 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.
```

@@ -31,0 +39,0 @@ pack.png

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