Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to mdoc.js #741

Closed
wants to merge 17 commits into from
Closed

Migrate to mdoc.js #741

wants to merge 17 commits into from

Conversation

zetashift
Copy link
Contributor

Currently running against:

root> docs/mdoc
[info] Updating
[info] Resolved  dependencies
[warn]
[warn]  Note: Unresolved dependencies path:
[error] stack trace is suppressed; run last docs / update for the full output
[error] (docs / update) sbt.librarymanagement.ResolveException: Error downloading org.scala-js:scalajs-dom_sjs1_2.12:0.0.0+1310-714813e3+20221
102-2315-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /home/rishi/.ivy2/local/org.scala-js/scalajs-dom_sjs1_2.12/0.0.0+1310-714813e3+20221102-2315-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/scala-js/scalajs-dom_sjs1_2.12/0.0.0+1310-714813e3+20221102-2315-SNAPSHOT/scalajs-dom_sjs1_2.12-0.0.0+1310-714813e3+20221102-2315-SNAPSHOT.pom

@zetashift
Copy link
Contributor Author

Do we track the current scala-js-dom version in the build file? I want to inject it in the docs using mdoc, but I can't seem to find the value.

@armanbilge
Copy link
Member

We use the sbt dynver plugin, you can use the previousStableVersion setting key to access it.
https://github.com/sbt/sbt-dynver/blob/125101baaff68978727f58994ecb9fd781501796/sbtdynver/src/main/scala/sbtdynver/DynVerPlugin.scala#L25

Make sure that the git tags are up to date in your local clone :)

@zetashift
Copy link
Contributor Author

Next error, I am trying to get interactive scala JS to work, I made a mdoc.properties in the root folder but I get the following error:

bad option: '--intransitive'
Exception in thread "main" java.util.NoSuchElementException
        at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1318)
        at java.base/java.util.ServiceLoader$2.next(ServiceLoader.java:1306)
        at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1403)
        at mdoc.modifiers.JsModifier.onLoad(JsModifier.scala:102)
        at mdoc.internal.cli.Settings.$anonfun$onLoad$1(Settings.scala:222)
        at mdoc.internal.cli.Settings.$anonfun$onLoad$1$adapted(Settings.scala:222)
        at scala.collection.immutable.List.foreach(List.scala:431)
        at mdoc.internal.cli.Settings.onLoad(Settings.scala:222)
        at mdoc.internal.cli.Context$.fromSettings(Context.scala:50)
        at mdoc.internal.cli.MainOps$.$anonfun$process$1(MainOps.scala:272)
        at metaconfig.Configured.andThen(Configured.scala:45)
        at mdoc.internal.cli.MainOps$.process(MainOps.scala:272)
        at mdoc.MainProcess.process(Main.scala:41)
        at mdoc.MainProcess.process$(Main.scala:38)
        at mdoc.Main$.process(Main.scala:13)
        at mdoc.MainProcess.process(Main.scala:36)
        at mdoc.MainProcess.process$(Main.scala:35)
        at mdoc.Main$.process(Main.scala:13)
        at mdoc.Main$.main(Main.scala:15)
        at mdoc.Main.main(Main.scala)
        ```

@armanbilge
Copy link
Member

Hum, why did you add mdoc.properties? I haven't needed that in any of my projects using mdoc.js

@zetashift
Copy link
Contributor Author

Oh oops, I read the instructions for mdoc:js modifiers wrong, thank you :P

@zetashift
Copy link
Contributor Author

Alright I got console logging working from the docs/mdoc --watch command and then loading the readme.md.

I need to improve the examples I think.
Btw how are we deploying the mdoc.js site? Docusaurus seems like overkill

@armanbilge armanbilge linked an issue Nov 3, 2022 that may be closed by this pull request
@armanbilge
Copy link
Member

🎉

I need to improve the examples I think.

Do you mean the ones in the existing documentation? Maybe, haven't looked at them recently 😂 even if we just start by porting them

Btw how are we deploying the mdoc.js site? Docusaurus seems like overkill

Agree about docusaurus. I have to think about this, open to ideas too. Maybe we can steal the html/theme from the scala-js.org website which uses jekyll.

https://github.com/scala-js/scala-js-website

@zetashift
Copy link
Contributor Author

Do you mean the ones in the existing documentation? Maybe, haven't looked at them recently joy even if we just start by porting them

I'll try to port them over!

Agree about docusaurus. I have to think about this, open to ideas too. Maybe we can steal the html/theme from the scala-js.org website which uses jekyll.

https://github.com/scala-js/scala-js-website

Yea I think we can just create a stylesheet based off of the main website. At the very least to get us started.

@zetashift
Copy link
Contributor Author

I am converting the examples and I see this piece of code:

def main(pre: html.Pre) = {
  import scala.concurrent
              .ExecutionContext
              .Implicits
              .global
  import js.Thenable.Implicits._
  val url =
    "https://www.boredapi.com/api/activity"
  val responseText = for {
    response <- dom.fetch(url)
    text <- response.text()
  } yield {
    text
  }
  for (text <- responseText)
    pre.textContent = text
}

Is an ExecutionContext really necessary for using fetch?

@armanbilge
Copy link
Member

Strictly speaking, no. It's only necessary if you convert the Promises to Futures.

@zetashift
Copy link
Contributor Author

Is it correct that Promise can't be flatmapped?
Running into this error:

 value flatMap is not a member of scala.scalajs.js.Promise[org.scalaj
s.dom.Response]
    response <- fetch(url)
                ^^^^^^^^^^

The code:

def fetchBoredApi(element: html.Pre) = {
  val url =
    "https://www.boredapi.com/api/activity"

  val responseText = for {
    response <- fetch(url)
    text <- response.text()
  } yield {
    text
  }

  for (text <- responseText)
    pre.textContent = text
}

@sjrd
Copy link
Member

sjrd commented Dec 3, 2022

Yes, you need a .toFuture

docs/readme.md Outdated
Comment on lines 57 to 64
```scala mdoc:js:invisible
<button class="button-run">Run</button
<div id="outer-container"></div>
<button id="demo1" class="button-run">Run</button>
---
document.getElementById("demo1").addEventListener("click", (ev: Event) => {
appendElement(document.getElementById("outer-container").asInstanceOf[html.Div])
})
```
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entirely unsure if this is a nice way to do runnable examples.

@zetashift
Copy link
Contributor Author

Closing this to hide my shameful Git skills! New PR will be up soon(TM)

@zetashift zetashift closed this Feb 19, 2023
@zetashift zetashift deleted the add/mdocjs branch February 20, 2023 01:00
@zetashift zetashift restored the add/mdocjs branch February 27, 2023 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate readme project to another docs framework
4 participants