@@ -7,6 +7,10 @@ import { parse as jsonParse } from 'jsonc-parser'
77import { normalizePath } from 'vite'
88import type { Page , ResolvedOptions , UserOptions } from './types'
99
10+ function isCLIMode ( path : string ) {
11+ return path . includes ( 'src/' )
12+ }
13+
1014export function resolveOptions ( userOptions : UserOptions = { } ) : ResolvedOptions {
1115 return {
1216 layout : 'default' ,
@@ -18,11 +22,12 @@ export function resolveOptions(userOptions: UserOptions = {}): ResolvedOptions {
1822
1923export function loadPagesJson ( path = 'src/pages.json' , cwd = process . cwd ( ) ) {
2024 let pageJsonPath = resolve ( cwd , path )
21- if ( ! existsSync ( pageJsonPath ) ) {
25+ if ( ! isCLIMode ( path ) )
2226 pageJsonPath = resolve ( cwd , 'pages.json' )
23- if ( ! existsSync ( pageJsonPath ) )
24- throw new Error ( "Can't find pages.json" )
25- }
27+
28+ if ( ! existsSync ( pageJsonPath ) )
29+ throw new Error ( 'Can\'t find pages.json' )
30+
2631 const pagesJsonRaw = readFileSync ( pageJsonPath , {
2732 encoding : 'utf-8' ,
2833 } )
@@ -49,10 +54,8 @@ export function getTarget(
4954) {
5055 if ( ! ( resolvePath . endsWith ( '.vue' ) || resolvePath . endsWith ( '.nvue' ) ) )
5156 return false
52- let isSrcMode = false
53- if ( resolvePath . startsWith ( join ( cwd , 'src' ) ) )
54- isSrcMode = true
55- const relativePath = relative ( join ( cwd , isSrcMode ? 'src' : '' ) , resolvePath )
57+
58+ const relativePath = relative ( join ( cwd , isCLIMode ( resolvePath ) ? 'src' : '' ) , resolvePath )
5659 const fileWithoutExt = path . basename (
5760 relativePath ,
5861 path . extname ( relativePath ) ,
0 commit comments