MCHashtoName/index.js

36 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from "fs"
import { join, dirname } from "path"
process.stdin.setEncoding("utf8");
function readlineSync(msg = "Input") {
return new Promise((resolve, reject) => {
console.log(msg)
process.stdin.resume();
process.stdin.on("data", function (data) {
process.stdin.pause();
resolve(data.substring(0, data.length - 2));
});
});
}
// entry point
async function main() {
let jsonpath = await readlineSync("Input the JSON Path");
let srcpath = await readlineSync("Input the src Path");
let distpath = await readlineSync("Input the dist Path");
let json = JSON.parse(fs.readFileSync(jsonpath, "utf8"));
let objects = json.objects;
Object.keys(objects).forEach(element => {
let hash = objects[element].hash;
let distfilepath = join(distpath, element);
if (!fs.existsSync(distfilepath)) {
fs.mkdirSync(dirname(distfilepath), { recursive: true });
}
fs.renameSync(join(srcpath, hash.substring(0, 2), hash), distfilepath);
});
}
main();