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.1.1 to 1.2.0

6

changelog.md
# Changelog
## 1.2.0
*2021-01-23*
- Added Node.js exports, `init(options?)` and `pack(input, output, options?)`
- Added optional `<input>` command-line option to `rpkr pack`, changing the syntax to `rpkr pack [<input>] [<output>|--force]`.
- Changed default file globs to be more specific.
## 1.1.1

@@ -4,0 +10,0 @@ *2021-01-23*

100

index.js
#!/usr/bin/env node
const RPKR_VERSION = '1.1.1';
const RPKR_VERSION = '1.2.0';
const fs = require('fs');
const copyfiles = require('copyfiles');
const movefiles = require('glob-move');
const archiver = require('archiver');

@@ -18,3 +19,3 @@ const jsonFormat = require('json-format');

mcsnap: null,
description: 'Default resource pack configuration.',
description: 'Default resource pack configuration, which creates an automatic pack.mcmeta file when packing.',
languages: null,

@@ -27,10 +28,11 @@ files: [

"assets/**/*.json",
"assets/**/*.lang",
"assets/**/*.txt",
"assets/**/*.fsh",
"assets/**/*.bin"
"assets/**/lang/**/*.lang",
"assets/**/texts/**/*.txt",
"assets/**/sounds/**/*.ogg",
"assets/**/shaders/**/*.fsh",
"assets/**/shaders/**/*.bin"
]
};
function init({ force }) {
function init({ force } = {}) {
if (fs.existsSync('.rpkr.json') && !force) {

@@ -49,3 +51,3 @@ log('Warning: This folder is already initialised with an .rpkr.json configuration file.');

function package(output, { zipped }) {
function pack(input = '.', output, { zipped } = {}) {
fs.readFile('.rpkr.json', 'utf8', (err, contents) => {

@@ -64,3 +66,3 @@ if (err) init();

}
let outputPathName = output || `${name} ${packver} (${versionLabel})`;
output = output || `${name} ${packver} (${versionLabel})`;

@@ -92,5 +94,5 @@ // Create automatic mcmeta file

/// Write mcmeta to disc
if (!zipped || output.includes('/')) fs.mkdirSync(outputPathName, { recursive: true });
if (!zipped || output.includes('/')) fs.mkdirSync(output, { recursive: true });
fs.writeFileSync(
(zipped ? 'temp-' : outputPathName + '/') + 'pack.mcmeta',
(zipped ? 'temp-' : output + '/') + 'pack.mcmeta',
jsonFormat(mcmetaContent, { type: 'space' }),

@@ -104,17 +106,38 @@ err => {

// Localise paths
for (let i in files) {
files[i] = input.replace(/\/$/, '') + '/' + files[i];
}
// Write output to disk
const success = s => log(`${s ? 'S' : 'Uns'}uccessfully packaged version ${packver} of '${name}' for Minecraft ${mcver} to '${outputPathName.replace(/\/$|\.zip$/, '')}${zipped ? '.zip' : '/'}'`);
const success = s => log(`${s ? 'S' : 'Uns'}uccessfully packaged version ${packver} of '${name}' for Minecraft ${mcver} to '${output.replace(/\/$|\.zip$/, '')}${zipped ? '.zip' : '/'}'`);
log(`Packaging version ${packver} of '${name}'...`);
if (zipped) {
const filename = outputPathName + '.zip';
const output = fs.createWriteStream(filename);
if (fs.existsSync(filename)) log(`Warning: Overwriting existing file ${filename}.`);
const zipFile = output + '.zip';
if (fs.existsSync(zipFile)) log(`Warning: Overwriting existing file ${zipFile}.`);
const out = fs.createWriteStream(zipFile);
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => fs.unlink('temp-pack.mcmeta', err => err ? log(`Error: ${err}`) : success(true)));
archive.pipe(output); // Start writing to zip file
out.on('close', () => fs.unlink('temp-pack.mcmeta', err => err ? log(`Error: ${err}`) : success(true)));
archive.pipe(out); // Start writing to zip file
archive.file('temp-pack.mcmeta', { name: 'pack.mcmeta' });
for (let glob of [...files]) archive.glob(glob);
for (let glob of [...files]) archive.glob(glob.replace(/^.\//, ''));
archive.finalize(); // End writing to zip file
}
else copyfiles([...files, outputPathName], {}, err => err ? (log('Error: ' + err), success(false)) : success(true));
else {
copyfiles([...files, output], {}, err => {
if (err) {
log('Error: ' + err);
success(false);
}
else if (input !== '.') {
const oldOutput = output + '/' + input;
movefiles(oldOutput + '/*', output)
.then(() => {
fs.rmdirSync(oldOutput)
success(true)
})
.catch(err => log(err))
} else success(true)
});
}

@@ -124,9 +147,12 @@ });

module.exports = { init, pack };
const arg = n => process.argv[n + 1] || '';
if (!arg(1)) {
log('Welcome to resourcepacker, the simple way to package Minecraft resource packs.');
log('Type `rpkr help` for a list of commands.');
}
else if (arg(1).includes('h')) {
log(`\n
if (arg(0).includes('resourcepacker')) {
if (!arg(1)) {
log('Welcome to resourcepacker, the simple way to package Minecraft resource packs.');
log('Type `rpkr help` for a list of commands.');
}
else if (arg(1).includes('h')) {
log(`\n
rpkr --help

@@ -137,16 +163,20 @@ Display this help message.

Use '--force' to overwrite the existing .rpkr.json configuration file with default settings.
rpkr pack [<name>|--folder]
rpkr pack [<input>] [<output>|--folder]
Package your resource pack into a zip file with its name described by the configuration file.
Use '--folder'> to output the resource pack into a zip file instead of a folder.
Or, use <name> to set a custom output folder name; append '.zip' to pack to a zip file instead.
Use '--folder' to output the resource pack into a zip file instead of a folder.
Or, use <output> to set a custom output folder name; append '.zip' to pack to a zip file instead.
rpkr --version
Display the current version of resourcepacker.
`);
}
else if (arg(1).includes('v')) log('The current version of resourcepacker is ' + RPKR_VERSION);
else if (arg(1) === 'init') init({ force: /^--?f(orce)?/.test(arg(2)) });
else if (arg(1) === 'pack') {
const [input, out] = arg(3) ? [arg(2), arg(3)] : ['.', arg(2)];
const zipExt = out.endsWith('.zip');
const zipExpl = out.match(/^--?f(older)?.*/)
const output = zipExt ? out.replace(/\.zip$/, '') : (zipExpl ? '' : out)
pack(input, output, { zipped: zipExt || zipExpl });
}
else log('Unknown command; type `rpkr help` for help');
}
else if (arg(1).includes('v')) log('The current version of resourcepacker is ' + RPKR_VERSION);
else if (arg(1) === 'init') init({ force: /^--?f(orce)?/.test(arg(2)) });
else if (arg(1) === 'pack') {
const zipExt = arg(2).endsWith('.zip');
package(zipExt ? arg(2).replace(/\.zip$/, '') : arg(2).replace(/^--?f(older)?.*/, ''), { zipped: zipExt || !arg(2) });
}
else log('Unknown command; type `rpkr help` for help');
{
"name": "resourcepacker",
"version": "1.1.1",
"version": "1.2.0",
"description": "Package Minecraft resource packs easily and cleanly from a messy working directory",

@@ -28,2 +28,3 @@ "keywords": [

"copyfiles": "^2.4.1",
"glob-move": "^1.0.1",
"json-format": "^1.0.1",

@@ -30,0 +31,0 @@ "pack-format": "^1.0.2"

@@ -11,4 +11,6 @@ [![Latest version](https://img.shields.io/github/v/release/Nixinova/resourcepacker?label=latest&style=flat-square)](https://github.com/Nixinova/resourcepacker/releases)

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.
### Command-line
Install [resourcepacker on npm](https://www.npmjs.com/package/resourcepacker) by typing **`npm install -g resourcepacker`** into the command line.
After installing resourcepacker, `cd` to the directory your resource is located in, then type **`rpkr init`** to ready your directory with a configuration file (`.rpkr.json`). Customise the values in this configuration file to your liking. For information on how to use this configuration file, please see the **Configuration** section below.

@@ -18,2 +20,21 @@

### Node
Install resourcepacker locally using **`npm install resourcepacker`**. Two functions are exported: `init` and `pack`.
- `init(options?: object)`:
Initialize with a `.rpkr.json` configuration file. The following options are available:
- `force`: Overwrite an existing `.rpkr.json` file.
- `pack(input: string, output: string, options?: object)`:
Package a resource pack from folder `input` into folder `output`. Set `input` to `"."` (a dot) to use the current folder.
- `zipped`: Output to a zip file instead of a folder.
Example:
```js
const rpkr = require('resourcepacker')
rpkr.init({force: true})
rpkr.pack('My Pack', 'Output', {zipped: false})
```
## Configuration

@@ -54,9 +75,11 @@

assets/**/*.json
assets/**/*.lang
assets/**/*.txt
assets/**/*.fsh
assets/**/*.bin
assets/**/lang/**/*.lang
assets/**/texts/**/*.txt
assets/**/sounds/**/*.ogg
assets/**/shaders/**/*.fsh
assets/**/shaders/**/*.bin
```
## Try it out
Clone [this repository](https://github.com/Nixinova/resourcepacker.git) then type **`cd resourcepacker && npm install && 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.
Clone [this repository](https://github.com/Nixinova/resourcepacker.git) then type **`cd resourcepacker && npm install && node . 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