@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
41 lines • 1.16 kB
JavaScript
import { getAppLogger } from "@intlayer/config";
import configuration from "@intlayer/config/built";
import { relative } from "path";
const formatCode = async (filePath, code) => {
const appLogger = getAppLogger(configuration);
let prettier;
try {
prettier = require("prettier");
} catch (error) {
}
if (prettier) {
try {
const prettierConfig = await prettier.resolveConfig(filePath ?? "");
const formattedCode = await prettier.format(code, {
...prettierConfig,
filepath: filePath
// Explicitly provide the filepath so Prettier can infer the parser
});
const relativePath = relative(configuration.content.baseDir, filePath);
appLogger(`Applied Prettier formatting to ${relativePath}`, {
level: "info",
isVerbose: true
});
return formattedCode;
} catch (error) {
const err = error;
appLogger(
`Failed to apply Prettier formatting to ${filePath}: ${err.message}`,
{
level: "warn",
isVerbose: true
}
);
}
}
return code;
};
export {
formatCode
};
//# sourceMappingURL=formatCode.mjs.map