refactor: rename formatter utilities
parent
6dabb848a5
commit
542ed6c08f
|
|
@ -37,7 +37,6 @@
|
||||||
"find-up": "catalog:",
|
"find-up": "catalog:",
|
||||||
"ora": "catalog:",
|
"ora": "catalog:",
|
||||||
"pkg-types": "catalog:",
|
"pkg-types": "catalog:",
|
||||||
"prettier": "catalog:",
|
|
||||||
"rimraf": "catalog:"
|
"rimraf": "catalog:"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import fs from 'node:fs/promises';
|
||||||
|
|
||||||
|
import { execa } from 'execa';
|
||||||
|
|
||||||
|
async function formatFile(filepath: string) {
|
||||||
|
await execa('oxfmt', [filepath], {
|
||||||
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
|
||||||
|
return await fs.readFile(filepath, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
export { formatFile };
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
export * from './constants';
|
export * from './constants';
|
||||||
export * from './date';
|
export * from './date';
|
||||||
|
export { formatFile } from './formatter';
|
||||||
export * from './fs';
|
export * from './fs';
|
||||||
export * from './git';
|
export * from './git';
|
||||||
export { getStagedFiles, add as gitAdd } from './git';
|
export { getStagedFiles, add as gitAdd } from './git';
|
||||||
export { generatorContentHash } from './hash';
|
export { generatorContentHash } from './hash';
|
||||||
export * from './monorepo';
|
export * from './monorepo';
|
||||||
export { toPosixPath } from './path';
|
export { toPosixPath } from './path';
|
||||||
export { prettierFormat } from './prettier';
|
|
||||||
export * from './spinner';
|
export * from './spinner';
|
||||||
export type { Package } from '@manypkg/get-packages';
|
export type { Package } from '@manypkg/get-packages';
|
||||||
export { default as colors } from 'chalk';
|
export { default as colors } from 'chalk';
|
||||||
|
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
import fs from 'node:fs/promises';
|
|
||||||
|
|
||||||
import { format, getFileInfo, resolveConfig } from 'prettier';
|
|
||||||
|
|
||||||
async function prettierFormat(filepath: string) {
|
|
||||||
const prettierOptions = await resolveConfig(filepath, {});
|
|
||||||
|
|
||||||
const fileInfo = await getFileInfo(filepath);
|
|
||||||
|
|
||||||
const input = await fs.readFile(filepath, 'utf8');
|
|
||||||
const output = await format(input, {
|
|
||||||
...prettierOptions,
|
|
||||||
parser: fileInfo.inferredParser as any,
|
|
||||||
});
|
|
||||||
if (output !== input) {
|
|
||||||
await fs.writeFile(filepath, output, 'utf8');
|
|
||||||
}
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
export { prettierFormat };
|
|
||||||
|
|
@ -6,10 +6,10 @@ import {
|
||||||
colors,
|
colors,
|
||||||
consola,
|
consola,
|
||||||
findMonorepoRoot,
|
findMonorepoRoot,
|
||||||
|
formatFile,
|
||||||
getPackages,
|
getPackages,
|
||||||
gitAdd,
|
gitAdd,
|
||||||
outputJSON,
|
outputJSON,
|
||||||
prettierFormat,
|
|
||||||
toPosixPath,
|
toPosixPath,
|
||||||
} from '@vben/node-utils';
|
} from '@vben/node-utils';
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ async function createCodeWorkspace({
|
||||||
const outputPath = join(monorepoRoot, CODE_WORKSPACE_FILE);
|
const outputPath = join(monorepoRoot, CODE_WORKSPACE_FILE);
|
||||||
await outputJSON(outputPath, { folders }, spaces);
|
await outputJSON(outputPath, { folders }, spaces);
|
||||||
|
|
||||||
await prettierFormat(outputPath);
|
await formatFile(outputPath);
|
||||||
if (autoCommit) {
|
if (autoCommit) {
|
||||||
await gitAdd(CODE_WORKSPACE_FILE, monorepoRoot);
|
await gitAdd(CODE_WORKSPACE_FILE, monorepoRoot);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue