Compare commits

...

3 Commits

Author SHA1 Message Date
869c0bb70b Update README.md
+ Add more examples 
+ Update options
2024-09-02 22:39:38 +12:00
e79b1c8f39 fix pack metadata 2024-09-02 22:25:26 +12:00
e146afe50c allow user specified version 2024-09-02 22:16:34 +12:00
4 changed files with 77 additions and 27 deletions

3
.gitignore vendored
View File

@ -132,4 +132,5 @@ dist
# MSE chicanery
Maoist-Standard-English.zip
template/assets/minecraft/lang/en_mse.json
template/assets/minecraft/lang/en_mse.json
resourcepacks

View File

@ -9,7 +9,9 @@
```
Example usage:
* `./packgen.js -fR` generate a pack with the latest release version and descriptive output (recommended)
* `./packgen.js -f -v 1.15` using version "1.15" for pack generation
* `./packgen.js --lang en_nz` generate a pack using `en_nz` insead of the default `en_gb`
* `./packgen.js -f` generate a pack with a descriptive output zip E.g. `en_gb-v1.19.1-en_MSE` insead of just `Maoist-Standard-English.zip`
* `./packgen.js -m https://example.com/mc/game/version_manifest_v2.json -r https://example.com/` with a custom server `example.com`
@ -168,12 +170,15 @@ zlm_arab
## General Options:
```
Options:
-h, --help Show help [boolean]
-V, --version Show version number [boolean]
-f, --descriptivefile Descriptive output E.g. "en_gb-v1.19.1-en_MSE" [boolean]
-l, --lang <language> base language for pack generation [string]
-m, --manifest <url> custom manifest endpoint [string]
-r, --resources <url> custom resources endpoint [string]
-h, --help Show help [boolean]
-V, --version Show version number [boolean]
-f, --descriptivefile descriptive output E.g. "en_gb-v1.19.1-en_MSE"[boolean]
-l, --lang <language> base language for pack generation [string]
-v, --verid <version-id> base version for pack generation [string]
-R, --releaseOnly use only the *latest* release version [boolean]
-m, --manifest <url> custom manifest endpoint [string]
-r, --resources <url> custom resources endpoint [string]
-d, --debug verbose debug output [boolean]
```
# Why Us

View File

@ -1,8 +1,8 @@
./packgen.js -f -l en_au
./packgen.js -f -l en_ca
./packgen.js -f -l en_gb
./packgen.js -f -l en_nz
./packgen.js -f -l en_pt
./packgen.js -f -l en_ud
./packgen.js -f -l enp
./packgen.js -f -l enws
./packgen.js -fR -l en_au
./packgen.js -fR -l en_ca
./packgen.js -fR -l en_gb
./packgen.js -fR -l en_nz
./packgen.js -fR -l en_pt
./packgen.js -fR -l en_ud
./packgen.js -fR -l enp
./packgen.js -fR -l enws

View File

@ -25,13 +25,20 @@ var argv = require("yargs/yargs")(process.argv.slice(2))
required: false,
type: "string",
},
// TODO: version: {
// alias: "v",
// description: "<version> base version for pack generation",
// requiresArg: true,
// required: false,
// type: "string",
// },
verid: {
alias: "v",
description: "<version-id> base version for pack generation",
requiresArg: true,
required: false,
type: "string",
},
releaseOnly: {
alias: "R",
description: "use only the *latest* release version",
requiresArg: false,
required: false,
type: "boolean",
},
manifest: {
alias: "m",
description: "<url> custom manifest endpoint",
@ -46,9 +53,22 @@ var argv = require("yargs/yargs")(process.argv.slice(2))
required: false,
type: "string",
},
debug: {
alias: "d",
description: "verbose debug output",
requiresArg: false,
required: false,
type: "boolean",
},
})
.parse();
if (argv.debug) {console.log(argv)}
if (argv.verid && argv.releaseOnly) {
console.log('Ignoreing specified version and using latest release. (remove "releaseOnly" to use specified version)')
argv.verid = undefined
}
const urlReq = function (reqUrl, options, cb) {
if (typeof options === "function") {
cb = options;
@ -79,7 +99,22 @@ let piston =
urlReq(piston, function (body, res) {
json = JSON.parse(body);
let version = json.versions[0].id; // latest version
var version;
if (argv.releaseOnly) {
version = json.versions.filter(v => v.type === 'release')[0].id // latest type ("release") version
} else if (argv.verid) {
if (json.versions.filter(v => v.id === argv.verid ).length >= 1) { // specified ("argv.verid") version
console.log("Found metadata for",argv.verid)
version = argv.verid
} else {
console.log("No metadata found for",argv.verid,"are you sure this is a valid version id?")
process.exit(1);
}
} else {
version = json.versions[0].id; // latest type ("any") version
}
let resources =
argv.resources || "https://resources.download.minecraft.net/";
let baselang = argv.lang || "en_gb";
@ -99,10 +134,16 @@ urlReq(piston, function (body, res) {
console.log(`Using base language "${baselang}" from version (${version})`);
urlReq(json.versions[1].url, function (body, res) {
if (argv.debug) {console.log(version,json.versions.filter(v => v.id === version )[0].url)}
urlReq(json.versions.filter(v => v.id === version )[0].url, function (body, res) {
json = JSON.parse(body);
urlReq(json.assetIndex.url, function (body, res) {
json = JSON.parse(body);
if (json.objects[`minecraft/lang/${baselang}.json`] === undefined) {
console.log("This version has no/outdated language file (only ≥1.13 )")
process.exit(1);
}
hash = json.objects[`minecraft/lang/${baselang}.json`].hash;
urlReq(
resources + `${hash.substring(0, 2)}/${hash}`,
@ -132,6 +173,7 @@ urlReq(piston, function (body, res) {
var mcmeta = __dirname + "/template/pack.mcmeta";
var mcmeta_data = JSON.parse(fs.readFileSync(mcmeta));
var mcmeta_data_old = fs.readFileSync(mcmeta);
mcmeta_data.pack.description = mcmeta_template;
fs.writeFileSync(mcmeta, JSON.stringify(mcmeta_data));
@ -145,8 +187,10 @@ urlReq(piston, function (body, res) {
console.log(
"en_mse.json generated, creating pack and compressing.",
);
// Make sure resourcepacks folder exists
if (!fs.existsSync(__dirname +"/resourcepacks/")) {fs.mkdirSync(__dirname +"/resourcepacks/")}
const output = fs.createWriteStream(
__dirname + `/${filename}.zip`,
__dirname + `/resourcepacks/${filename}.zip`,
);
const archive = archiver("zip", {
zlib: { level: 9 }, // Sets the compression level.
@ -159,7 +203,7 @@ urlReq(piston, function (body, res) {
"language-pack archive generated with a filesize of " +
archive.pointer() +
" bytes" +
`\n(./${filename}.zip)`,
`\n(./resourcepacks/${filename}.zip)`,
);
});
archive.pipe(output);