@@ -4,6 +4,7 @@ import rd from "rd";
44import Ajv from "ajv" ;
55import chalk from "chalk" ;
66import config from "../config" ;
7+ import readConfig from "../helper/readConfig" ;
78
89const packageConfig = {
910 type : "object" ,
@@ -18,14 +19,17 @@ const pkgConfigValidate = ajv.compile(packageConfig);
1819
1920const normalRouterReg = / p a g e s \/ ( [ a - z A - Z ] + ) \/ i n d e x .( t s x | j s | t s | j s x ) $ / ;
2021const tabRouterReg = / p a g e s \/ t a b s \/ ( [ a - z A - Z ] + ) \/ i n d e x .( t s x | j s | t s | j s x ) $ / ;
21- const packageRouterReg = / p a g e s \/ p a c k a g e s \/ ( [ a - z A - Z ] + ) \/ ( [ a - z A - Z ] + ) \/ i n d e x .( t s x | j s | t s | j s x ) $ / ;
22+ const packageRouterReg =
23+ / p a g e s \/ p a c k a g e s \/ ( [ a - z A - Z ] + ) \/ ( [ a - z A - Z ] + ) \/ i n d e x .( t s x | j s | t s | j s x ) $ / ;
2224
2325enum RouteType {
2426 NORMAL = "normal" ,
2527 TAB = "tab" ,
2628 PACKAGE = "package" ,
2729}
2830
31+ const extraConfig = readConfig ( ) ;
32+
2933export default function generateRoutes ( ) {
3034 // 获得当前执行node命令时候的文件夹目录名
3135 const commandPath = process . cwd ( ) ;
@@ -91,10 +95,11 @@ export default function generateRoutes() {
9195 routes . source [ name ] = routeUsefulPath ;
9296 routes . routeMap [ name ] = `/${ routeUsefulPath } ` ;
9397 const shortLink = name . replace ( / ( [ A - Z ] ) / g, "-$1" ) . toLowerCase ( ) ;
94- routes . customRoutes [ `/${ routeUsefulPath } ` ] =
95- `/${ shortLink . startsWith ( '-' ) ? shortLink . slice ( 1 ) : shortLink } ` ;
98+ routes . customRoutes [ `/${ routeUsefulPath } ` ] = `/${
99+ shortLink . startsWith ( "-" ) ? shortLink . slice ( 1 ) : shortLink
100+ } `;
96101 routes . names . push ( name ) ;
97- routes . pages = moveHomeToFirst ( routes . pages )
102+ routes . pages = moveHomeToFirst ( routes . pages , extraConfig . routerEntry ) ;
98103 }
99104 }
100105 } ) ;
@@ -177,17 +182,18 @@ function removeExtname(filepath: string) {
177182
178183// 入口页面置顶
179184// @ts -ignore
180- function moveHomeToFirst ( pages : string [ ] ) {
181- const pagesCopy = pages
182- const homeObject = pages . filter ( ( it ) =>
183- / h o m e | H o m e / . test ( it )
184- ) ;
185+ function moveHomeToFirst ( pages : string [ ] , entryPage ?: string ) {
186+ const entryPageReg = entryPage
187+ ? new RegExp ( `/home|Home|${ entryPage } /` )
188+ : new RegExp ( `/home|Home/` ) ;
189+ const pagesCopy = pages ;
190+ const homeObject = pages . filter ( ( it ) => entryPageReg . test ( it ) ) ;
185191 if ( homeObject . length > 0 ) {
186- const homeIndex = pages . indexOf ( homeObject [ 0 ] as string )
192+ const homeIndex = pages . indexOf ( homeObject [ 0 ] as string ) ;
187193 if ( homeIndex !== 0 ) {
188- pagesCopy . splice ( homeIndex , 1 )
194+ pagesCopy . splice ( homeIndex , 1 ) ;
189195 pagesCopy . unshift ( homeObject [ 0 ] as string ) ;
190196 }
191197 }
192- return pagesCopy
198+ return pagesCopy ;
193199}
0 commit comments