Skip to content

Commit

Permalink
fix(utils): fix path format (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skiyee authored May 21, 2024
1 parent bdf8ab7 commit 791cfe4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { parse as jsonParse } from 'jsonc-parser'
import { normalizePath } from 'vite'
import type { Page, ResolvedOptions, UserOptions } from './types'

function isCLIMode(path: string) {
return path.includes('src/')
}

export function resolveOptions(userOptions: UserOptions = {}): ResolvedOptions {
return {
layout: 'default',
Expand All @@ -18,11 +22,12 @@ export function resolveOptions(userOptions: UserOptions = {}): ResolvedOptions {

export function loadPagesJson(path = 'src/pages.json', cwd = process.cwd()) {
let pageJsonPath = resolve(cwd, path)
if (!existsSync(pageJsonPath)) {
if (!isCLIMode(path))
pageJsonPath = resolve(cwd, 'pages.json')
if (!existsSync(pageJsonPath))
throw new Error("Can't find pages.json")
}

if (!existsSync(pageJsonPath))
throw new Error('Can\'t find pages.json')

const pagesJsonRaw = readFileSync(pageJsonPath, {
encoding: 'utf-8',
})
Expand All @@ -49,10 +54,8 @@ export function getTarget(
) {
if (!(resolvePath.endsWith('.vue') || resolvePath.endsWith('.nvue')))
return false
let isSrcMode = false
if (resolvePath.startsWith(join(cwd, 'src')))
isSrcMode = true
const relativePath = relative(join(cwd, isSrcMode ? 'src' : ''), resolvePath)

const relativePath = relative(join(cwd, isCLIMode(resolvePath) ? 'src' : ''), resolvePath)
const fileWithoutExt = path.basename(
relativePath,
path.extname(relativePath),
Expand Down

0 comments on commit 791cfe4

Please sign in to comment.