// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT

import promises from "node:fs/promises";
import path from "node:path";

import { distDirectory } from "./const.js";
import { convertPackFileToJSONFile } from "./json-pack-tools.js";

const packsDistDirectory = path.join(distDirectory, "packs");
const packsSourceDirectory = "packs";

console.log(`Converting pack files in ${packsDistDirectory} to json files in ${packsSourceDirectory}:`);

const conversionPromises = (await promises.readdir(packsDistDirectory, { withFileTypes: true }))
    .filter((dirent) => dirent.isFile() && path.extname(dirent.name) === ".db")
    .map(async (dirent) => convertPackFileToJSONFile(path.join(packsDistDirectory, dirent.name), packsSourceDirectory));

await Promise.all(conversionPromises);