mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-04 11:09:01 +08:00
18 lines
493 B
TypeScript
18 lines
493 B
TypeScript
import { readFileSync } from 'node:fs';
|
|
|
|
import { once } from 'lodash-es';
|
|
import { type BuiltInParserName, format } from 'prettier';
|
|
|
|
import { ProjectRoot } from './path';
|
|
|
|
const readConfig = once(() => {
|
|
const path = ProjectRoot.join('.prettierrc').value;
|
|
const config = JSON.parse(readFileSync(path, 'utf-8'));
|
|
return config;
|
|
});
|
|
|
|
export function prettier(content: string, parser: BuiltInParserName) {
|
|
const config = readConfig();
|
|
return format(content, { parser, ...config });
|
|
}
|