Skip to content

Commit

Permalink
feat: create disablePrettier module option
Browse files Browse the repository at this point in the history
  • Loading branch information
ivomarsan committed Jan 3, 2025
1 parent cca440c commit a85f121
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions docs/content/1.guide/1.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export interface ModuleOptions {
* @default true
*/
experimentalRemoveNuxtDefs?: boolean;
/**
* Disable prettier formatter
* @default false
*/
disablePrettier?: boolean;
}

```
Expand Down
1 change: 1 addition & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineNuxtConfig({
nuxtTypedRouter: {
plugin: true,
pathCheck: true,
disablePrettier: false,
removeNuxtDefs: true,
ignoreRoutes: ['[...404].vue'],
},
Expand Down
1 change: 1 addition & 0 deletions src/core/config/moduleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ModuleOptionsStore {
plugin: boolean = false;
strict: boolean | StrictOptions = false;
pathCheck: boolean = true;
disablePrettier: boolean = false;
autoImport: boolean = false;
rootDir: string = '';
buildDir: string = '';
Expand Down
4 changes: 2 additions & 2 deletions src/core/fs/writeFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ export async function processPathAndWriteFile({
outDir,
}: ProcessPathAndWriteFileArgs): Promise<void> {
try {
const { rootDir } = moduleOptionStore;
const { rootDir, disablePrettier } = moduleOptionStore;

const finalOutDir = outDir ?? `.nuxt/typed-router`;
const processedOutDir = resolve(rootDir, finalOutDir);
const outputFile = resolve(process.cwd(), `${processedOutDir}/${fileName}`);
const formatedContent = await formatOutputWithPrettier(content);
const formatedContent = disablePrettier ? content : await formatOutputWithPrettier(content);

if (fs.existsSync(outputFile)) {
await writeFile(outputFile, formatedContent);
Expand Down
1 change: 1 addition & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineNuxtModule<ModuleOptions>({
plugin: false,
strict: false,
pathCheck: true,
disablePrettier: false,
removeNuxtDefs: true,
ignoreRoutes: [],
},
Expand Down

0 comments on commit a85f121

Please sign in to comment.