@proofkit/typegen
Version:
`@proofkit/typegen` is a tool for generating TypeScript types from FileMaker database schemas, making it easier to work with FileMaker data in modern TypeScript projects.
27 lines (22 loc) • 785 B
text/typescript
import { Project } from "ts-morph";
import { format, getFileInfo } from "prettier";
/**
* Formats all source files in a ts-morph Project using prettier and saves the changes.
* @param project The ts-morph Project containing the files to format
*/
export async function formatAndSaveSourceFiles(project: Project) {
try {
const files = project.getSourceFiles();
// run each file through the prettier formatter
for await (const file of files) {
const filePath = file.getFilePath();
const fileInfo = await getFileInfo(filePath);
if (fileInfo.ignored) continue;
const formatted = await format(file.getFullText(), {
filepath: filePath,
});
file.replaceWithText(formatted);
}
} catch (error) {}
await project.save();
}