diff --git a/packages/core/README.md b/packages/core/README.md index 944602f..b276a6c 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -114,14 +114,14 @@ export interface Options { */ routeBlockLang: 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml' - onBeforeLoadUserConfig: (ctx: PageContext) => void - onAfterLoadUserConfig: (ctx: PageContext) => void - onBeforeScanPages: (ctx: PageContext) => void - onAfterScanPages: (ctx: PageContext) => void - onBeforeMergePageMetaData: (ctx: PageContext) => void - onAfterMergePageMetaData: (ctx: PageContext) => void - onBeforeWriteFile: (ctx: PageContext) => void - onAfterWriteFile: (ctx: PageContext) => void + onBeforeLoadUserConfig: (ctx: Context) => void + onAfterLoadUserConfig: (ctx: Context) => void + onBeforeScanPages: (ctx: Context) => void + onAfterScanPages: (ctx: Context) => void + onBeforeMergePageMetaData: (ctx: Context) => void + onAfterMergePageMetaData: (ctx: Context) => void + onBeforeWriteFile: (ctx: Context) => void + onAfterWriteFile: (ctx: Context) => void } ``` diff --git a/packages/core/client.d.ts b/packages/core/client.d.ts index e5b9115..cbb33b9 100644 --- a/packages/core/client.d.ts +++ b/packages/core/client.d.ts @@ -1,9 +1,8 @@ declare module 'virtual:uni-pages' { - import type { SubPackage } from './src/config/types/index' - import type { PageMetaDatum } from './src/types' + import type { PagesJSON } from '.' - export const pages: PageMetaDatum[] - export const subPackages: SubPackage[] + export const pages: PagesJSON.Page[] + export const subPackages: PagesJSON.SubPackage[] } declare global { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts new file mode 100644 index 0000000..b7f5aa5 --- /dev/null +++ b/packages/core/src/config.ts @@ -0,0 +1,5 @@ +import type { UserPagesJson } from './types' + +export function defineUniPages(config: UserPagesJson) { + return config +} diff --git a/packages/core/src/config/index.ts b/packages/core/src/config/index.ts deleted file mode 100644 index 289239c..0000000 --- a/packages/core/src/config/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { UserPagesConfig } from './types' - -export * from './types' - -export function defineUniPages(config: UserPagesConfig) { - return config -} diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index b39b26a..b2a204b 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -1,9 +1,7 @@ import type { FSWatcher } from 'chokidar' import type { CommentObject, CommentSymbol } from 'comment-json' import type { Logger, ViteDevServer } from 'vite' -import type { TabBar, TabBarItem } from './config' -import type { PagesConfig } from './config/types' -import type { ExcludeIndexSignature, PageMetaDatum, PagePath, ResolvedOptions, SubPageMetaDatum, UserOptions } from './types' +import type { KnownKeys, PagesJSON, PathSet, ResolvedOptions, UserOptions } from './types' import fs from 'node:fs' import path from 'node:path' @@ -18,9 +16,9 @@ import detectNewline from 'detect-newline' import { loadConfig } from 'unconfig' import { OUTPUT_NAME } from './constant' import { writeDeclaration } from './declaration' -import { checkPagesJsonFileSync, getPageFiles, writeFileWithLock } from './files' +import { checkPagesJsonFileSync, getPathSets, writeFileWithLock } from './files' import { resolveOptions } from './options' -import { Page } from './page' +import { PAGE_TYPE_KEY, PageFile, TABBAR_INDEX_KEY } from './pageFile' import { debug, invalidatePagesModule, @@ -28,16 +26,16 @@ import { mergePageMetaDataArray, } from './utils' -export class PageContext { +export class Context { private _server: ViteDevServer | undefined - pagesGlobConfig: PagesConfig | undefined + pagesGlobConfig: PagesJSON.PagesJson | undefined pagesConfigSourcePaths: string[] = [] - pages = new Map() // abs path -> Page - subPages = new Map>() // root -> abs path -> page - pageMetaData: PageMetaDatum[] = [] - subPageMetaData: SubPageMetaDatum[] = [] + pageFiles = new Map() // abs path -> PageFile + subPageFiles = new Map>() // root -> abs path -> page + pages: PagesJSON.Page[] = [] + subPackages: PagesJSON.SubPackage[] = [] resolvedPagesJSONPath = '' private resolvedPagesJSONIndent?: string // ' ' @@ -75,7 +73,7 @@ export class PageContext { async loadUserPagesConfig() { const configSource = this.options.configSource - const { config, sources } = await loadConfig({ cwd: this.root, sources: configSource, defaults: {} }) + const { config, sources } = await loadConfig({ cwd: this.root, sources: configSource, defaults: {} }) this.pagesGlobConfig = config.default || config this.pagesConfigSourcePaths = sources debug.options(this.pagesGlobConfig) @@ -83,38 +81,38 @@ export class PageContext { async scanPages() { const pageDirFiles = this.options.dirs.map((dir) => { - return { dir, files: getPagePaths(dir, this.options) } + return { dir, files: getPathSets(dir, this.options) } }) const paths = pageDirFiles.map(page => page.files).flat() debug.pages(paths) - const pages = new Map() + const pageFiles = new Map() for (const path of paths) { - const page = this.pages.get(path.absolutePath) || new Page(this, path) - pages.set(path.absolutePath, page) + const page = this.pageFiles.get(path.abs) || new PageFile(this, path) + pageFiles.set(path.abs, page) } - this.pages = pages + this.pageFiles = pageFiles } async scanSubPages() { - const paths: Record = {} - const subPages = new Map>() + const paths: Record = {} + const subPageFiles = new Map>() for (const dir of this.options.subPackages) { - const pagePaths = getPagePaths(dir, this.options) + const pagePaths = getPathSets(dir, this.options) paths[dir] = pagePaths - const pages = new Map() + const pageFiles = new Map() for (const path of pagePaths) { - const page = this.subPages.get(dir)?.get(path.absolutePath) || new Page(this, path) - pages.set(path.absolutePath, page) + const page = this.subPageFiles.get(dir)?.get(path.abs) || new PageFile(this, path) + pageFiles.set(path.abs, page) } - subPages.set(dir, pages) + subPageFiles.set(dir, pageFiles) } debug.subPages(JSON.stringify(paths, null, 2)) - this.subPages = subPages + this.subPageFiles = subPageFiles } setupViteServer(server: ViteDevServer) { @@ -198,8 +196,8 @@ export class PageContext { * @param overrides custom page config * @returns pages rules */ - async parsePages(pages: Map, type: 'main' | 'sub', overrides?: PageMetaDatum[]) { - const jobs: Promise[] = [] + async parsePages(pages: Map, type: 'main' | 'sub', overrides?: PagesJSON.Page[]) { + const jobs: Promise[] = [] for (const [_, page] of pages) { jobs.push(page.getPageMeta()) } @@ -211,11 +209,11 @@ export class PageContext { : generatedPageMetaData // 使用 Map 去重,保留每个 path 的最后一个元素,同时保持较好的性能 - const parseMeta = Array.from( + const parseMeta: PagesJSON.Page[] = Array.from( result.reduce((map, page) => { map.set(page.path, page) return map - }, new Map()).values(), + }, new Map()).values(), ) return type === 'main' ? this.setHomePage(parseMeta) : parseMeta @@ -226,13 +224,13 @@ export class PageContext { * @param result pages rules array * @returns pages rules */ - setHomePage(result: PageMetaDatum[]): PageMetaDatum[] { - const hasHome = result.some(({ type }) => type === 'home') + setHomePage(result: PagesJSON.Page[]): PagesJSON.Page[] { + const hasHome = result.some(p => (p as any)[PAGE_TYPE_KEY] === 'home') if (!hasHome) { const isFoundHome = result.some((item) => { const isFound = this.options.homePage.find(v => (v === item.path)) if (isFound) - item.type = 'home' + (item as any)[PAGE_TYPE_KEY] = 'home' return isFound }) @@ -244,49 +242,45 @@ export class PageContext { } } - result.sort(page => (page.type === 'home' ? -1 : 0)) + result.sort(page => ((page as any)[PAGE_TYPE_KEY] === 'home' ? -1 : 0)) return result } async mergePageMetaData() { - const pageMetaData = await this.parsePages(this.pages, 'main', this.pagesGlobConfig?.pages) + const pages = await this.parsePages(this.pageFiles, 'main', this.pagesGlobConfig?.pages) - this.pageMetaData = pageMetaData - debug.pages(this.pageMetaData) + this.pages = pages + debug.pages(this.pages) } async mergeSubPageMetaData() { - const subPageMaps: Record = {} - const subPackages = this.pagesGlobConfig?.subPackages || [] + const subPageMaps = (this.pagesGlobConfig?.subPackages || []).reduce( + (map, item) => { + map[item.root] = item + return map + }, + {} as Record, + ) - for (const [dir, pages] of this.subPages) { + for (const [dir, pfiles] of this.subPageFiles) { const basePath = slash(path.join(this.options.root, this.options.outDir)) const root = slash(path.relative(basePath, path.join(this.options.root, dir))) - const globPackage = subPackages?.find(v => v.root === root) - subPageMaps[root] = await this.parsePages(pages, 'sub', globPackage?.pages) - subPageMaps[root] = subPageMaps[root].map(page => ({ ...page, path: slash(path.relative(root, page.path)) })) - } - - // Inherit subPackages that do not exist in the config - for (const { root, pages } of subPackages) { - if (root && !subPageMaps[root]) - subPageMaps[root] = pages || [] + const pkg = subPageMaps[root] || { root } + const pages = await this.parsePages(pfiles, 'sub', pkg.pages) + pkg.pages = pages.map(page => ({ ...page, path: slash(path.relative(root, page.path)) })) + subPageMaps[root] = pkg } - const subPageMetaData = Object.keys(subPageMaps) - .map(root => ({ root, pages: subPageMaps[root] })) - .filter(meta => meta.pages.length > 0) - - this.subPageMetaData = subPageMetaData - debug.subPages(this.subPageMetaData) + this.subPackages = Object.values(subPageMaps).filter(pkg => pkg.pages.length > 0) + debug.subPages(this.subPackages) } - private async getTabBarMerged(): Promise { - const tabBarItems: (TabBarItem & { index: number })[] = [] - for (const [_, page] of this.pages) { - const tabbar = await page.getTabBar() + private async getTabBarMerged(): Promise { + const tabBarItems: (PagesJSON.TabBarItem)[] = [] + for (const [_, pf] of this.pageFiles) { + const tabbar = await pf.getTabBar() if (tabbar) { tabBarItems.push(tabbar) } @@ -306,12 +300,15 @@ export class PageContext { pagePaths.set(item.pagePath, true) } - tabBarItems.sort((a, b) => a.index - b.index) + tabBarItems.sort((a, b) => { + const aIdx = (a as any)[TABBAR_INDEX_KEY] || 0 + const bIdx = (b as any)[TABBAR_INDEX_KEY] || 0 + return aIdx - bIdx + }) for (const item of tabBarItems) { if (!pagePaths.has(item.pagePath)) { - const { index: _, ...tabbar } = item - tabBar.list.push(tabbar) + tabBar.list.push(item) } } @@ -320,20 +317,20 @@ export class PageContext { async updatePagesJSON(filepath?: string) { if (filepath) { - let page = this.pages.get(filepath) - if (!page) { - let subPage: Page | undefined - for (const [_, pages] of this.subPages) { - subPage = pages.get(filepath) - if (subPage) { + let pageFile = this.pageFiles.get(filepath) + if (!pageFile) { + let subPageFile: PageFile | undefined + for (const [_, pageFiles] of this.subPageFiles) { + subPageFile = pageFiles.get(filepath) + if (subPageFile) { break } } - page = subPage + pageFile = subPageFile } - if (page) { - await page.read() - if (!page.hasChanged()) { + if (pageFile) { + await pageFile.read() + if (!pageFile.hasChanged()) { debug.cache(`The route block on page ${filepath} did not send any changes, skipping`) return false } @@ -359,13 +356,13 @@ export class PageContext { const pagesMap = new Map() const pages = this.withUniPlatform - ? this.pageMetaData.filter(v => !/\..*$/.test(v.path) || v.path.includes(platform)).map((v) => { + ? this.pages.filter(v => !/\..*$/.test(v.path) || v.path.includes(platform)).map((v) => { v.path = v.path.replace(/\..*$/, '') return v }) - : this.pageMetaData + : this.pages pages.forEach(v => pagesMap.set(v.path, v)) - this.pageMetaData = [...pagesMap.values()] + this.pages = [...pagesMap.values()] this.options.onBeforeWriteFile(this) @@ -399,11 +396,11 @@ export class PageContext { } resolveRoutes() { - return cjStringify(this.pageMetaData, null, 2) + return cjStringify(this.pages, null, 2) } resolveSubRoutes() { - return cjStringify(this.subPageMetaData, null, 2) + return cjStringify(this.subPackages, null, 2) } generateDeclaration() { @@ -424,15 +421,15 @@ export class PageContext { const currentPlatform = platform.toUpperCase() // pages - pageJson.pages = mergePlatformItems(oldPages as any, currentPlatform, this.pageMetaData, 'path') + pageJson.pages = mergePlatformItems(oldPages as any, currentPlatform, this.pages, 'path') // subPackages pageJson.subPackages = oldSubPackages || new CommentArray() - const newSubPackages = new Map() - for (const item of this.subPageMetaData) { + const newSubPackages = new Map() + for (const item of this.subPackages) { newSubPackages.set(item.root, item) } - for (const existing of pageJson.subPackages as unknown as SubPageMetaDatum[]) { + for (const existing of pageJson.subPackages as unknown as PagesJSON.SubPackage[]) { const sub = newSubPackages.get(existing.root) if (sub) { existing.pages = mergePlatformItems(existing.pages, currentPlatform, sub.pages, 'path') as any @@ -495,22 +492,7 @@ export class PageContext { } } -function getPagePaths(dir: string, options: ResolvedOptions) { - const pagesDirPath = slash(path.resolve(options.root, dir)) - const basePath = slash(path.join(options.root, options.outDir)) - const files = getPageFiles(pagesDirPath, options) - debug.pages(dir, files) - const pagePaths = files - .map(file => slash(file)) - .map(file => ({ - relativePath: path.relative(basePath, slash(path.resolve(pagesDirPath, file))), - absolutePath: slash(path.resolve(pagesDirPath, file)), - })) - - return pagePaths -} - -function mergePlatformItems(source: any[] | undefined, currentPlatform: string, items: T[], uniqueKeyName: keyof ExcludeIndexSignature): CommentArray { +function mergePlatformItems(source: any[] | undefined, currentPlatform: string, items: T[], uniqueKeyName: KnownKeys): CommentArray { const src = (source as CommentArray) || new CommentArray() currentPlatform = currentPlatform.toUpperCase() diff --git a/packages/core/src/declaration.ts b/packages/core/src/declaration.ts index 8938ff3..fa4de38 100644 --- a/packages/core/src/declaration.ts +++ b/packages/core/src/declaration.ts @@ -1,18 +1,18 @@ -import type { PageContext } from './context' +import type { Context } from './context' import { existsSync } from 'node:fs' import { mkdir, readFile, writeFile as writeFile_ } from 'node:fs/promises' import { dirname, join } from 'node:path' import { normalizePath } from 'vite' -export function getDeclaration(ctx: PageContext) { - const subPagesPath = ctx.subPageMetaData.map((sub) => { +export function getDeclaration(ctx: Context) { + const subPagesPath = ctx.subPackages.map((sub) => { return sub.pages.map(v => (`"/${normalizePath(join(sub.root, v.path))}"`)) }).flat() const tabsPagesPath = ctx.pagesGlobConfig?.tabBar?.list?.map((v) => { return `"/${v!.pagePath}"` }) ?? [] - const allPagesPath = [...ctx.pageMetaData.filter(page => !tabsPagesPath.includes(page.path)).map(v => `"/${v.path}"`), ...subPagesPath] + const allPagesPath = [...ctx.pages.filter(page => !tabsPagesPath.includes(page.path)).map(v => `"/${v.path}"`), ...subPagesPath] const code = `/* eslint-disable */ /* prettier-ignore */ // @ts-nocheck @@ -51,7 +51,7 @@ async function writeFile(filePath: string, content: string) { return await writeFile_(filePath, content, 'utf-8') } -export async function writeDeclaration(ctx: PageContext, filepath: string) { +export async function writeDeclaration(ctx: Context, filepath: string) { const originalContent = existsSync(filepath) ? await readFile(filepath, 'utf-8') : '' const code = getDeclaration(ctx) diff --git a/packages/core/src/files.ts b/packages/core/src/files.ts index 1185f9f..8aa427f 100644 --- a/packages/core/src/files.ts +++ b/packages/core/src/files.ts @@ -1,5 +1,7 @@ -import type { ResolvedOptions } from './types' +import type { PathSet, ResolvedOptions } from './types' import fs from 'node:fs' +import path from 'node:path' +import { slash } from '@antfu/utils' import fg from 'fast-glob' import lockfile from 'proper-lockfile' import { FILE_EXTENSIONS } from './constant' @@ -22,6 +24,21 @@ export function getPageFiles(path: string, options: ResolvedOptions): string[] { return files } +export function getPathSets(dir: string, options: ResolvedOptions): PathSet[] { + const pagesDirPath = slash(path.resolve(options.root, dir)) + const basePath = slash(path.join(options.root, options.outDir)) + const files = getPageFiles(pagesDirPath, options) + debug.pages(dir, files) + const pagePaths = files + .map(file => slash(file)) + .map(file => ({ + rel: path.relative(basePath, slash(path.resolve(pagesDirPath, file))), + abs: slash(path.resolve(pagesDirPath, file)), + })) + + return pagePaths +} + /** * 检查指定路径的 pages.json 文件,如果文件不存在或不是有效文件则创建一个空的 pages.json 文件 * @param path - 要检查的文件路径 diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index bb3f726..b4997e9 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -14,9 +14,9 @@ import { OUTPUT_NAME, RESOLVED_MODULE_ID_VIRTUAL, } from './constant' -import { PageContext } from './context' +import { Context } from './context' import { checkPagesJsonFileSync } from './files' -import { findMacro, parseSFC } from './page' +import { findMacro, parseSFC } from './pageFile' export * from './config' export * from './constant' @@ -24,12 +24,12 @@ export * from './context' export * from './customBlock' export * from './files' export * from './options' -export * from './page' +export * from './pageFile' export * from './types' export * from './utils' export function VitePluginUniPages(userOptions: UserOptions = {}): Plugin { - let ctx: PageContext + let ctx: Context // TODO: check if the pages.json file is valid const resolvedPagesJSONPath = path.join( @@ -43,7 +43,7 @@ export function VitePluginUniPages(userOptions: UserOptions = {}): Plugin { name: 'vite-plugin-uni-pages', enforce: 'pre', async configResolved(config) { - ctx = new PageContext(userOptions, config.root) + ctx = new Context(userOptions, config.root) if (config.plugins.some(v => v.name === 'vite-plugin-uni-platform')) ctx.withUniPlatform = true diff --git a/packages/core/src/options.ts b/packages/core/src/options.ts index aff5562..15d509a 100644 --- a/packages/core/src/options.ts +++ b/packages/core/src/options.ts @@ -1,6 +1,5 @@ import type { LoadConfigSource } from 'unconfig' -import type { PagesConfig } from './config' -import type { ResolvedOptions, UserOptions } from './types' +import type { PagesJSON, ResolvedOptions, UserOptions } from './types' import { resolve } from 'node:path' import process from 'node:process' import { slash } from '@antfu/utils' @@ -35,7 +34,7 @@ export function resolveOptions(userOptions: UserOptions, viteRoot: string = proc const resolvedDirs = resolvePageDirs(dir, root, exclude) const resolvedSubDirs = subPackages.map(dir => slash(dir)) const resolvedHomePage = typeof homePage === 'string' ? [homePage] : homePage - const resolvedConfigSource = typeof configSource === 'string' ? [{ files: configSource } as LoadConfigSource] : configSource + const resolvedConfigSource = typeof configSource === 'string' ? [{ files: configSource } as LoadConfigSource] : configSource const resolvedDts = !dts ? false : typeof dts === 'string' ? dts : resolve(viteRoot, 'uni-pages.d.ts') const resolvedOptions: ResolvedOptions = { diff --git a/packages/core/src/page.ts b/packages/core/src/pageFile.ts similarity index 81% rename from packages/core/src/page.ts rename to packages/core/src/pageFile.ts index c335fb5..2d1b3eb 100644 --- a/packages/core/src/page.ts +++ b/packages/core/src/pageFile.ts @@ -1,7 +1,6 @@ import type { SFCDescriptor, SFCParseOptions } from '@vue/compiler-sfc' -import type { TabBarItem } from './config' -import type { PageContext } from './context' -import type { PageMetaDatum, PagePath, RouteBlockLang, UserPageMeta } from './types' +import type { Context } from './context' +import type { PagesJSON, PathSet, RouteBlockLang, UserPageMeta } from './types' import fs from 'node:fs' import { extname } from 'node:path' import * as t from '@babel/types' @@ -12,10 +11,13 @@ import { normalizePath } from 'vite' import { getRouteBlock, getRouteSfcBlock } from './customBlock' import { babelGenerate, debug, parseCode } from './utils' -export class Page { - ctx: PageContext +export const PAGE_TYPE_KEY = Symbol.for('type') +export const TABBAR_INDEX_KEY = Symbol.for('index') - path: PagePath +export class PageFile { + ctx: Context + + path: PathSet uri: string changed: boolean = true @@ -23,26 +25,27 @@ export class Page { private raw: string = '' private meta: UserPageMeta | undefined - constructor(ctx: PageContext, path: PagePath) { + constructor(ctx: Context, path: PathSet) { this.ctx = ctx this.path = path - this.uri = normalizePath(path.relativePath.replace(extname(path.relativePath), '')) + this.uri = normalizePath(path.rel.replace(extname(path.rel), '')) } - public async getPageMeta(forceUpdate = false): Promise { + public async getPageMeta(forceUpdate = false): Promise { if (forceUpdate || !this.meta) { await this.read() } - const { path, tabBar: _, ...others } = this.meta || {} + const { path, type, tabBar: _, ...others } = this.meta || {} return { path: path ?? this.uri, ...others, + [PAGE_TYPE_KEY]: type, // 既标注了 page 的 类型,又避免序列化时会多个 key } } - public async getTabBar(forceUpdate = false): Promise { + public async getTabBar(forceUpdate = false): Promise { if (forceUpdate || !this.meta) { await this.read() } @@ -56,7 +59,7 @@ export class Page { return { ...tabBar, pagePath: tabBar.pagePath || this.uri, - index: tabBar.index || 0, + [TABBAR_INDEX_KEY]: tabBar.index || 0, } } @@ -89,8 +92,8 @@ export class Page { private async readPageMetaFromFile(): Promise { try { - const content = await fs.promises.readFile(this.path.absolutePath, { encoding: 'utf-8' }) - const sfc = parseSFC(content, { filename: this.path.absolutePath }) + const content = await fs.promises.readFile(this.path.abs, { encoding: 'utf-8' }) + const sfc = parseSFC(content, { filename: this.path.abs }) const meta = await tryPageMetaFromMacro(sfc) if (meta) { @@ -100,7 +103,7 @@ export class Page { return tryPageMetaFromCustomBlock(sfc, this.ctx.options.routeBlockLang) } catch (err: any) { - throw new Error(`Read page meta fail in ${this.path.relativePath}\n${err.message}`) + throw new Error(`Read page meta fail in ${this.path.rel}\n${err.message}`) } } } diff --git a/packages/core/src/types/index.ts b/packages/core/src/types/index.ts new file mode 100644 index 0000000..5ee764e --- /dev/null +++ b/packages/core/src/types/index.ts @@ -0,0 +1,3 @@ +export type * as PagesJSON from './uniapp' +export * from './unipages' +export * from './utils' diff --git a/packages/core/src/config/types/common.ts b/packages/core/src/types/uniapp/common.ts similarity index 100% rename from packages/core/src/config/types/common.ts rename to packages/core/src/types/uniapp/common.ts diff --git a/packages/core/src/config/types/condition.ts b/packages/core/src/types/uniapp/condition.ts similarity index 100% rename from packages/core/src/config/types/condition.ts rename to packages/core/src/types/uniapp/condition.ts diff --git a/packages/core/src/config/types/easycom.ts b/packages/core/src/types/uniapp/easycom.ts similarity index 100% rename from packages/core/src/config/types/easycom.ts rename to packages/core/src/types/uniapp/easycom.ts diff --git a/packages/core/src/config/types/globalStyle/appPlus.ts b/packages/core/src/types/uniapp/globalStyle/appPlus.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/appPlus.ts rename to packages/core/src/types/uniapp/globalStyle/appPlus.ts diff --git a/packages/core/src/config/types/globalStyle/h5.ts b/packages/core/src/types/uniapp/globalStyle/h5.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/h5.ts rename to packages/core/src/types/uniapp/globalStyle/h5.ts diff --git a/packages/core/src/config/types/globalStyle/index.ts b/packages/core/src/types/uniapp/globalStyle/index.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/index.ts rename to packages/core/src/types/uniapp/globalStyle/index.ts diff --git a/packages/core/src/config/types/globalStyle/mpAlipay.ts b/packages/core/src/types/uniapp/globalStyle/mpAlipay.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpAlipay.ts rename to packages/core/src/types/uniapp/globalStyle/mpAlipay.ts diff --git a/packages/core/src/config/types/globalStyle/mpBaidu.ts b/packages/core/src/types/uniapp/globalStyle/mpBaidu.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpBaidu.ts rename to packages/core/src/types/uniapp/globalStyle/mpBaidu.ts diff --git a/packages/core/src/config/types/globalStyle/mpJd.ts b/packages/core/src/types/uniapp/globalStyle/mpJd.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpJd.ts rename to packages/core/src/types/uniapp/globalStyle/mpJd.ts diff --git a/packages/core/src/config/types/globalStyle/mpKuaishou.ts b/packages/core/src/types/uniapp/globalStyle/mpKuaishou.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpKuaishou.ts rename to packages/core/src/types/uniapp/globalStyle/mpKuaishou.ts diff --git a/packages/core/src/config/types/globalStyle/mpLark.ts b/packages/core/src/types/uniapp/globalStyle/mpLark.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpLark.ts rename to packages/core/src/types/uniapp/globalStyle/mpLark.ts diff --git a/packages/core/src/config/types/globalStyle/mpQq.ts b/packages/core/src/types/uniapp/globalStyle/mpQq.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpQq.ts rename to packages/core/src/types/uniapp/globalStyle/mpQq.ts diff --git a/packages/core/src/config/types/globalStyle/mpToutiao.ts b/packages/core/src/types/uniapp/globalStyle/mpToutiao.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpToutiao.ts rename to packages/core/src/types/uniapp/globalStyle/mpToutiao.ts diff --git a/packages/core/src/config/types/globalStyle/mpWeixin.ts b/packages/core/src/types/uniapp/globalStyle/mpWeixin.ts similarity index 100% rename from packages/core/src/config/types/globalStyle/mpWeixin.ts rename to packages/core/src/types/uniapp/globalStyle/mpWeixin.ts diff --git a/packages/core/src/config/types/index.ts b/packages/core/src/types/uniapp/index.ts similarity index 94% rename from packages/core/src/config/types/index.ts rename to packages/core/src/types/uniapp/index.ts index 71df4d0..9323f8f 100644 --- a/packages/core/src/config/types/index.ts +++ b/packages/core/src/types/uniapp/index.ts @@ -1,15 +1,17 @@ -import type { PageMetaDatum } from '../../types' import type { Condition } from './condition' import type { EasyCom } from './easycom' import type { GlobalStyle } from './globalStyle' +import type { Pages } from './pages' import type { SubPackages } from './subPackages' import type { TabBar } from './tabBar' import type { TheWindow } from './theWindow' import type { UniIdRouter } from './uniIdRouter' +export * from './common' export * from './condition' export * from './easycom' export * from './globalStyle' +export * from './pages' export * from './subPackages' export * from './tabBar' export * from './theWindow' @@ -20,7 +22,7 @@ export * from './uniIdRouter' * * 注意定位权限申请等原属于 app.json 的内容,需要在 manifest 中配置 */ -export interface PagesConfig { +export interface PagesJson { /** * 设置默认页面的窗口表现 */ @@ -29,7 +31,7 @@ export interface PagesConfig { /** * 设置页面路径及窗口表现 */ - pages?: PageMetaDatum[] + pages?: Pages /** * 组件自动引入规则 @@ -143,5 +145,3 @@ export interface PagesConfig { [x: string]: any } - -export interface UserPagesConfig extends PagesConfig {} diff --git a/packages/core/src/types/uniapp/pages.ts b/packages/core/src/types/uniapp/pages.ts new file mode 100644 index 0000000..3b51d0a --- /dev/null +++ b/packages/core/src/types/uniapp/pages.ts @@ -0,0 +1,23 @@ +import type { GlobalStyle } from './globalStyle' + +export interface Page { + /** + * 配置页面路径 + */ + path: string + /** + * 配置页面窗口表现,配置项参考下方 pageStyle + */ + style?: GlobalStyle + /** + * 当前页面是否需要登录才可以访问,此配置优先级高于 uniIdRouter 下的 needLogin + */ + needLogin?: boolean + + /** + * 自定义属性 + */ + [key: string]: any +} + +export type Pages = Page[] diff --git a/packages/core/src/config/types/subPackages.ts b/packages/core/src/types/uniapp/subPackages.ts similarity index 83% rename from packages/core/src/config/types/subPackages.ts rename to packages/core/src/types/uniapp/subPackages.ts index 98148f6..7bcb6e4 100644 --- a/packages/core/src/config/types/subPackages.ts +++ b/packages/core/src/types/uniapp/subPackages.ts @@ -1,4 +1,4 @@ -import type { PageMetaDatum } from '../../types' +import type { Pages } from './pages' export interface SubPackage { /** @@ -9,7 +9,7 @@ export interface SubPackage { /** * 子包由哪些页面组成,参数同 pages */ - pages: PageMetaDatum[] + pages: Pages /** * 分包插件 diff --git a/packages/core/src/config/types/tabBar.ts b/packages/core/src/types/uniapp/tabBar.ts similarity index 100% rename from packages/core/src/config/types/tabBar.ts rename to packages/core/src/types/uniapp/tabBar.ts diff --git a/packages/core/src/config/types/theWindow.ts b/packages/core/src/types/uniapp/theWindow.ts similarity index 100% rename from packages/core/src/config/types/theWindow.ts rename to packages/core/src/types/uniapp/theWindow.ts diff --git a/packages/core/src/config/types/uniIdRouter.ts b/packages/core/src/types/uniapp/uniIdRouter.ts similarity index 100% rename from packages/core/src/config/types/uniIdRouter.ts rename to packages/core/src/types/uniapp/uniIdRouter.ts diff --git a/packages/core/src/types.ts b/packages/core/src/types/unipages.ts similarity index 59% rename from packages/core/src/types.ts rename to packages/core/src/types/unipages.ts index 0a68ca1..25d977a 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types/unipages.ts @@ -1,20 +1,19 @@ import type { CommentJSONValue } from 'comment-json' import type { LoadConfigSource } from 'unconfig' -import type { GlobalStyle, PagesConfig, TabBarItem } from './config' -import type { PageContext } from './context' -import type { debug } from './utils' +import type { Context } from '../context' +import type { debug } from '../utils' +import type * as PagesJSON from './uniapp' +import type { DeepPartial, MaybePromiseCallable } from './utils' export interface CustomBlock { attr: Record content: Record | CommentJSONValue } -export type debugType = keyof typeof debug - -export type ConfigSource = string | LoadConfigSource | LoadConfigSource[] - export type RouteBlockLang = 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml' +export type ConfigSource = string | LoadConfigSource | LoadConfigSource[] + export interface Options { /** @@ -82,16 +81,16 @@ export interface Options { /** * enable debug log */ - debug: boolean | debugType + debug: boolean | keyof typeof debug - onBeforeLoadUserConfig: (ctx: PageContext) => void - onAfterLoadUserConfig: (ctx: PageContext) => void - onBeforeScanPages: (ctx: PageContext) => void - onAfterScanPages: (ctx: PageContext) => void - onBeforeMergePageMetaData: (ctx: PageContext) => void - onAfterMergePageMetaData: (ctx: PageContext) => void - onBeforeWriteFile: (ctx: PageContext) => void - onAfterWriteFile: (ctx: PageContext) => void + onBeforeLoadUserConfig: (ctx: Context) => void + onAfterLoadUserConfig: (ctx: Context) => void + onBeforeScanPages: (ctx: Context) => void + onAfterScanPages: (ctx: Context) => void + onBeforeMergePageMetaData: (ctx: Context) => void + onAfterMergePageMetaData: (ctx: Context) => void + onBeforeWriteFile: (ctx: Context) => void + onAfterWriteFile: (ctx: Context) => void } export type UserOptions = Partial @@ -114,41 +113,15 @@ export interface ResolvedOptions extends Omit[] + configSource: LoadConfigSource[] } -export interface PagePath { - relativePath: string - absolutePath: string +export interface PathSet { + rel: string + abs: string } -export interface PageMetaDatum { - /** - * 配置页面路径 - */ - path: string - type?: string - /** - * 配置页面窗口表现,配置项参考下方 pageStyle - */ - style?: GlobalStyle - /** - * 当前页面是否需要登录才可以访问,此配置优先级高于 uniIdRouter 下的 needLogin - */ - needLogin?: boolean - [x: string]: any -} - -export type ExcludeIndexSignature = { - [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] -} - -export interface SubPageMetaDatum { - root: string - pages: PageMetaDatum[] -} - -export interface UserTabBarItem extends Partial { +export interface UserTabBarItem extends Partial { /** * 配置页面路径 * @deprecated 可选,将会根据文件路径自动生成 @@ -161,7 +134,13 @@ export interface UserTabBarItem extends Partial { index?: number } -export interface UserPageMeta extends Partial { +export interface UserPageMeta extends Partial { + + /** + * 标识 page 类型 + */ + type?: 'page' | 'home' + /** * 配置页面路径 * @deprecated 可选,将会根据文件路径自动生成 @@ -174,9 +153,7 @@ export interface UserPageMeta extends Partial { tabBar?: UserTabBarItem } -export type MaybePromise = T | Promise -export type MaybeCallable = T | (() => T) -export type MaybePromiseCallable = T | (() => T) | (() => Promise) +export type UserPagesJson = DeepPartial export declare function definePage(options: MaybePromiseCallable): void diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts new file mode 100644 index 0000000..7f2737e --- /dev/null +++ b/packages/core/src/types/utils.ts @@ -0,0 +1,15 @@ +export type MaybePromise = T | Promise +export type MaybeCallable = T | (() => T) +export type MaybePromiseCallable = T | (() => T) | (() => Promise) + +export type ExcludeIndexSignature = { + [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] +} + +export type KnownKeys = keyof ExcludeIndexSignature + +export type DeepPartial = T extends Array + ? Array> + : T extends object + ? { [P in keyof T]?: DeepPartial } + : T diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 9933836..c84c070 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -1,5 +1,5 @@ import type { ModuleNode, ViteDevServer } from 'vite' -import type { PageMetaDatum } from './types' +import type { PagesJSON } from './types' import { createRequire } from 'node:module' import path from 'node:path' import vm from 'node:vm' @@ -46,9 +46,9 @@ export function isTargetFile(path: string) { * @param pageMetaData page meta data array * TODO: support merge middleware */ -export function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]) { +export function mergePageMetaDataArray(pageMetaData: PagesJSON.Page[]) { const pageMetaDataObj = groupBy(pageMetaData, 'path') - const result: PageMetaDatum[] = [] + const result: PagesJSON.Page[] = [] for (const path in pageMetaDataObj) { const _pageMetaData = pageMetaDataObj[path] const options = _pageMetaData[0] diff --git a/packages/schema/package.json b/packages/schema/package.json index 40bbe73..a9e0d3a 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -25,7 +25,7 @@ "jsonschema" ], "scripts": { - "build": "ts-json-schema-generator -p \"../core/src/config/types/index.ts\" -t \"PagesConfig\" -o \"schema.json\" --no-type-check", + "build": "ts-json-schema-generator -p \"../core/src/types/index.ts\" -t \"PagesJson\" -o \"schema.json\" --no-type-check", "prepublishOnly": "pnpm build" }, "devDependencies": { diff --git a/packages/schema/schema.json b/packages/schema/schema.json index 904f5bd..a32c6b0 100644 --- a/packages/schema/schema.json +++ b/packages/schema/schema.json @@ -1,5 +1,5 @@ { - "$ref": "#/definitions/PagesConfig", + "$ref": "#/definitions/PagesJson", "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "AnimationType": { @@ -2680,7 +2680,10 @@ }, "type": "object" }, - "PageMetaDatum": { + "Page": { + "additionalProperties": { + "description": "自定义属性" + }, "properties": { "needLogin": { "description": "当前页面是否需要登录才可以访问,此配置优先级高于 uniIdRouter 下的 needLogin", @@ -2693,9 +2696,6 @@ "style": { "$ref": "#/definitions/GlobalStyle", "description": "配置页面窗口表现,配置项参考下方 pageStyle" - }, - "type": { - "type": "string" } }, "required": [ @@ -2703,7 +2703,13 @@ ], "type": "object" }, - "PagesConfig": { + "Pages": { + "items": { + "$ref": "#/definitions/Page" + }, + "type": "array" + }, + "PagesJson": { "description": "对 uni-app 进行全局配置,决定页面文件的路径、窗口样式、原生的导航栏、底部的原生 tabBar 等,类似微信小程序中 app.json 的页面管理部分\n\n注意定位权限申请等原属于 app.json 的内容,需要在 manifest 中配置", "properties": { "condition": { @@ -2727,11 +2733,8 @@ "description": "大屏左侧窗口" }, "pages": { - "description": "设置页面路径及窗口表现", - "items": { - "$ref": "#/definitions/PageMetaDatum" - }, - "type": "array" + "$ref": "#/definitions/Pages", + "description": "设置页面路径及窗口表现" }, "preloadRule": { "additionalProperties": { @@ -2825,22 +2828,19 @@ "additionalProperties": false, "properties": { "pages": { - "description": "子包由哪些页面组成,参数同 pages", - "items": { - "$ref": "#/definitions/PageMetaDatum" - }, - "type": "array" + "$ref": "#/definitions/Pages", + "description": "子包由哪些页面组成,参数同 pages" }, "plugins": { "additionalProperties": { "properties": { - "provider": { + "export": { "type": "string" }, - "version": { + "provider": { "type": "string" }, - "export": { + "version": { "type": "string" } }, @@ -3005,9 +3005,6 @@ "type": "string" } }, - "required": [ - "list" - ], "type": "object" }, "TabBarIconFont": { @@ -3285,4 +3282,4 @@ "type": "object" } } -} \ No newline at end of file +} diff --git a/packages/volar/src/schema.ts b/packages/volar/src/schema.ts index b7ce351..b46180f 100644 --- a/packages/volar/src/schema.ts +++ b/packages/volar/src/schema.ts @@ -1,6 +1,6 @@ import pagesJsonSchema from '@uni-helper/pages-json-schema/schema.json' -pagesJsonSchema.$ref = '#/definitions/PageMetaDatum' -pagesJsonSchema.definitions.PageMetaDatum.required = [] +pagesJsonSchema.$ref = '#/definitions/Page' +pagesJsonSchema.definitions.Page.required = [] export const schema = pagesJsonSchema diff --git a/test/generate.spec.ts b/test/generate.spec.ts index c5f5064..903bd13 100644 --- a/test/generate.spec.ts +++ b/test/generate.spec.ts @@ -1,8 +1,8 @@ -import type { UserPagesConfig } from '../packages/core/src' +import type { PagesJson, UserPagesJson } from '../packages/core/src' import { describe, expect, it } from 'vitest' -import { PageContext } from '../packages/core/src' +import { Context } from '../packages/core/src' -const pagesGlobConfig: UserPagesConfig = { +const pagesGlobConfig: UserPagesJson = { globalStyle: { navigationBarTextStyle: 'black', navigationBarTitleText: 'uni-helper', @@ -23,7 +23,7 @@ const pagesGlobConfig: UserPagesConfig = { describe('generate routes', () => { it('vue - pages snapshot', async () => { - const ctx = new PageContext({ dir: 'packages/playground/src/pages', homePage: 'pages/index' }) + const ctx = new Context({ dir: 'packages/playground/src/pages', homePage: 'pages/index' }) await ctx.scanPages() await ctx.mergePageMetaData() const routes = ctx.resolveRoutes() @@ -31,19 +31,16 @@ describe('generate routes', () => { expect(routes).toMatchInlineSnapshot(` "[ { - "path": "../packages/playground/src/pages/A-top", - "type": "page" + "path": "../packages/playground/src/pages/A-top" }, { "path": "../packages/playground/src/pages/i18n", - "type": "page", "style": { "navigationBarTitleText": "%app.name%" } }, { "path": "../packages/playground/src/pages/index", - "type": "page", "middlewares": [ "auth", "test" @@ -51,7 +48,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-json", - "type": "page", "style": { "navigationBarTitleText": "test json page" }, @@ -61,7 +57,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-jsonc-with-comment", - "type": "page", "style": { // #ifdef H5 "navigationBarTitleText": "test jsonc page H5" @@ -71,7 +66,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-yaml", - "type": "page", "style": { "navigationBarTitleText": "test yaml page" }, @@ -81,7 +75,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test", - "type": "page", "style": { "navigationBarTitleText": "test page" }, @@ -90,16 +83,13 @@ describe('generate routes', () => { ] }, { - "path": "../packages/playground/src/pages/blog/index", - "type": "page" + "path": "../packages/playground/src/pages/blog/index" }, { - "path": "../packages/playground/src/pages/blog/post", - "type": "page" + "path": "../packages/playground/src/pages/blog/post" }, { "path": "../packages/playground/src/pages/define-page/async-function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -109,7 +99,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/conditional-compilation", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -119,7 +108,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -129,7 +117,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/nested-function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -139,7 +126,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/object", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -149,21 +135,18 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/option-api", - "type": "page", "style": { "navigationBarTitleText": "Option API 内使用 definePage" } }, { "path": "../packages/playground/src/pages/define-page/remove-console", - "type": "page", "style": { "navigationBarTitleText": "this is a title" } }, { "path": "../packages/playground/src/pages/define-page/yaml", - "type": "page", "style": { "navigationBarTitleText": "yaml test" } @@ -173,9 +156,9 @@ describe('generate routes', () => { }) it('vue - not merge pages snapshot', async () => { - const ctx = new PageContext({ dir: 'packages/playground/src/pages', mergePages: false }) + const ctx = new Context({ dir: 'packages/playground/src/pages', mergePages: false }) await ctx.scanPages() - ctx.pagesGlobConfig = pagesGlobConfig + ctx.pagesGlobConfig = pagesGlobConfig as PagesJson await ctx.mergePageMetaData() const routes = ctx.resolveRoutes() @@ -191,19 +174,16 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/A-top", - "type": "page", "style": {} }, { "path": "../packages/playground/src/pages/i18n", - "type": "page", "style": { "navigationBarTitleText": "%app.name%" } }, { "path": "../packages/playground/src/pages/index", - "type": "page", "style": {}, "middlewares": [ "auth", @@ -212,7 +192,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-json", - "type": "page", "style": { "navigationBarTitleText": "test json page" }, @@ -222,7 +201,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-jsonc-with-comment", - "type": "page", "style": { // #ifdef H5 "navigationBarTitleText": "test jsonc page H5" @@ -232,7 +210,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test-yaml", - "type": "page", "style": { "navigationBarTitleText": "test yaml page" }, @@ -242,7 +219,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/test", - "type": "page", "style": { "navigationBarTitleText": "test page" }, @@ -252,17 +228,14 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/blog/index", - "type": "page", "style": {} }, { "path": "../packages/playground/src/pages/blog/post", - "type": "page", "style": {} }, { "path": "../packages/playground/src/pages/define-page/async-function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -272,7 +245,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/conditional-compilation", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -282,7 +254,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -292,7 +263,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/nested-function", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -302,7 +272,6 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/object", - "type": "page", "style": { "navigationBarTitleText": "hello world" }, @@ -312,21 +281,18 @@ describe('generate routes', () => { }, { "path": "../packages/playground/src/pages/define-page/option-api", - "type": "page", "style": { "navigationBarTitleText": "Option API 内使用 definePage" } }, { "path": "../packages/playground/src/pages/define-page/remove-console", - "type": "page", "style": { "navigationBarTitleText": "this is a title" } }, { "path": "../packages/playground/src/pages/define-page/yaml", - "type": "page", "style": { "navigationBarTitleText": "yaml test" } @@ -336,7 +302,7 @@ describe('generate routes', () => { }) it('fix subPackage cannot match the second-level dir', async () => { - const ctx = new PageContext({ + const ctx = new Context({ subPackages: [ 'packages/playground/src/pages-sub-pages/sub-activity', 'packages/playground/src/pages-sub-pages/sub-main', @@ -351,12 +317,10 @@ describe('generate routes', () => { "root": "../packages/playground/src/pages-sub-pages/sub-activity", "pages": [ { - "path": "pages/about/index", - "type": "page" + "path": "pages/about/index" }, { - "path": "pages/home/index", - "type": "page" + "path": "pages/home/index" } ] }, @@ -364,12 +328,10 @@ describe('generate routes', () => { "root": "../packages/playground/src/pages-sub-pages/sub-main", "pages": [ { - "path": "pages/about/index", - "type": "page" + "path": "pages/about/index" }, { - "path": "pages/home/index", - "type": "page" + "path": "pages/home/index" } ] } @@ -378,7 +340,7 @@ describe('generate routes', () => { }) it('check pages is exist', async () => { - const ctx = new PageContext({ + const ctx = new Context({ subPackages: [ 'packages/playground/src/pages-sub-empty', 'packages/playground/src/pages-sub-pages/sub-main', @@ -394,12 +356,10 @@ describe('generate routes', () => { "root": "../packages/playground/src/pages-sub-pages/sub-main", "pages": [ { - "path": "pages/about/index", - "type": "page" + "path": "pages/about/index" }, { - "path": "pages/home/index", - "type": "page" + "path": "pages/home/index" } ] }