import { formatPath } from "./utils/formatter.mjs";
import { buildDictionary } from "./buildIntlayerDictionary/buildIntlayerDictionary.mjs";
import { createDictionaryEntryPoint } from "./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";
import { createModuleAugmentation } from "./createType/createModuleAugmentation.mjs";
import { createTypes } from "./createType/createType.mjs";
import { loadLocalDictionaries } from "./loadDictionaries/loadLocalDictionaries.mjs";
import { getAppLogger } from "@intlayer/config";

//#region ../@intlayer/webpack/dist/esm/chokidar/dist/esm/handleAdditionalContentDeclarationFile.mjs
const handleAdditionalContentDeclarationFile = async (filePath, config) => {
	const appLogger = getAppLogger(config);
	appLogger(`Additional file detected: ${formatPath(filePath)}`, { isVerbose: true });
	const dictionariesOutput = await buildDictionary(await loadLocalDictionaries(filePath, config), config);
	await createTypes(Object.values(dictionariesOutput?.mergedDictionaries ?? {}).map((dictionary) => dictionary.dictionaryPath), config);
	await createDictionaryEntryPoint(config);
	appLogger("Dictionaries built", { isVerbose: true });
	createModuleAugmentation(config);
	appLogger("Module augmentation built", { isVerbose: true });
	for await (const plugin of config.plugins ?? []) {
		const { unmergedDictionaries, mergedDictionaries } = dictionariesOutput;
		await plugin.afterBuild?.({
			dictionaries: {
				unmergedDictionaries,
				mergedDictionaries
			},
			configuration: config
		});
	}
};

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