fs: implement path separator info

This commit is contained in:
Alex Zenla 2023-09-05 16:24:38 -07:00
parent 3056aa9dfc
commit 8d3cd99c46
Signed by: alex
GPG Key ID: C0780728420EBFE5
4 changed files with 10 additions and 0 deletions

View File

@ -2,5 +2,6 @@ package gay.pizza.dough.fs
interface FsProvider : FsPathResolver {
val currentWorkingDirectory: FsPath
val separator: String
val operations: FsOperations
}

View File

@ -1,8 +1,12 @@
package gay.pizza.dough.fs
import gay.pizza.dough.fs.nodefs.NodePathModule
object NodejsFsProvider : FsProvider {
override val currentWorkingDirectory: FsPath
get() = NodePath(".")
override val separator: String
get() = NodePathModule.separator
override val operations: FsOperations = NodeFsOperations

View File

@ -3,6 +3,9 @@ package gay.pizza.dough.fs.nodefs
@JsModule("node:path")
@JsNonModule
external object NodePathModule {
@JsName("sep")
val separator: String
@JsName("basename")
fun baseName(path: String): String

View File

@ -6,6 +6,8 @@ import kotlin.io.path.absolute
class JavaFsProvider(val fileSystem: FileSystem) : FsProvider {
override val currentWorkingDirectory: FsPath
get() = fileSystem.getPath(".").absolute().toFsPath()
override val separator: String
get() = fileSystem.separator
override val operations: FsOperations = JavaFsOperations