import { logger } from "../logger.mjs";
import { getPackageJsonPath } from "../utils/getPackageJsonPath.mjs";
import { resolve } from "node:path";
import { existsSync } from "node:fs";

//#region ../core/dist/esm/config/dist/esm/configFile/searchConfigurationFile.mjs
const EXTENSION = [
	"ts",
	"js",
	"json",
	"cjs",
	"mjs",
	""
];
const CONFIGURATION_FILE_NAME_1 = "intlayer.config";
const CONFIGURATION_FILE_NAME_2 = ".intlayerrc";
const configurationFiles = [...EXTENSION.filter((extension) => extension !== "").map((ext) => `${CONFIGURATION_FILE_NAME_1}.${ext}`), CONFIGURATION_FILE_NAME_2];
/**
* Search for the configuration file in the given path
*
* List of detected configuration files:
* - intlayer.config.ts
* - intlayer.config.js
* - intlayer.config.json
* - intlayer.config.cjs
* - intlayer.config.mjs
* - .intlayerrc
*/
const searchConfigurationFile = (startDir) => {
	let configurationFilePath;
	let numCustomConfiguration = 0;
	const { baseDir } = getPackageJsonPath(startDir);
	for (const fileName of configurationFiles) try {
		const filePath = resolve(baseDir, fileName);
		if (!existsSync(filePath)) {} else {
			numCustomConfiguration += 1;
			if (!configurationFilePath) configurationFilePath = filePath;
		}
	} catch (error) {
		logger(`${fileName}: ${error}`, { level: "error" });
	}
	return {
		configurationFilePath,
		numCustomConfiguration
	};
};

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