simplify
This commit is contained in:
parent
c6ff2412d1
commit
fa4f103ad4
|
|
@ -17,7 +17,7 @@
|
||||||
Commands can return one of two types:
|
Commands can return one of two types:
|
||||||
|
|
||||||
- string
|
- string
|
||||||
- { status: "ok" | "error", output: string }
|
- { error: string }
|
||||||
|
|
||||||
## Fonts
|
## Fonts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ export default function (project: string) {
|
||||||
state.project = project
|
state.project = project
|
||||||
}
|
}
|
||||||
|
|
||||||
return state?.project ? `loaded ${project}` : { status: "error", output: `failed to load ${project}` }
|
return state?.project ? `loaded ${project}` : { error: `failed to load ${project}` }
|
||||||
}
|
}
|
||||||
|
|
@ -5,13 +5,13 @@ import { appPath } from "@/webapp"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const state = Thread.getStore()
|
const state = Thread.getStore()
|
||||||
if (!state) return { status: "error", output: "no state" }
|
if (!state) return { error: "no state" }
|
||||||
|
|
||||||
const project = state.project
|
const project = state.project
|
||||||
if (!project) return { status: "error", output: "no project loaded" }
|
if (!project) return { error: "no project loaded" }
|
||||||
|
|
||||||
const root = appPath(project)
|
const root = appPath(project)
|
||||||
if (!root) return { status: "error", output: "error loading project" }
|
if (!root) return { error: "error loading project" }
|
||||||
|
|
||||||
let files: string[] = []
|
let files: string[] = []
|
||||||
|
|
||||||
|
|
@ -23,5 +23,5 @@ export default function () {
|
||||||
files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
|
files = files.filter(file => file.endsWith(`${project}.ts`) || file.endsWith(`${project}.tsx`))
|
||||||
}
|
}
|
||||||
|
|
||||||
return `* project: ${project}\n` + files.join(" ")
|
return files.join(" ")
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
import { Thread } from "@/shell"
|
import { Thread } from "@/shell"
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
return Thread.getStore()?.project || "none"
|
const state = Thread.getStore()
|
||||||
|
if (!state) return { error: "no state" }
|
||||||
|
|
||||||
|
return state?.project || "none"
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,11 @@ async function exec(cmd: string, args: string[]): Promise<["ok" | "error", strin
|
||||||
if (typeof output === "string") {
|
if (typeof output === "string") {
|
||||||
return ["ok", output]
|
return ["ok", output]
|
||||||
} else if (typeof output === "object") {
|
} else if (typeof output === "object") {
|
||||||
return [output.status || "ok", output.output]
|
if (output.error) {
|
||||||
|
return ["error", output.error]
|
||||||
|
} else {
|
||||||
|
return ["ok", JSON.stringify(output)]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return ["ok", String(output)]
|
return ["ok", String(output)]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user