-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathformat.mts
More file actions
25 lines (21 loc) · 747 Bytes
/
format.mts
File metadata and controls
25 lines (21 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { IndentationText, NewLineKind, Project, QuoteKind } from "ts-morph";
export const formatOutput = async (outputPath: string) => {
const project = new Project({
skipAddingFilesFromTsConfig: true,
manipulationSettings: {
indentationText: IndentationText.TwoSpaces,
newLineKind: NewLineKind.LineFeed,
quoteKind: QuoteKind.Double,
usePrefixAndSuffixTextForRename: false,
useTrailingCommas: true,
},
});
const sourceFiles = project.addSourceFilesAtPaths(`${outputPath}/**/*`);
const tasks = sourceFiles.map((sourceFile) => {
sourceFile.formatText();
sourceFile.fixMissingImports();
sourceFile.organizeImports();
return sourceFile.save();
});
await Promise.all(tasks);
};