From b8ee55d237f0b9f0cdaa96e4cf99cda3b5becf5f Mon Sep 17 00:00:00 2001 From: WongXX Date: Sun, 26 May 2024 01:40:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 12 ++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 index.js create mode 100644 package.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..a8d7ab0 --- /dev/null +++ b/index.js @@ -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(); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..837609c --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "mchashtoname", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "node index.js" + }, + "author": "", + "license": "ISC" +} \ No newline at end of file