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

Target a single file for --in and --out #322

Merged
merged 6 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ contained, by default the `docs/` directory is used.
+ --in mydocs
```

The `--in` flag doesn't have to be a directory, it also supports individual
files.

```diff
coursier launch org.scalameta:mdoc_@SCALA_BINARY_VERSION@:@VERSION@ -- \
+ --in mydocs/readme.md
```

Use `--site.VARIABLE=value` to add site variables that can be referenced from
markdown as `@@VARIABLE@`.

Expand Down
2 changes: 1 addition & 1 deletion mdoc-sbt/src/main/scala/mdoc/MdocPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object MdocPlugin extends AutoPlugin {
)
val mdocIn =
settingKey[File](
"Input directory containing markdown sources to be processed by mdoc. " +
"Input directory or source file containing markdown to be processed by mdoc. " +
"Defaults to the toplevel docs/ directory."
)
val mdocOut =
Expand Down
7 changes: 6 additions & 1 deletion mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ final class MainOps(
}

def generateCompleteSite(): Exit = {
val files = IO.inputFiles(settings)
val isFile = settings.in.toFile.isFile
val files = if (isFile) {
settings.toInputFile(settings.in).toList
} else {
IO.inputFiles(settings)
}
val timer = new Timer()
val n = files.length
compilingFiles(n)
Expand Down
12 changes: 8 additions & 4 deletions mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class Section(val name: String) extends StaticAnnotation
case class Settings(
@Section("Common options")
@Description(
"The input directory containing markdown and other documentation sources. " +
"Markdown files will be processed by mdoc while other files will be copied " +
"verbatim to the output directory."
"The input directory containing markdown and other documentation sources " +
"or an individual file that you'd like to target. Markdown files will be " +
"processed by mdoc while other files will be copied verbatim to the output directory."
)
@ExtraName("i")
in: AbsolutePath,
Expand Down Expand Up @@ -161,7 +161,11 @@ case class Settings(
def isFileWatching: Boolean = watch && !check

def toInputFile(infile: AbsolutePath): Option[InputFile] = {
val relpath = infile.toRelative(in)
val relpath = if (infile == in) {
RelativePath(in.toNIO.getFileName.toString)
} else {
infile.toRelative(in)
}
if (isIncluded(relpath)) {
val outfile = out.resolve(relpath)
Some(InputFile(relpath, infile, outfile))
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/cli/BaseCliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ abstract class BaseCliSuite extends FunSuite {
expected: String,
extraArgs: Array[String] = Array.empty,
setup: CliFixture => Unit = _ => (),
configureInFlag: AbsolutePath => String = _.toString(),
expectedExitCode: Int = 0,
onStdout: String => Unit = _ => ()
): Unit = {
Expand All @@ -29,7 +30,7 @@ abstract class BaseCliSuite extends FunSuite {
setup(CliFixture(in.toNIO, out))
val args = Array[String](
"--in",
in.toString,
configureInFlag(in),
"--out",
out.toString,
"--cwd",
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/src/test/scala/tests/cli/CliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package tests.cli

import java.nio.file.Files
import mdoc.internal.BuildInfo
import scala.meta.io.AbsolutePath
import java.nio.file.Paths

class CliSuite extends BaseCliSuite {

Expand Down Expand Up @@ -187,4 +189,24 @@ class CliSuite extends BaseCliSuite {
|""".stripMargin
)

checkCli(
"single-file",
"""
|/index.md
|# Single file
|```scala mdoc
|println("one file")
|```
|""".stripMargin,
"""
|/index.md
|# Single file
|```scala
|println("one file")
|// one file
|```
|""".stripMargin,
configureInFlag = { in => in + "/index.md" }
)

}
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"rename-version": "docusaurus-rename-version"
},
"devDependencies": {
"docusaurus": "1.6.2"
"docusaurus": "1.14.4"
}
}