Skip to content

Commit

Permalink
Better validate input
Browse files Browse the repository at this point in the history
  • Loading branch information
ozelot379 committed Aug 22, 2019
1 parent deaa71d commit c66ec33
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## [1.7.1]
- Better validate input

## [1.7.0]
- Supports input and output a `Buffer`
- Remove temp folder usage, instead write directly to the output
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ozelot379/convert-minecraft-java-texture-to-bedrock",
"productName": "ConvertMinecraftJavaTextureToBedrock",
"version": "1.7.0",
"version": "1.7.1",
"description": "CLI version for convert Minecraft Java texture packs to Minecraft Bedrock texture packs",
"keywords": [
"Minecraft",
Expand Down
9 changes: 8 additions & 1 deletion src/Converter/MetadataConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import uuid from "uuid/v4";
* Class MetadataConverter
*/
class MetadataConverter extends AbstractConverter {
/**
* @returns {string}
*/
static get PACK_MCMETA() {
return "pack.mcmeta";
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -70,7 +77,7 @@ class MetadataConverter extends AbstractConverter {
* @inheritDoc
*/
async* getData() {
const date = ["pack.mcmeta", "manifest.json", "bedrock_uuid_header", "bedrock_uuid_module"];
const date = [this.constructor.PACK_MCMETA, "manifest.json", "bedrock_uuid_header", "bedrock_uuid_module"];

yield date;
}
Expand Down
12 changes: 11 additions & 1 deletion src/Input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AbstractInput from "./AbstractInput";
import BufferInput from "./BufferInput";
import FolderInput from "./FolderInput";
import fs from "fs-extra";
import MetadataConverter from "../Converter/MetadataConverter";
import path from "path";
import ZipInput from "./ZipInput";

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

if (fs.statSync(input).isDirectory()) {
if (!fs.existsSync(path.join(input, MetadataConverter.PACK_MCMETA))) { // Prevents copy whole wrong folders
throw new Error(`Invalid folder input ${input} - Missing ${MetadataConverter.PACK_MCMETA}!`);
}

return new FolderInput(input);
}


const ext = path.extname(input).toLowerCase().substr(1);

switch (ext) {
case "zip":
return new ZipInput(input);

default:
return new FolderInput(input);
throw new Error(`The input ${input} is no zip archive or folder!`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import yargs from "yargs";
verbose: argv.verbose
});
} catch (err) {
console.error(err);
console.error(err.message);

process.exit(1);
}
Expand Down

0 comments on commit c66ec33

Please sign in to comment.