2021-05-15 20:09:52 +08:00
|
|
|
import fs from "node:fs/promises";
|
2018-05-24 15:30:45 -03:00
|
|
|
|
|
|
|
|
async function readJson(file) {
|
2021-01-09 02:09:40 +09:00
|
|
|
const data = await fs.readFile(file);
|
2018-05-24 15:30:45 -03:00
|
|
|
return JSON.parse(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function writeJson(file, content) {
|
|
|
|
|
content = JSON.stringify(content, null, 2);
|
2021-01-09 02:09:40 +09:00
|
|
|
return fs.writeFile(file, content);
|
2018-05-24 15:30:45 -03:00
|
|
|
}
|
|
|
|
|
|
2018-05-29 00:22:59 -06:00
|
|
|
async function copyFile(from, to) {
|
2021-01-09 02:09:40 +09:00
|
|
|
const data = await fs.readFile(from);
|
|
|
|
|
return fs.writeFile(to, data);
|
2018-05-29 00:22:59 -06:00
|
|
|
}
|
|
|
|
|
|
2021-05-15 20:09:52 +08:00
|
|
|
export { readJson, writeJson, copyFile };
|