import fs from 'fs'; import path from 'path'; import prettier from 'prettier'; const configPath = path.resolve(process.cwd(), 'prettierrc.js'); const prettierConfig = prettier.resolveConfig(configPath, { useCache: false, }); export async function prettierString( string: string, options?: prettier.Options, ) { return prettier.format(string, { ...(await prettierConfig), parser: 'babel', ...options, }); } export async function prettierFile( outputPath: string, options?: prettier.Options, ) { const file = fs.readFileSync(outputPath, { encoding: 'utf-8' }); const prettyFile = await prettierString(file, options); fs.writeFileSync(outputPath, prettyFile); }