allow user specified version

This commit is contained in:
ayaka 2024-09-02 22:16:34 +12:00
parent d65cfc22e1
commit e146afe50c
3 changed files with 67 additions and 20 deletions

1
.gitignore vendored
View File

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

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);
@ -167,6 +211,8 @@ urlReq(piston, function (body, res) {
archive.finalize();
},
);
// Revert template, yeah not a great way of doing it i know. :(
fs.writeFileSync(mcmeta, mcmeta_data_old);
},
);
});