-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Scala.js support for completions install on node
- Loading branch information
1 parent
daab94d
commit 8db890b
Showing
14 changed files
with
472 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
core/js/src/main/scala/caseapp/core/app/PlatformCommandsMethods.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package caseapp.core.app.nio | ||
|
||
object File { | ||
def separator = Path.nodePath.sep.asInstanceOf[String] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package caseapp.core.app.nio | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.Dynamic.{global => g} | ||
|
||
object FileOps { | ||
|
||
private lazy val nodeFs = g.require("fs") | ||
private lazy val nodeOs = g.require("os") | ||
private lazy val nodeProcess = g.require("process") | ||
|
||
def readFile(path: Path): String = | ||
nodeFs.readFileSync(path.underlying, js.Dictionary("encoding" -> "utf8")).asInstanceOf[String] | ||
def writeFile(path: Path, content: String): Unit = | ||
nodeFs.writeFileSync(path.underlying, content) | ||
def appendToFile(path: Path, content: String): Unit = | ||
nodeFs.writeFileSync(path.underlying, content, js.Dictionary("mode" -> "a")) | ||
def readEnv(varName: String): Option[String] = | ||
nodeProcess.env.asInstanceOf[js.Dictionary[String]].get(varName) | ||
def homeDir: Path = | ||
Paths.get(nodeOs.homedir().asInstanceOf[String]) | ||
|
||
def createDirectories(path: Path): Unit = | ||
nodeFs.mkdirSync(path.underlying, js.Dictionary("recursive" -> true)) | ||
|
||
// simple aliases, to avoid explicit imports of Files, | ||
// which might point to _root_.java.nio.file.Files or _root_.caseapp.core.app.nio.Files | ||
def exists(path: Path): Boolean = | ||
Files.exists(path) | ||
def isRegularFile(path: Path): Boolean = | ||
Files.isRegularFile(path) | ||
def deleteIfExists(path: Path): Boolean = | ||
Files.deleteIfExists(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package caseapp.core.app.nio | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.Dynamic.{global => g} | ||
|
||
object Files { | ||
|
||
def exists(path: Path): Boolean = | ||
nodeFs.existsSync(path.underlying).asInstanceOf[Boolean] | ||
def createDirectories(path: Path): Unit = | ||
nodeFs.mkdirSync(path.underlying, js.Dictionary("recursive" -> true)) | ||
def isRegularFile(path: Path): Boolean = | ||
exists(path) && nodeFs.statSync(path.underlying).isFile().asInstanceOf[Boolean] | ||
def deleteIfExists(path: Path): Boolean = { | ||
nodeFs.rmSync(path.underlying, js.Dictionary("recursive" -> true)) | ||
true | ||
} | ||
|
||
private lazy val nodeFs = g.require("fs") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package caseapp.core.app.nio | ||
|
||
import scala.scalajs.js | ||
import scala.scalajs.js.Dynamic.{global => g} | ||
|
||
final case class Path(underlying: String) { | ||
import Path.nodePath | ||
def resolve(chunk: String): Path = | ||
Path(nodePath.join(underlying, chunk).asInstanceOf[String]) | ||
def getFileName: Path = | ||
Path(nodePath.basename(underlying).asInstanceOf[String]) | ||
def getParent: Path = | ||
Path(nodePath.join(underlying, "..").asInstanceOf[String]) | ||
override def toString: String = underlying | ||
} | ||
|
||
object Path { | ||
private[nio] lazy val nodePath = g.require("path") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package caseapp.core.app.nio | ||
|
||
object Paths { | ||
def get(path: String): Path = | ||
Path(path) | ||
} |
219 changes: 0 additions & 219 deletions
219
core/jvm-native/src/main/scala/caseapp/core/app/PlatformCommandsMethods.scala
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
core/jvm-native/src/main/scala/caseapp/core/app/nio/FileOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package caseapp.core.app.nio | ||
|
||
import java.nio.charset.StandardCharsets | ||
import java.nio.file.{FileAlreadyExistsException, Files, Path, Paths, StandardOpenOption} | ||
|
||
object FileOps { | ||
|
||
def readFile(path: Path): String = | ||
new String(Files.readAllBytes(path), StandardCharsets.UTF_8) | ||
def writeFile(path: Path, content: String): Unit = | ||
Files.write(path, content.getBytes(StandardCharsets.UTF_8)) | ||
def appendToFile(path: Path, content: String): Unit = | ||
Files.write(path, content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND) | ||
def readEnv(varName: String): Option[String] = | ||
Option(System.getenv(varName)) | ||
def homeDir: Path = | ||
Paths.get(sys.props("user.home")) | ||
|
||
def createDirectories(path: Path): Unit = | ||
try Files.createDirectories(path) | ||
catch { | ||
// Ignored, see https://bugs.openjdk.java.net/browse/JDK-8130464 | ||
case _: FileAlreadyExistsException if Files.isDirectory(path) => | ||
} | ||
|
||
// simple aliases, to avoid explicit imports of Files, | ||
// which might point to _root_.java.nio.file.Files or _root_.caseapp.core.app.nio.Files | ||
def exists(path: Path): Boolean = | ||
Files.exists(path) | ||
def isRegularFile(path: Path): Boolean = | ||
Files.isRegularFile(path) | ||
def deleteIfExists(path: Path): Boolean = | ||
Files.deleteIfExists(path) | ||
} |
17 changes: 17 additions & 0 deletions
17
core/jvm-native/src/main/scala/caseapp/core/app/nio/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package caseapp.core.app | ||
|
||
package object nio { | ||
|
||
type Path = java.nio.file.Path | ||
|
||
object Paths { | ||
def get(path: String): Path = | ||
java.nio.file.Paths.get(path) | ||
} | ||
|
||
object File { | ||
def separator: String = | ||
java.io.File.separator | ||
} | ||
|
||
} |
Oops, something went wrong.