mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-27 20:55:25 +00:00
Move isFile into util
That allows its use in entry.ts as well.
This commit is contained in:
parent
c72c53f64d
commit
c10450c4c5
@ -1,6 +1,5 @@
|
|||||||
import { field, logger } from "@coder/logger"
|
import { field, logger } from "@coder/logger"
|
||||||
import * as cp from "child_process"
|
import * as cp from "child_process"
|
||||||
import { promises as fs } from "fs"
|
|
||||||
import http from "http"
|
import http from "http"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import { CliMessage, OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc"
|
import { CliMessage, OpenCommandPipeArgs } from "../../lib/vscode/src/vs/server/ipc"
|
||||||
@ -19,7 +18,7 @@ import {
|
|||||||
import { coderCloudBind } from "./coder-cloud"
|
import { coderCloudBind } from "./coder-cloud"
|
||||||
import { commit, version } from "./constants"
|
import { commit, version } from "./constants"
|
||||||
import { register } from "./routes"
|
import { register } from "./routes"
|
||||||
import { humanPath, open } from "./util"
|
import { humanPath, isFile, open } from "./util"
|
||||||
import { ipcMain, WrapperProcess } from "./wrapper"
|
import { ipcMain, WrapperProcess } from "./wrapper"
|
||||||
|
|
||||||
export const runVsCodeCli = (args: DefaultedArgs): void => {
|
export const runVsCodeCli = (args: DefaultedArgs): void => {
|
||||||
@ -55,21 +54,12 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
|
|||||||
forceNewWindow: args["new-window"],
|
forceNewWindow: args["new-window"],
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDir = async (path: string): Promise<boolean> => {
|
|
||||||
try {
|
|
||||||
const st = await fs.stat(path)
|
|
||||||
return st.isDirectory()
|
|
||||||
} catch (error) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < args._.length; i++) {
|
for (let i = 0; i < args._.length; i++) {
|
||||||
const fp = path.resolve(args._[i])
|
const fp = path.resolve(args._[i])
|
||||||
if (await isDir(fp)) {
|
if (await isFile(fp)) {
|
||||||
pipeArgs.folderURIs.push(fp)
|
|
||||||
} else {
|
|
||||||
pipeArgs.fileURIs.push(fp)
|
pipeArgs.fileURIs.push(fp)
|
||||||
|
} else {
|
||||||
|
pipeArgs.folderURIs.push(fp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,3 +261,12 @@ export function canConnect(path: string): Promise<boolean> {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const isFile = async (path: string): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const stat = await fs.stat(path)
|
||||||
|
return stat.isFile()
|
||||||
|
} catch (error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { field, logger } from "@coder/logger"
|
import { field, logger } from "@coder/logger"
|
||||||
import * as cp from "child_process"
|
import * as cp from "child_process"
|
||||||
import * as fs from "fs-extra"
|
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import * as path from "path"
|
import * as path from "path"
|
||||||
import * as ipc from "../../lib/vscode/src/vs/server/ipc"
|
import * as ipc from "../../lib/vscode/src/vs/server/ipc"
|
||||||
import { arrayify, generateUuid } from "../common/util"
|
import { arrayify, generateUuid } from "../common/util"
|
||||||
import { rootPath } from "./constants"
|
import { rootPath } from "./constants"
|
||||||
import { settings } from "./settings"
|
import { settings } from "./settings"
|
||||||
|
import { isFile } from "./util"
|
||||||
|
|
||||||
export class VscodeProvider {
|
export class VscodeProvider {
|
||||||
public readonly serverRootPath: string
|
public readonly serverRootPath: string
|
||||||
@ -123,15 +123,6 @@ export class VscodeProvider {
|
|||||||
private async getFirstPath(
|
private async getFirstPath(
|
||||||
startPaths: Array<{ url?: string | string[] | ipc.Query | ipc.Query[]; workspace?: boolean } | undefined>,
|
startPaths: Array<{ url?: string | string[] | ipc.Query | ipc.Query[]; workspace?: boolean } | undefined>,
|
||||||
): Promise<ipc.StartPath | undefined> {
|
): Promise<ipc.StartPath | undefined> {
|
||||||
const isFile = async (path: string): Promise<boolean> => {
|
|
||||||
try {
|
|
||||||
const stat = await fs.stat(path)
|
|
||||||
return stat.isFile()
|
|
||||||
} catch (error) {
|
|
||||||
logger.warn(error.message)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let i = 0; i < startPaths.length; ++i) {
|
for (let i = 0; i < startPaths.length; ++i) {
|
||||||
const startPath = startPaths[i]
|
const startPath = startPaths[i]
|
||||||
const url = arrayify(startPath && startPath.url).find((p) => !!p)
|
const url = arrayify(startPath && startPath.url).find((p) => !!p)
|
||||||
|
Loading…
Reference in New Issue
Block a user