diff --git a/bmcl.js b/bmcl.js new file mode 100644 index 0000000..82b8bc7 --- /dev/null +++ b/bmcl.js @@ -0,0 +1,42 @@ +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")); + + json.forEach(element => { + let hash = element.hash; + let srcfilepath = join(srcpath, hash.substring(0, 2), hash); + let distfilepath = join(distpath, element.path); + + if (!fs.existsSync(distfilepath)) { + fs.mkdirSync(dirname(distfilepath), { recursive: true }); + } + + if (fs.existsSync(srcfilepath)) { + fs.copyFileSync(srcfilepath, distfilepath); + } else { + console.log(`文件不存在:${srcfilepath}`) + } + }); +} + +main(); \ No newline at end of file diff --git a/index.js b/mc.js similarity index 100% rename from index.js rename to mc.js diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ceefa9e --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "mchashtoname", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "mchashtoname", + "version": "1.0.0", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json index 837609c..2e8e7fb 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "type": "module", "scripts": { - "test": "node index.js" + "mc": "node mc.js", + "bmcl": "node bmcl.js" }, "author": "", "license": "ISC"