Skip to content

Commit

Permalink
Add excludeFilter support to GitBook generator
Browse files Browse the repository at this point in the history
It excludes hidden files by default and thus `.git` and `.gitignore`.
The test case does not match exactly the issue described in #67 (namely
use of submodules) but instead tests a similar situation where the
source directory is the project's base directory.

Fixes #67
  • Loading branch information
jonas committed Sep 2, 2016
1 parent 878168a commit d1a6565
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ object GitBookPlugin extends AutoPlugin {
inConfig(config)(
Seq(
includeFilter := AllPassFilter,
excludeFilter := HiddenFileFilter,
gitbookInstallDir := None,
mappings := generate(
sourceDirectory.value,
target.value,
includeFilter.value,
excludeFilter.value,
gitbookInstallDir.value,
streams.value
),
Expand All @@ -42,7 +44,7 @@ object GitBookPlugin extends AutoPlugin {
SiteHelpers.addMappingsToSiteDir(mappings in config, siteSubdirName in config)

/** Run gitbook commands. */
private[sbt] def generate(src: File, target: File, inc: FileFilter, installDir: Option[File], s: TaskStreams): Seq[(File, String)] = {
private[sbt] def generate(src: File, target: File, inc: FileFilter, exc: FileFilter, installDir: Option[File], s: TaskStreams): Seq[(File, String)] = {
val runEnv = installDir.map("HOME" -> _.getAbsolutePath).toSeq
def run(cmd: String*) =
Process(cmd.toSeq, Some(src), runEnv: _*) ! s.log match {
Expand Down Expand Up @@ -81,9 +83,8 @@ object GitBookPlugin extends AutoPlugin {
}

// Figure out what was generated.
for {
(file, name) <- (target ** inc --- target pair relativeTo(target))
} yield file -> name
val files = (target ** inc) --- (target ** exc) --- target
files pair relativeTo(target)
}

private[sbt] def bookJson(src: File): File = src / "book.json"
Expand Down
5 changes: 5 additions & 0 deletions src/sbt-test/gitbook/ignore-dot-files/.bookignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
project/
target/
boot/
global/
*.sbt
1 change: 1 addition & 0 deletions src/sbt-test/gitbook/ignore-dot-files/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_book
12 changes: 12 additions & 0 deletions src/sbt-test/gitbook/ignore-dot-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Hello, GitBook!

The SBT site plugin can build your http://gitbook.com[GitBook] documentation.

## First Section

- item 1
- item 2

```scala
case class User(name: String, age: Int)
```
1 change: 1 addition & 0 deletions src/sbt-test/gitbook/ignore-dot-files/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Summary
3 changes: 3 additions & 0 deletions src/sbt-test/gitbook/ignore-dot-files/book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"gitbook": "3.x.x"
}
30 changes: 30 additions & 0 deletions src/sbt-test/gitbook/ignore-dot-files/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name := "test"

enablePlugins(GitBookPlugin)

sourceDirectory in GitBook := baseDirectory.value
siteSubdirName in GitBook := "docs"

val gitHeadPath = ".git/HEAD"

initialize := {
// Create .git test file before running makeSite
IO.write(baseDirectory.value / gitHeadPath, "test")
}

TaskKey[Unit]("checkContent") := {
val dest = (target in makeSite).value / (siteSubdirName in GitBook).value

val generatedGitFile = baseDirectory.value / gitHeadPath
assert(generatedGitFile.exists, s"${generatedGitFile.getAbsolutePath} did not exist")

for (path <- Seq("index.html")) {
val file = dest / path
assert(file.exists, s"${file.getAbsolutePath} did not exist")
}

for (path <- Seq(gitHeadPath, ".gitignore", ".bookignore", "target", "project")) {
val file = dest / path
assert(!file.exists, s"${file.getAbsolutePath} should not exist")
}
}
1 change: 1 addition & 0 deletions src/sbt-test/gitbook/ignore-dot-files/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % sys.props("project.version"))
2 changes: 2 additions & 0 deletions src/sbt-test/gitbook/ignore-dot-files/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> make-site
> checkContent

0 comments on commit d1a6565

Please sign in to comment.