import { parallelize } from "../utils/parallelize.mjs";
import { resolve } from "node:path";
import { mkdir, writeFile } from "node:fs/promises";
import { clearModuleCache, getProjectRequire } from "@intlayer/config";

//#region ../@intlayer/webpack/dist/esm/chokidar/dist/esm/createType/createType.mjs
const generateTypeScriptType = (dictionary) => {
	return `/* eslint-disable */\nexport default ${JSON.stringify(dictionary, null, 2)} as const;\n`;
};
/**
* This function generates a TypeScript type definition from a JSON object
*/
const createTypes = async (dictionariesPaths, configuration) => {
	const { build, content } = configuration;
	const { typesDir } = content;
	await mkdir(typesDir, { recursive: true });
	return (await parallelize(dictionariesPaths, async (dictionaryPath) => {
		const requireFunction = build.require ?? getProjectRequire();
		clearModuleCache(dictionaryPath);
		const dictionary = requireFunction(dictionaryPath);
		if (!dictionary.key) return;
		const typeDefinition = generateTypeScriptType(dictionary);
		const outputPath = resolve(typesDir, `${dictionary.key}.ts`);
		await writeFile(outputPath, typeDefinition);
		return outputPath;
	})).filter(Boolean);
};

//#endregion
export { createTypes };
//# sourceMappingURL=createType.mjs.map