appDir
This commit is contained in:
parent
88640d7acf
commit
0202ebb217
|
|
@ -5,7 +5,7 @@ import { join, extname } from "path"
|
||||||
import type { CommandOutput } from "app/src/shared/types"
|
import type { CommandOutput } from "app/src/shared/types"
|
||||||
import { NOSE_WWW } from "app/src/config"
|
import { NOSE_WWW } from "app/src/config"
|
||||||
import { getState } from "@/session"
|
import { getState } from "@/session"
|
||||||
import { appPath } from "app/src/webapp"
|
import { appDir } from "app/src/webapp"
|
||||||
import { isBinaryFile } from "app/src/utils"
|
import { isBinaryFile } from "app/src/utils"
|
||||||
import { highlight } from "../lib/highlight"
|
import { highlight } from "../lib/highlight"
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ export default async function (path: string) {
|
||||||
const project = state.project
|
const project = state.project
|
||||||
if (!project) return { error: "no project loaded" }
|
if (!project) return { error: "no project loaded" }
|
||||||
|
|
||||||
const root = appPath(project)
|
const root = appDir(project)
|
||||||
if (!root) return { error: "error loading project" }
|
if (!root) return { error: "error loading project" }
|
||||||
|
|
||||||
let files: string[] = []
|
let files: string[] = []
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { join, extname } from "path"
|
||||||
import type { CommandOutput } from "app/src/shared/types"
|
import type { CommandOutput } from "app/src/shared/types"
|
||||||
import { NOSE_WWW } from "app/src/config"
|
import { NOSE_WWW } from "app/src/config"
|
||||||
import { getState } from "@/session"
|
import { getState } from "@/session"
|
||||||
import { appPath } from "app/src/webapp"
|
import { appDir } from "app/src/webapp"
|
||||||
import { isBinaryFile } from "app/src/utils"
|
import { isBinaryFile } from "app/src/utils"
|
||||||
import { countChar } from "app/src/shared/utils"
|
import { countChar } from "app/src/shared/utils"
|
||||||
|
|
||||||
|
|
@ -16,7 +16,7 @@ export default async function (path: string) {
|
||||||
const project = state.project
|
const project = state.project
|
||||||
if (!project) return { error: "no project loaded" }
|
if (!project) return { error: "no project loaded" }
|
||||||
|
|
||||||
const root = appPath(project)
|
const root = appDir(project)
|
||||||
if (!root) return { error: "error loading project" }
|
if (!root) return { error: "error loading project" }
|
||||||
|
|
||||||
let files: string[] = []
|
let files: string[] = []
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { readdirSync } from "fs"
|
import { readdirSync } from "fs"
|
||||||
import { NOSE_WWW } from "app/src/config"
|
import { NOSE_WWW } from "app/src/config"
|
||||||
import { getState } from "@/session"
|
import { getState } from "@/session"
|
||||||
import { appPath } from "app/src/webapp"
|
import { appDir } from "app/src/webapp"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const state = getState()
|
const state = getState()
|
||||||
|
|
@ -10,7 +10,7 @@ export default function () {
|
||||||
const project = state.project
|
const project = state.project
|
||||||
if (!project) return { error: "no project loaded" }
|
if (!project) return { error: "no project loaded" }
|
||||||
|
|
||||||
const root = appPath(project)
|
const root = appDir(project)
|
||||||
if (!root) return { error: "error loading project" }
|
if (!root) return { error: "error loading project" }
|
||||||
|
|
||||||
let files: string[] = []
|
let files: string[] = []
|
||||||
|
|
|
||||||
|
|
@ -33,20 +33,19 @@ export function apps(): string[] {
|
||||||
return apps.sort()
|
return apps.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function appPath(name: string): string | undefined {
|
export function appDir(name: string): string | undefined {
|
||||||
const path = [
|
const path = [
|
||||||
`${name}.ts`,
|
`${name}.ts`,
|
||||||
`${name}.tsx`,
|
`${name}.tsx`,
|
||||||
join(name, "index.ts"),
|
name
|
||||||
join(name, "index.tsx")
|
|
||||||
]
|
]
|
||||||
.map(path => join(NOSE_WWW, path))
|
.map(path => join(NOSE_WWW, path))
|
||||||
.flat()
|
.flat()
|
||||||
.filter(path => isFile(path))[0]
|
.filter(path => /\.tsx?$/.test(path) ? isFile(path) : isDir(path))[0]
|
||||||
|
|
||||||
if (!path) return
|
if (!path) return
|
||||||
|
|
||||||
return dirname(path)
|
return /\.tsx?$/.test(path) ? dirname(path) : path
|
||||||
}
|
}
|
||||||
|
|
||||||
async function findApp(name: string): Promise<App | undefined> {
|
async function findApp(name: string): Promise<App | undefined> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user