-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-json.mjs
44 lines (38 loc) · 996 Bytes
/
update-json.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { readFile, writeFile } from "fs/promises";
import inquirer from "inquirer";
let readPath,
processPath,
writePath = "./output/modified.json",
data,
updateProcess;
const questions = [
{
type: "input",
default: "./data.json",
name: "readPath",
message: "Enter the path to the file that you would like to read:",
},
{
type: "list",
choices: ["jsonAddSlug"],
name: "processPath",
message: "Enter the path to the update module that you would like to use:",
},
];
await inquirer
.prompt(questions)
.then((answers) => {
readPath = answers.readPath;
processPath = `./update-processes/${answers.processPath}.mjs`;
})
.catch((error) => {
console.log(error);
});
try {
data = JSON.parse(await readFile(readPath, { endcoding: "utf8" }));
updateProcess = await import(processPath);
} catch (err) {
console.log(err);
}
const modifiedJSON = JSON.stringify(updateProcess.default(data));
writeFile(writePath, modifiedJSON);