2024-05-25 17:40:41 +00:00
|
|
|
|
import fs from "fs"
|
2024-05-25 18:06:34 +00:00
|
|
|
|
import { join, dirname } from "path"
|
2024-05-25 17:40:41 +00:00
|
|
|
|
|
|
|
|
|
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();
|
2024-05-25 17:53:38 +00:00
|
|
|
|
resolve(data.substring(0, data.length - 2));
|
2024-05-25 17:40:41 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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"));
|
|
|
|
|
|
2024-06-02 07:39:01 +00:00
|
|
|
|
json.forEach(element => {
|
|
|
|
|
let hash = element.hash;
|
2024-05-25 18:32:12 +00:00
|
|
|
|
let srcfilepath = join(srcpath, hash.substring(0, 2), hash);
|
2024-06-02 07:39:01 +00:00
|
|
|
|
let distfilepath = join(distpath, element.path);
|
2024-05-25 18:32:12 +00:00
|
|
|
|
|
2024-05-25 17:57:47 +00:00
|
|
|
|
if (!fs.existsSync(distfilepath)) {
|
2024-05-25 18:06:34 +00:00
|
|
|
|
fs.mkdirSync(dirname(distfilepath), { recursive: true });
|
2024-05-25 17:40:41 +00:00
|
|
|
|
}
|
2024-05-25 18:32:12 +00:00
|
|
|
|
|
|
|
|
|
if (fs.existsSync(srcfilepath)) {
|
|
|
|
|
fs.copyFileSync(srcfilepath, distfilepath);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`文件不存在:${srcfilepath}`)
|
|
|
|
|
}
|
2024-05-25 17:40:41 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|