mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
chore: improve resolve app options
This commit is contained in:
parent
f6355ca65d
commit
978a997159
@ -1,20 +1,35 @@
|
|||||||
import { resolve } from 'path'
|
import { resolve } from 'path'
|
||||||
|
import defu from 'defu'
|
||||||
import { Builder } from './builder'
|
import { Builder } from './builder'
|
||||||
import { NuxtRoute, resolvePagesRoutes } from './pages'
|
import { NuxtRoute, resolvePagesRoutes } from './pages'
|
||||||
|
import { NormalizedConfiguration } from 'src/config'
|
||||||
|
|
||||||
export interface NuxtApp {
|
export interface NuxtApp {
|
||||||
srcDir: string
|
options: AppOptions
|
||||||
main?: string
|
main?: string
|
||||||
routes: NuxtRoute[]
|
routes: NuxtRoute[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AppOptions {
|
||||||
|
srcDir?: string
|
||||||
|
dir?: NormalizedConfiguration['dir']
|
||||||
|
extensions?: NormalizedConfiguration['extensions']
|
||||||
|
}
|
||||||
|
|
||||||
// Scan project structure
|
// Scan project structure
|
||||||
export async function resolveApp (builder: Builder, srcDir: string): Promise<NuxtApp> {
|
export async function resolveApp (builder: Builder, options: AppOptions = {}): Promise<NuxtApp> {
|
||||||
const { nuxt } = builder
|
const { nuxt } = builder
|
||||||
|
|
||||||
|
options = defu(options, {
|
||||||
|
srcDir: nuxt.options.srcDir,
|
||||||
|
dir: nuxt.options.dir,
|
||||||
|
extensions: nuxt.options.extensions
|
||||||
|
})
|
||||||
|
|
||||||
// Create base app object
|
// Create base app object
|
||||||
const app: NuxtApp = {
|
const app: NuxtApp = {
|
||||||
srcDir,
|
options,
|
||||||
|
// Overwritten by the resolvers
|
||||||
main: '',
|
main: '',
|
||||||
routes: []
|
routes: []
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ export async function generate (builder: Builder) {
|
|||||||
const { nuxt } = builder
|
const { nuxt } = builder
|
||||||
|
|
||||||
await fsExtra.mkdirp(nuxt.options.buildDir)
|
await fsExtra.mkdirp(nuxt.options.buildDir)
|
||||||
builder.app = await resolveApp(builder, nuxt.options.srcDir)
|
builder.app = await resolveApp(builder)
|
||||||
|
|
||||||
const templatesDir = join(builder.nuxt.options.appDir, '_templates')
|
const templatesDir = join(builder.nuxt.options.appDir, '_templates')
|
||||||
const appTemplates = await scanTemplates(templatesDir, templateData(builder))
|
const appTemplates = await scanTemplates(templatesDir, templateData(builder))
|
||||||
|
@ -13,14 +13,12 @@ export interface NuxtRoute {
|
|||||||
|
|
||||||
export async function resolvePagesRoutes (builder, app: NuxtApp) {
|
export async function resolvePagesRoutes (builder, app: NuxtApp) {
|
||||||
const { nuxt } = builder
|
const { nuxt } = builder
|
||||||
|
const pagesDirName = app.options.dir.pages
|
||||||
|
const extensions = app.options.extensions
|
||||||
|
|
||||||
// TODO: these variables should be overriable by app not global
|
const pagesDir = resolve(app.options.srcDir, pagesDirName)
|
||||||
const pagesDirName = nuxt.options.dir.pages
|
|
||||||
const extensions = nuxt.options.extensions
|
|
||||||
|
|
||||||
const pagesDir = resolve(app.srcDir, pagesDirName)
|
|
||||||
const pagesPattern = `${pagesDirName}/**/*.{${extensions.join(',')}}`
|
const pagesPattern = `${pagesDirName}/**/*.{${extensions.join(',')}}`
|
||||||
const files = await resolveFiles(builder, pagesPattern, app.srcDir)
|
const files = await resolveFiles(builder, pagesPattern, app.options.srcDir)
|
||||||
|
|
||||||
const routes: NuxtRoute[] = []
|
const routes: NuxtRoute[] = []
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user