11import { existsSync } from 'fs'
2- import type { NuxtModule } from '@nuxt/schema'
32import { resolve } from 'pathe'
4- import {
5- defineNuxtModule ,
6- addPluginTemplate ,
7- createResolver ,
8- } from '@nuxt/kit'
3+ import { defineNuxtModule , addPluginTemplate , createResolver } from '@nuxt/kit'
94
105// Module options TypeScript interface definition
116export interface ModuleOptions {
127 configPath ?: string ,
138 builderConfigPath ?: string ,
149}
1510
16- const module : NuxtModule < ModuleOptions > = defineNuxtModule < ModuleOptions > ( {
11+ export default defineNuxtModule < ModuleOptions > ( {
1712 meta : {
1813 name : 'VueformBuilder' ,
1914 configKey : 'vueform-builder' ,
2015 compatibility : {
2116 nuxt : '^3.0.0' ,
2217 } ,
2318 } ,
19+ // Default configuration options of the Nuxt module
2420 defaults : {
2521 configPath : undefined ,
26- builderConfigPath : undefined ,
2722 } ,
28- async setup ( options , nuxt ) {
23+ async setup ( options , nuxt ) {
2924 const resolver = createResolver ( import . meta. url )
3025
3126 nuxt . hook ( 'prepare:types' , ( opts ) => {
@@ -49,33 +44,54 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
4944 ]
5045 }
5146
52- const configBase = resolve (
47+ let configBase = resolve (
5348 nuxt . options . rootDir ,
5449 options . configPath || 'vueform.config.js'
5550 )
5651
57- const builderConfigBase = resolve (
52+ let builderConfigBase = resolve (
5853 nuxt . options . rootDir ,
5954 options . builderConfigPath || 'builder.config.js'
6055 )
6156
6257 addPluginTemplate ( {
6358 async getContents ( ) {
64- const configPath = await resolver . resolvePath ( configBase )
65- const configPathExists = existsSync ( configPath )
66- const builderConfigPath = await resolver . resolvePath ( builderConfigBase )
67- const builderConfigPathExists = existsSync ( builderConfigPath )
59+ let configPath = await resolver . resolvePath ( configBase )
60+ let configPathExists = existsSync ( configPath )
6861
6962 if ( ! configPathExists ) {
70- throw new Error (
71- `Vueform configuration was not located at ${ configPath } `
63+ configBase = resolve (
64+ nuxt . options . rootDir ,
65+ 'vueform.config.ts'
7266 )
67+
68+ configPath = await resolver . resolvePath ( configBase )
69+ configPathExists = existsSync ( configPath )
70+
71+ if ( ! configPathExists ) {
72+ throw new Error (
73+ `Vueform configuration was not located at ${ configPath } `
74+ )
75+ }
7376 }
7477
78+ let builderConfigPath = await resolver . resolvePath ( builderConfigBase )
79+ let builderConfigPathExists = existsSync ( builderConfigPath )
80+
7581 if ( ! builderConfigPathExists ) {
76- throw new Error (
77- `Vueform Builder configuration was not located at ${ configPath } `
82+ builderConfigBase = resolve (
83+ nuxt . options . rootDir ,
84+ 'builder.config.ts'
7885 )
86+
87+ builderConfigPath = await resolver . resolvePath ( builderConfigBase )
88+ builderConfigPathExists = existsSync ( builderConfigPath )
89+
90+ if ( ! builderConfigPathExists ) {
91+ throw new Error (
92+ `Vueform Builder configuration was not located at ${ configPath } `
93+ )
94+ }
7995 }
8096
8197 return `import { defineNuxtPlugin } from '#imports'
@@ -95,7 +111,5 @@ const module: NuxtModule<ModuleOptions> = defineNuxtModule<ModuleOptions>({
95111 } ,
96112 filename : 'vueformBuilderPlugin.mjs' ,
97113 } )
98- } ,
114+ }
99115} )
100-
101- export default module
0 commit comments