第一次提交

This commit is contained in:
WongXX 2024-05-26 01:40:41 +08:00
commit b8ee55d237
2 changed files with 48 additions and 0 deletions

36
index.js Normal file
View File

@ -0,0 +1,36 @@
import fs from "fs"
import { join } 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);
});
});
}
// 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 (!distfilepath) {
fs.mkdirSync(distfilepath, { recursive: true });
}
fs.renameSync(join(srcpath, hash.substring(0, 2), hash), distfilepath);
});
}
main();

12
package.json Normal file
View File

@ -0,0 +1,12 @@
{
"name": "mchashtoname",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "node index.js"
},
"author": "",
"license": "ISC"
}