Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@zenstackhq/runtime": "workspace:*",
"langium": "1.3.1",
"lower-case-first": "^2.0.2",
"prettier": "^2.8.3 || 3.x",
"semver": "^7.5.2",
"ts-morph": "^16.0.0",
"ts-pattern": "^4.3.0",
Expand Down
31 changes: 2 additions & 29 deletions packages/sdk/src/code-gen.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import prettier from 'prettier';
import { CompilerOptions, DiagnosticCategory, ModuleKind, Project, ScriptTarget, SourceFile } from 'ts-morph';
import { CompilerOptions, DiagnosticCategory, ModuleKind, Project, ScriptTarget } from 'ts-morph';
import { PluginError } from './types';

const formatOptions = {
trailingComma: 'all',
tabWidth: 4,
printWidth: 120,
bracketSpacing: true,
semi: true,
singleQuote: true,
useTabs: false,
parser: 'typescript',
} as const;

async function formatFile(sourceFile: SourceFile) {
try {
const content = sourceFile.getFullText();
const formatted = await prettier.format(content, formatOptions);
sourceFile.replaceWithText(formatted);
await sourceFile.save();
} catch {
/* empty */
}
}

/**
* Creates a TS code generation project
*/
Expand All @@ -46,11 +23,7 @@ export function createProject(options?: CompilerOptions) {
* Persists a TS project to disk.
*/
export async function saveProject(project: Project) {
await Promise.all(
project.getSourceFiles().map(async (sf) => {
await formatFile(sf);
})
);
project.getSourceFiles().forEach((sf) => sf.formatText());
await project.save();
}

Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.