Skip to content

Commit

Permalink
feat: use array for ResolvedHomePage
Browse files Browse the repository at this point in the history
  • Loading branch information
KeJunMao committed May 12, 2023
1 parent 0432783 commit 6f4b3bb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
25 changes: 13 additions & 12 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ export class PageContext {
? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData))
: generatedPageMetaData

this.hasHome(result)
this.setHomePage(result)

result.sort(page => (page.type === 'home' ? -1 : 0))

return result
}

hasHome(result: PageMetaDatum[]) {
const isHome = result.some((page) => {
setHomePage(result: PageMetaDatum[]) {
const hasHome = result.some((page) => {
if (page.type === 'home')
return true

Expand All @@ -185,22 +185,23 @@ export class PageContext {
return false
})

if (isHome)
if (hasHome)
return true

const findHome = result.some((item) => {
if (this.options.homePage === item.path) {
const isFoundHome = result.some((item) => {
if (this.options.homePage.includes(item.path)) {
item.type = 'home'
return true
}
else {
return false
}
else { return false }
})

if (findHome)
return true
else console.warn('No home page found, please check the configuration of pages.config.ts')
if (isFoundHome) { return true }
else {
this.logger?.warn('No home page found, check the configuration of pages.config.ts, or add the `homePage` option to UniPages in vite.config.js, or add `type="home"` to the routeBlock of your vue page.', {
timestamp: true,
})
}
}

async mergePageMetaData() {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs'
import fs from 'node:fs'
import fg from 'fast-glob'
import { extsToGlob } from './utils'

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ResolvedOptions, UserOptions } from './types'

export function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions {
const {
homePage = 'pages/index',
homePage = ['pages/index', 'pages/index/index'],
mergePages = true,
dir = 'src/pages',
subPackages = [],
Expand All @@ -28,9 +28,10 @@ export function resolveOptions(userOptions: UserOptions, viteRoot?: string): Res
const root = viteRoot || slash(process.cwd())
const resolvedDirs = resolvePageDirs(dir, root, exclude)
const resolvedSubDirs = subPackages.map(dir => slash(dir))
const ResolvedHomePage = typeof homePage === 'string' ? [homePage] : homePage

const resolvedOptions: ResolvedOptions = {
homePage,
homePage: ResolvedHomePage,
mergePages,
dirs: resolvedDirs,
subPackages: resolvedSubDirs,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type debugType = keyof typeof debug
export interface Options {
/**
* The default application entry page is the home page
* @default 'pages/index'
* @default 'pages/index' or 'pages/index/index'
*/
homePage: string

Expand Down Expand Up @@ -75,7 +75,7 @@ export interface Options {

export type UserOptions = Partial<Options>

export interface ResolvedOptions extends Omit<Options, 'dir'> {
export interface ResolvedOptions extends Omit<Options, 'dir' | 'homePage'> {
/**
* Resolves to the `root` value from Vite config.
* @default config.root
Expand All @@ -86,7 +86,10 @@ export interface ResolvedOptions extends Omit<Options, 'dir'> {
* Resolved page dirs
*/
dirs: string[]

/**
* Resolved entry page
*/
homePage: string[]
}

export interface PagePath {
Expand Down

0 comments on commit 6f4b3bb

Please sign in to comment.