Skip to content

Commit 791cfe4

Browse files
authored
fix(utils): fix path format (#37)
1 parent bdf8ab7 commit 791cfe4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/utils.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import { parse as jsonParse } from 'jsonc-parser'
77
import { normalizePath } from 'vite'
88
import type { Page, ResolvedOptions, UserOptions } from './types'
99

10+
function isCLIMode(path: string) {
11+
return path.includes('src/')
12+
}
13+
1014
export function resolveOptions(userOptions: UserOptions = {}): ResolvedOptions {
1115
return {
1216
layout: 'default',
@@ -18,11 +22,12 @@ export function resolveOptions(userOptions: UserOptions = {}): ResolvedOptions {
1822

1923
export 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

Comments
 (0)