mirror of
https://github.com/GayPizzaSpecifications/dough.git
synced 2025-08-05 22:41:31 +00:00
Fix nodejs support.
This commit is contained in:
@ -0,0 +1,113 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import gay.pizza.dough.core.time.UnixTime
|
||||
import gay.pizza.dough.fs.nodefs.NodeFsModule
|
||||
import kotlinx.serialization.DeserializationStrategy
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
object NodeFsOperations : FsOperations {
|
||||
override fun exists(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isDirectory(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isRegularFile(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isSymbolicLink(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isReadable(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isWritable(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun isExecutable(path: FsPath): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun lastModified(path: FsPath): UnixTime {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun list(path: FsPath): Sequence<FsPath> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun walk(path: FsPath): Sequence<FsPath> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun visit(path: FsPath, visitor: FsPathVisitor) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun readString(path: FsPath): String =
|
||||
NodeFsModule.readFileSync(path.fullPathString, "utf-8")
|
||||
|
||||
override fun readAllBytes(path: FsPath): ByteArray {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun readBytesChunked(path: FsPath, block: (ByteArray, Int) -> Unit) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun <T> readJsonFile(
|
||||
path: FsPath,
|
||||
deserializer: DeserializationStrategy<T>
|
||||
): T {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun readLines(path: FsPath): Sequence<String> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun <T> readJsonLines(
|
||||
path: FsPath,
|
||||
deserializer: DeserializationStrategy<T>
|
||||
): Sequence<T> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun writeString(path: FsPath, content: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun writeAllBytes(path: FsPath, bytes: ByteArray) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun <T> writeJsonFile(
|
||||
path: FsPath,
|
||||
serializer: SerializationStrategy<T>,
|
||||
value: T
|
||||
) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun delete(path: FsPath) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun deleteOnExit(path: FsPath) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun deleteRecursively(path: FsPath) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun createDirectories(path: FsPath) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
18
dough-fs/src/jsMain/kotlin/gay/pizza/dough/fs/NodePath.kt
Normal file
18
dough-fs/src/jsMain/kotlin/gay/pizza/dough/fs/NodePath.kt
Normal file
@ -0,0 +1,18 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import gay.pizza.dough.fs.nodefs.NodePathModule
|
||||
|
||||
class NodePath(override val fullPathString: String) : FsPath {
|
||||
override val entityNameString: String
|
||||
get() = NodePathModule.baseName(fullPathString)
|
||||
override val parent: FsPath
|
||||
get() = NodePath(fullPathString)
|
||||
override val operations: FsOperations
|
||||
get() = NodeFsOperations
|
||||
|
||||
override fun resolve(part: String): FsPath =
|
||||
NodePath(NodePathModule.resolve(fullPathString, part))
|
||||
|
||||
override fun relativeTo(path: FsPath): FsPath =
|
||||
NodePath(NodePathModule.relative(fullPathString, path.fullPathString))
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
import gay.pizza.dough.fs.nodefs.NodePathModule
|
||||
|
||||
object NodejsFsProvider : FsProvider {
|
||||
override val currentWorkingDirectory: FsPath
|
||||
get() = NodePath(NodePathModule.resolve("."))
|
||||
|
||||
override val operations: FsOperations
|
||||
get() = TODO()
|
||||
|
||||
override fun resolve(path: String): FsPath = NodePath(NodePathModule.resolve(path))
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package gay.pizza.dough.fs
|
||||
|
||||
actual val PlatformFsProvider: FsProvider = NodejsFsProvider
|
@ -0,0 +1,11 @@
|
||||
package gay.pizza.dough.fs.nodefs
|
||||
|
||||
@JsModule("node:fs")
|
||||
@JsNonModule
|
||||
external object NodeFsModule {
|
||||
@JsName("statSync")
|
||||
fun statSync(path: String): NodeFsStats
|
||||
|
||||
@JsName("readFileSync")
|
||||
fun readFileSync(path: String, encoding: String): String
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package gay.pizza.dough.fs.nodefs
|
||||
|
||||
external class NodeFsStats {
|
||||
val size: Long
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package gay.pizza.dough.fs.nodefs
|
||||
|
||||
@JsModule("node:path")
|
||||
@JsNonModule
|
||||
external object NodePathModule {
|
||||
@JsName("basename")
|
||||
fun baseName(path: String): String
|
||||
|
||||
@JsName("dirname")
|
||||
fun dirName(path: String): String
|
||||
|
||||
@JsName("resolve")
|
||||
fun resolve(vararg parts: String): String
|
||||
|
||||
@JsName("relative")
|
||||
fun relative(from: String, to: String): String
|
||||
}
|
Reference in New Issue
Block a user