Compare commits

..

3 Commits

Author SHA1 Message Date
c90e4ef042 command line arguments 2024-04-21 02:59:22 +12:00
73c06f5577 .prettierignore 2024-04-21 02:58:42 +12:00
0cfb24f1f0 edit README 2024-04-21 02:55:21 +12:00
5 changed files with 152 additions and 35 deletions

1
.prettierignore Normal file
View File

@ -0,0 +1 @@
template/pack.mcmeta

View File

@ -1,2 +1 @@
# MSE-Minecraft-Language

View File

@ -1,7 +1,11 @@
{
"main": "packgen.js",
"dependencies": {
"archiver": "^7.0.1",
"mse-translator": "https://git.stardust.wtf/iridium/MSE-Translator.git"
}
"main": "packgen.js",
"dependencies": {
"archiver": "^7.0.1",
"mse-translator": "https://git.stardust.wtf/iridium/MSE-Translator.git",
"yargs": "^17.7.2"
},
"devDependencies": {
"prettier": "3.2.5"
}
}

108
packgen.js Normal file → Executable file
View File

@ -1,20 +1,66 @@
const MSE = require('mse-translator');
const https = require('https');
const fs = require('fs');
const archiver = require('archiver');
#!/usr/bin/env node
const MSE = require("mse-translator");
const https = require("https");
const fs = require("fs");
const archiver = require("archiver");
var argv = require("yargs/yargs")(process.argv.slice(2))
.usage("\nMSE Minecraft language-pack generator \n\nUsage: $0 [options]")
.help("help")
.alias("help", "h")
.version("version", "1.0.1")
.alias("version", "V")
.options({
descriptivefile: {
alias: "f",
description: 'descriptive output E.g. "en_gb-v1.19.1-en_MSE"',
requiresArg: false,
required: false,
type: "boolean",
},
lang: {
alias: "l",
description: "<language> base language for pack generation",
requiresArg: true,
required: false,
type: "string",
},
// TODO: version: {
// alias: "v",
// description: "<version> base version for pack generation",
// requiresArg: true,
// required: false,
// type: "string",
// },
manifest: {
alias: "m",
description: "<url> custom manifest endpoint",
requiresArg: true,
required: false,
type: "string",
},
resources: {
alias: "r",
description: "<url> custom resources endpoint",
requiresArg: true,
required: false,
type: "string",
},
})
.parse();
const urlReq = function (reqUrl, options, cb) {
if (typeof options === 'function') {
if (typeof options === "function") {
cb = options;
options = {};
} // incase no options passed in
https
.get(reqUrl, (res) => {
let body = '';
res.on('data', (chunk) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on('end', () => {
res.on("end", () => {
try {
cb(body, res);
} catch (error) {
@ -22,20 +68,26 @@ const urlReq = function (reqUrl, options, cb) {
}
});
})
.on('error', (error) => {
.on("error", (error) => {
console.error(error.message);
});
};
let piston = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json';
let piston =
argv.manifest ||
"https://piston-meta.mojang.com/mc/game/version_manifest_v2.json";
urlReq(piston, function (body, res) {
json = JSON.parse(body);
let version = json.versions[0].id; // latest version
let resources = 'https://resources.download.minecraft.net/';
let baselang = 'en_gb';
//let filename = `${baselang} v${version} en_MSE`
let filename = `Maoist-Standard-English`;
let resources =
argv.resources || "https://resources.download.minecraft.net/";
let baselang = argv.lang || "en_gb";
let filename =
(argv.descriptivefile && `${baselang}-v${version}-en_MSE`) || // descriptive file name
"Maoist-Standard-English"; // default
let mcmeta_template = [
{
text: `§cen_MSE§r\n`,
@ -64,11 +116,11 @@ urlReq(piston, function (body, res) {
Object.keys(pack).forEach(function (key) {
var translated = MSE.translate(
pack[key]
.replace(/\%s/gi, '%_') //mc patch
.replace(/\$s/gi, '$_'),
.replace(/\%s/gi, "%_") //mc patch
.replace(/\$s/gi, "$_"),
)
.replace(/\%_/gi, '%s') //mc patch back
.replace(/\$_/gi, '$s');
.replace(/\%_/gi, "%s") //mc patch back
.replace(/\$_/gi, "$s");
if (translated != pack[key]) {
totals.translated = totals.translated + 1;
}
@ -78,40 +130,40 @@ urlReq(piston, function (body, res) {
`Translated ${totals.translated} out of ${totals.total} strings`,
);
var mcmeta = __dirname + '/template/pack.mcmeta';
var mcmeta = __dirname + "/template/pack.mcmeta";
var mcmeta_data = JSON.parse(fs.readFileSync(mcmeta));
mcmeta_data.pack.description = mcmeta_template;
fs.writeFileSync(mcmeta, JSON.stringify(mcmeta_data));
fs.writeFile(
__dirname +
'/template/assets/minecraft/lang/en_mse.json',
"/template/assets/minecraft/lang/en_mse.json",
JSON.stringify(pack, null, 4),
'utf8',
"utf8",
function (err) {
if (err) throw err;
console.log(
'en_mse.json generated, creating pack and compressing.',
"en_mse.json generated, creating pack and compressing.",
);
const output = fs.createWriteStream(
__dirname + `/${filename}.zip`,
);
const archive = archiver('zip', {
const archive = archiver("zip", {
zlib: { level: 9 }, // Sets the compression level.
});
archive.on('error', function (err) {
archive.on("error", function (err) {
throw err;
});
output.on('close', function () {
output.on("close", function () {
console.log(
'language-pack archive generated with a filesize of ' +
"language-pack archive generated with a filesize of " +
archive.pointer() +
' bytes' +
" bytes" +
`\n(./${filename}.zip)`,
);
});
archive.pipe(output);
archive.directory('template/', false);
archive.directory("template/", false);
archive.finalize();
},
);

View File

@ -119,6 +119,15 @@ buffer@^6.0.3:
base64-js "^1.3.1"
ieee754 "^1.2.1"
cliui@^8.0.1:
version "8.0.1"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-8.0.1.tgz#0c04b075db02cbfe60dc8e6cf2f5486b1a3608aa"
integrity sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==
dependencies:
string-width "^4.2.0"
strip-ansi "^6.0.1"
wrap-ansi "^7.0.0"
color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
@ -184,6 +193,11 @@ emoji-regex@^9.2.2:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72"
integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==
escalade@^3.1.1:
version "3.1.2"
resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27"
integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==
event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
@ -207,6 +221,11 @@ foreground-child@^3.1.0:
cross-spawn "^7.0.0"
signal-exit "^4.0.1"
get-caller-file@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==
glob@^10.0.0:
version "10.3.12"
resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.12.tgz#3a65c363c2e9998d220338e88a5f6ac97302960b"
@ -320,6 +339,11 @@ path-scurry@^1.10.2:
lru-cache "^10.2.0"
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
prettier@3.2.5:
version "3.2.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.5.tgz#e52bc3090586e824964a8813b09aba6233b28368"
integrity sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==
process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
@ -366,6 +390,11 @@ readdir-glob@^1.1.2:
dependencies:
minimatch "^5.1.0"
require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==
safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
@ -412,7 +441,7 @@ streamx@^2.15.0:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"
string-width@^4.1.0:
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@ -495,6 +524,15 @@ which@^2.0.1:
string-width "^4.1.0"
strip-ansi "^6.0.0"
wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"
wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
@ -504,6 +542,29 @@ wrap-ansi@^8.1.0:
string-width "^5.0.1"
strip-ansi "^7.0.1"
y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==
yargs-parser@^21.1.1:
version "21.1.1"
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35"
integrity sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==
yargs@^17.7.2:
version "17.7.2"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.2.tgz#991df39aca675a192b816e1e0363f9d75d2aa269"
integrity sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==
dependencies:
cliui "^8.0.1"
escalade "^3.1.1"
get-caller-file "^2.0.5"
require-directory "^2.1.1"
string-width "^4.2.3"
y18n "^5.0.5"
yargs-parser "^21.1.1"
zip-stream@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/zip-stream/-/zip-stream-6.0.1.tgz#e141b930ed60ccaf5d7fa9c8260e0d1748a2bbfb"