mirror of
https://github.com/GayPizzaSpecifications/dough.git
synced 2025-08-02 21:20:55 +00:00
Fix nodejs support.
This commit is contained in:
parent
24e8267449
commit
ff1c275589
@ -4,5 +4,5 @@ allprojects {
|
||||
}
|
||||
|
||||
tasks.withType<Wrapper> {
|
||||
gradleVersion = "8.0"
|
||||
gradleVersion = "8.3"
|
||||
}
|
||||
|
@ -7,6 +7,6 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10")
|
||||
implementation("org.jetbrains.kotlin:kotlin-serialization:1.8.10")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.10")
|
||||
implementation("org.jetbrains.kotlin:kotlin-serialization:1.9.10")
|
||||
}
|
||||
|
@ -23,13 +23,18 @@ tasks.withType<KotlinCompile> {
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
js {
|
||||
useCommonJs()
|
||||
|
||||
nodejs()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api("org.jetbrains.kotlin:kotlin-bom")
|
||||
api("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")
|
||||
api("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
|
||||
plugins {
|
||||
id("dough_base")
|
||||
}
|
||||
|
||||
val jvmMain = kotlin.targets.getByName<KotlinJvmTarget>("jvm").compilations.getByName("main")
|
||||
val jvmMain: KotlinJvmCompilation =
|
||||
kotlin.targets.getByName<KotlinJvmTarget>("jvm").compilations.getByName("main")
|
||||
|
||||
kotlin {
|
||||
js {
|
||||
binaries.executable()
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
val sampleJar = register<Jar>("sampleJar") {
|
||||
val sampleJar = register<Jar>("jvmSampleJar") {
|
||||
group = "application"
|
||||
|
||||
manifest {
|
||||
@ -22,7 +31,7 @@ tasks {
|
||||
})
|
||||
}
|
||||
|
||||
register<JavaExec>("runSample") {
|
||||
register<JavaExec>("jvmSampleRun") {
|
||||
group = "application"
|
||||
|
||||
mainClass.set("MainKt")
|
||||
@ -31,4 +40,7 @@ tasks {
|
||||
}
|
||||
|
||||
assemble.get().dependsOn(sampleJar)
|
||||
|
||||
val jsNodeRun = tasks.getByName("jsNodeRun") as NodeJsExec
|
||||
jsNodeRun.workingDir(projectDir)
|
||||
}
|
||||
|
@ -6,18 +6,16 @@ enum class JsPlatformType {
|
||||
Unknown;
|
||||
|
||||
companion object {
|
||||
fun current(): JsPlatformType {
|
||||
val isWindowAvailable = js("typeof window") != undefined
|
||||
val isProcessAvailable = js("typeof process") != undefined
|
||||
val current: JsPlatformType
|
||||
get() {
|
||||
val isWindowAvailable = js("typeof window") != undefined
|
||||
val isProcessAvailable = js("typeof process") != undefined
|
||||
|
||||
if (isProcessAvailable) {
|
||||
return Nodejs
|
||||
return when {
|
||||
isProcessAvailable -> Nodejs
|
||||
isWindowAvailable -> Browser
|
||||
else -> Unknown
|
||||
}
|
||||
}
|
||||
|
||||
if (isWindowAvailable) {
|
||||
return Browser
|
||||
}
|
||||
return Unknown
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,9 @@ package gay.pizza.dough.core
|
||||
|
||||
import gay.pizza.dough.core.time.ClockProvider
|
||||
import gay.pizza.dough.core.time.UnixTime
|
||||
import kotlin.js.Date
|
||||
|
||||
object StandardClockProvider : ClockProvider {
|
||||
override fun now(): UnixTime =
|
||||
UnixTime(js("(new Date()).getTime()") as Long)
|
||||
UnixTime(Date().getTime().toLong())
|
||||
}
|
||||
|
@ -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
|
||||
}
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,7 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
15
gradlew
vendored
15
gradlew
vendored
@ -83,10 +83,8 @@ done
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@ -133,10 +131,13 @@ location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
@ -197,6 +198,10 @@ if "$cygwin" || "$msys" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
|
13
samples/cat-text/build.gradle.kts
Normal file
13
samples/cat-text/build.gradle.kts
Normal file
@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
dough_sample
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
implementation(project(":dough-fs"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
samples/cat-text/hello.txt
Normal file
1
samples/cat-text/hello.txt
Normal file
@ -0,0 +1 @@
|
||||
Hello World
|
9
samples/cat-text/src/commonMain/kotlin/main.kt
Normal file
9
samples/cat-text/src/commonMain/kotlin/main.kt
Normal file
@ -0,0 +1,9 @@
|
||||
import gay.pizza.dough.fs.PlatformFsProvider
|
||||
import gay.pizza.dough.fs.readString
|
||||
|
||||
fun main() {
|
||||
val currentWorkingDirectory = PlatformFsProvider.currentWorkingDirectory
|
||||
val helloTextPath = currentWorkingDirectory.resolve("hello.txt")
|
||||
val content = helloTextPath.readString()
|
||||
println(content)
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
git ls-files -z | while IFS= read -rd '' f
|
||||
do
|
||||
if file --mime-encoding "$f" | grep -qv binary
|
||||
then
|
||||
tail -c1 < "$f" | read -r _ || echo >> "$f"
|
||||
fi
|
||||
done
|
Loading…
Reference in New Issue
Block a user