mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor: encapsulate pages validation into a separate function (#4826)
* refactor: encapsulate pages validation into a separate function * refactor: remove else
This commit is contained in:
parent
3966b265f9
commit
e3cc28c31e
@ -193,21 +193,7 @@ export default class Builder {
|
|||||||
// Call before hook
|
// Call before hook
|
||||||
await this.nuxt.callHook('build:before', this, this.options.build)
|
await this.nuxt.callHook('build:before', this, this.options.build)
|
||||||
|
|
||||||
// Check if pages dir exists and warn if not
|
await this.validatePages()
|
||||||
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
|
||||||
if (this._nuxtPages) {
|
|
||||||
if (!fsExtra.existsSync(path.join(this.options.srcDir, this.options.dir.pages))) {
|
|
||||||
const dir = this.options.srcDir
|
|
||||||
if (fsExtra.existsSync(path.join(this.options.srcDir, '..', this.options.dir.pages))) {
|
|
||||||
throw new Error(
|
|
||||||
`No \`${this.options.dir.pages}\` directory found in ${dir}. Did you mean to run \`nuxt\` in the parent (\`../\`) directory?`
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
this._defaultPage = true
|
|
||||||
consola.warn(`No \`${this.options.dir.pages}\` directory found in ${dir}. Using the default built-in page.`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate template
|
// Validate template
|
||||||
try {
|
try {
|
||||||
@ -248,6 +234,28 @@ export default class Builder {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if pages dir exists and warn if not
|
||||||
|
async validatePages() {
|
||||||
|
this._nuxtPages = typeof this.options.build.createRoutes !== 'function'
|
||||||
|
|
||||||
|
if (
|
||||||
|
!this._nuxtPages ||
|
||||||
|
await fsExtra.exists(path.join(this.options.srcDir, this.options.dir.pages))
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const dir = this.options.srcDir
|
||||||
|
if (await fsExtra.exists(path.join(this.options.srcDir, '..', this.options.dir.pages))) {
|
||||||
|
throw new Error(
|
||||||
|
`No \`${this.options.dir.pages}\` directory found in ${dir}. Did you mean to run \`nuxt\` in the parent (\`../\`) directory?`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
this._defaultPage = true
|
||||||
|
consola.warn(`No \`${this.options.dir.pages}\` directory found in ${dir}. Using the default built-in page.`)
|
||||||
|
}
|
||||||
|
|
||||||
validateTemplate() {
|
validateTemplate() {
|
||||||
// Validate template dependencies
|
// Validate template dependencies
|
||||||
const templateDependencies = this.template.dependencies
|
const templateDependencies = this.template.dependencies
|
||||||
|
Loading…
Reference in New Issue
Block a user