ruleset-id-extractor
Version:
CLI tool to extract and convert Jumio ruleset IDs and names to CSV
77 lines (68 loc) • 1.94 kB
JavaScript
import fs from "fs";
import inquirer from "inquirer";
import { convertRulesetToCsv } from "../src/convert.js";
console.log("Jumio Ruleset to CSV Converter");
const { inputMethod } = await inquirer.prompt([
{
type: "list",
name: "inputMethod",
message: "How would you like to provide the JSON ruleset?",
choices: ["Upload from file", "Paste JSON content"],
},
]);
let jsonData = null;
if (inputMethod === "Upload from file") {
const { inputFile } = await inquirer.prompt([
{
type: "input",
name: "inputFile",
message:
"Drag & drop your Jumio JSON ruleset file here or type the full path:",
validate: (input) => {
const cleanPath = input.replace(/^['"]|['"]$/g, "");
return (
fs.existsSync(cleanPath) ||
"File not found. Please enter a valid path."
);
},
},
]);
const cleanPath = inputFile.replace(/^['"]|['"]$/g, "");
jsonData = JSON.parse(fs.readFileSync(cleanPath, "utf-8"));
} else {
const { pastedJson } = await inquirer.prompt([
{
type: "input",
name: "pastedJson",
message: "Paste your full JSON content here:",
validate: (input) => {
try {
JSON.parse(input);
return true;
} catch {
return "Invalid JSON. Please check and try again.";
}
},
},
]);
jsonData = JSON.parse(pastedJson);
}
const { outputFile } = await inquirer.prompt([
{
type: "input",
name: "outputFile",
message: "Enter a name for the output CSV file:",
default: "ruleset.csv",
},
]);
const csvFilename = outputFile.toLowerCase().endsWith(".csv")
? outputFile
: outputFile + ".csv";
try {
const csv = convertRulesetToCsv(jsonData);
fs.writeFileSync(csvFilename, csv);
console.log(`CSV file has been saved as: ${csvFilename}`);
} catch (err) {
console.error("Failed to convert:", err.message);
}