Skip to content

Commit c66ec33

Browse files
author
ozelot379
committed
Better validate input
1 parent deaa71d commit c66ec33

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.7.1]
4+
- Better validate input
5+
36
## [1.7.0]
47
- Supports input and output a `Buffer`
58
- Remove temp folder usage, instead write directly to the output

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ozelot379/convert-minecraft-java-texture-to-bedrock",
33
"productName": "ConvertMinecraftJavaTextureToBedrock",
4-
"version": "1.7.0",
4+
"version": "1.7.1",
55
"description": "CLI version for convert Minecraft Java texture packs to Minecraft Bedrock texture packs",
66
"keywords": [
77
"Minecraft",

‎src/Converter/MetadataConverter.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import uuid from "uuid/v4";
66
* Class MetadataConverter
77
*/
88
class MetadataConverter extends AbstractConverter {
9+
/**
10+
* @returns {string}
11+
*/
12+
static get PACK_MCMETA() {
13+
return "pack.mcmeta";
14+
}
15+
916
/**
1017
* @inheritDoc
1118
*/
@@ -70,7 +77,7 @@ class MetadataConverter extends AbstractConverter {
7077
* @inheritDoc
7178
*/
7279
async* getData() {
73-
const date = ["pack.mcmeta", "manifest.json", "bedrock_uuid_header", "bedrock_uuid_module"];
80+
const date = [this.constructor.PACK_MCMETA, "manifest.json", "bedrock_uuid_header", "bedrock_uuid_module"];
7481

7582
yield date;
7683
}

‎src/Input/index.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import AbstractInput from "./AbstractInput";
22
import BufferInput from "./BufferInput";
33
import FolderInput from "./FolderInput";
44
import fs from "fs-extra";
5+
import MetadataConverter from "../Converter/MetadataConverter";
56
import path from "path";
67
import ZipInput from "./ZipInput";
78

@@ -33,14 +34,23 @@ async function detectInput(input) {
3334
throw new Error(`The input ${input} does not exists!`);
3435
}
3536

37+
if (fs.statSync(input).isDirectory()) {
38+
if (!fs.existsSync(path.join(input, MetadataConverter.PACK_MCMETA))) { // Prevents copy whole wrong folders
39+
throw new Error(`Invalid folder input ${input} - Missing ${MetadataConverter.PACK_MCMETA}!`);
40+
}
41+
42+
return new FolderInput(input);
43+
}
44+
45+
3646
const ext = path.extname(input).toLowerCase().substr(1);
3747

3848
switch (ext) {
3949
case "zip":
4050
return new ZipInput(input);
4151

4252
default:
43-
return new FolderInput(input);
53+
throw new Error(`The input ${input} is no zip archive or folder!`);
4454
}
4555
}
4656

‎src/cli.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import yargs from "yargs";
3333
verbose: argv.verbose
3434
});
3535
} catch (err) {
36-
console.error(err);
36+
console.error(err.message);
3737

3838
process.exit(1);
3939
}

0 commit comments

Comments
 (0)