2020-08-17 15:25:06 +00:00
|
|
|
import { resolve } from 'path'
|
2020-08-19 12:38:18 +00:00
|
|
|
import defu from 'defu'
|
2020-08-18 17:08:06 +00:00
|
|
|
import { Builder } from './builder'
|
2020-08-18 18:34:08 +00:00
|
|
|
import { NuxtRoute, resolvePagesRoutes } from './pages'
|
2020-08-19 12:38:18 +00:00
|
|
|
import { NormalizedConfiguration } from 'src/config'
|
2020-08-17 15:25:06 +00:00
|
|
|
|
|
|
|
export interface NuxtApp {
|
2020-08-19 12:38:18 +00:00
|
|
|
options: AppOptions
|
2020-08-17 15:25:06 +00:00
|
|
|
main?: string
|
|
|
|
routes: NuxtRoute[]
|
|
|
|
}
|
|
|
|
|
2020-08-19 12:38:18 +00:00
|
|
|
interface AppOptions {
|
|
|
|
srcDir?: string
|
|
|
|
dir?: NormalizedConfiguration['dir']
|
|
|
|
extensions?: NormalizedConfiguration['extensions']
|
|
|
|
}
|
|
|
|
|
2020-08-17 15:25:06 +00:00
|
|
|
// Scan project structure
|
2020-08-19 12:38:18 +00:00
|
|
|
export async function resolveApp (builder: Builder, options: AppOptions = {}): Promise<NuxtApp> {
|
2020-08-18 17:08:06 +00:00
|
|
|
const { nuxt } = builder
|
2020-08-17 15:25:06 +00:00
|
|
|
|
2020-08-19 12:38:18 +00:00
|
|
|
options = defu(options, {
|
|
|
|
srcDir: nuxt.options.srcDir,
|
|
|
|
dir: nuxt.options.dir,
|
|
|
|
extensions: nuxt.options.extensions
|
|
|
|
})
|
|
|
|
|
2020-08-18 18:34:08 +00:00
|
|
|
// Create base app object
|
|
|
|
const app: NuxtApp = {
|
2020-08-19 12:38:18 +00:00
|
|
|
options,
|
|
|
|
// Overwritten by the resolvers
|
2020-08-18 18:34:08 +00:00
|
|
|
main: '',
|
2020-08-17 15:25:06 +00:00
|
|
|
routes: []
|
|
|
|
}
|
2020-08-18 17:08:06 +00:00
|
|
|
|
2020-08-18 18:34:08 +00:00
|
|
|
// Resolve App.vue
|
|
|
|
app.main = nuxt.resolver.tryResolvePath('~/App') ||
|
|
|
|
nuxt.resolver.tryResolvePath('~/app') ||
|
|
|
|
resolve(nuxt.options.appDir, 'app.vue')
|
2020-08-18 17:08:06 +00:00
|
|
|
|
2020-08-18 18:34:08 +00:00
|
|
|
// Resolve pages/
|
|
|
|
app.routes.push(...await resolvePagesRoutes(builder, app))
|
2020-08-18 17:08:06 +00:00
|
|
|
|
2020-08-18 18:34:08 +00:00
|
|
|
return app
|
2020-08-18 17:08:06 +00:00
|
|
|
}
|