-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incremental commit toward autoplugin conversion.
- Loading branch information
Simeon H.K. Fitch
committed
Oct 5, 2015
1 parent
41021ca
commit 06c26bc
Showing
12 changed files
with
420 additions
and
313 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.idea | ||
target/ | ||
target |
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 |
---|---|---|
@@ -1,88 +1,59 @@ | ||
package com.typesafe.sbt | ||
|
||
import com.typesafe.sbt.site.AsciidoctorSupport | ||
import sbt._ | ||
import Keys._ | ||
import com.typesafe.sbt.site._ | ||
|
||
|
||
object SbtSite extends Plugin { | ||
object SiteKeys { | ||
object SbtSite extends AutoPlugin { | ||
override def trigger = allRequirements | ||
object autoImport { | ||
val makeSite = TaskKey[File]("make-site", "Generates a static website for a project.") | ||
val packageSite = TaskKey[File]("package-site", "Create a zip file of the website.") | ||
|
||
// Helper to point at mappings for the site. | ||
val siteMappings = mappings in makeSite | ||
val siteDirectory = target in makeSite | ||
val siteSources = sources in makeSite | ||
val siteSourceDirectory = sourceDirectory in makeSite | ||
|
||
val previewSite = TaskKey[Unit]("preview-site", "Launches a jetty server that serves your generated site from the target directory") | ||
val previewFixedPort = SettingKey[Option[Int]]("previewFixedPort") in previewSite | ||
val previewLaunchBrowser = SettingKey[Boolean]("previewLaunchBrowser") in previewSite | ||
} | ||
import autoImport._ | ||
|
||
// Helper to point at mappings for the site. | ||
private[sbt] val siteMappings = mappings in makeSite | ||
private[sbt] val siteDirectory = target in makeSite | ||
private[sbt] val siteSources = sources in makeSite | ||
private[sbt] val siteSourceDirectory = sourceDirectory in makeSite | ||
|
||
override lazy val projectSettings = Seq( | ||
siteMappings := Seq.empty, | ||
siteMappings <<= siteMappings ?? Seq.empty, | ||
siteDirectory := target.value / "site", | ||
siteSourceDirectory := sourceDirectory.value / "site", | ||
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf", | ||
siteMappings ++= SiteHelpers.selectSubpaths(siteSourceDirectory.value, (includeFilter in makeSite).value), | ||
makeSite := SiteHelpers.copySite(siteDirectory.value, streams.value.cacheDirectory, siteMappings.value), | ||
artifact in packageSite := SiteHelpers.siteArtifact(moduleName.value), | ||
artifactPath in packageSite <<= Defaults.artifactPathSetting(artifact in packageSite), | ||
packageSite := SiteHelpers.createSiteZip(makeSite.value, (artifactPath in packageSite).value, streams.value) | ||
) | ||
|
||
object site { | ||
import SiteKeys._ | ||
|
||
val settings = Seq( | ||
siteMappings := Seq.empty, | ||
siteDirectory := target.value / "site", | ||
siteSourceDirectory := sourceDirectory.value / "site", | ||
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf", | ||
siteMappings ++= selectSubpaths(siteSourceDirectory.value, (includeFilter in makeSite).value), | ||
makeSite := copySite(siteDirectory.value, streams.value.cacheDirectory, siteMappings.value), | ||
artifact in packageSite := siteArtifact(moduleName.value), | ||
artifactPath in packageSite <<= Defaults.artifactPathSetting(artifact in packageSite), | ||
packageSite := createSiteZip(makeSite.value, (artifactPath in packageSite).value, streams.value) | ||
) ++ Preview.settings | ||
|
||
/** Convenience functions to add a task of mappings to a site under a nested directory. */ | ||
def addMappingsToSiteDir(mappings: TaskKey[Seq[(File,String)]], nestedDirectory: String): Setting[_] = | ||
siteMappings <++= mappings map { m => | ||
for((f, d) <- m) yield (f, nestedDirectory + "/" + d) | ||
} | ||
|
||
/** Includes scaladoc APIS in site under a "latest/api" directory. */ | ||
def includeScaladoc(alias: String = "latest/api"): Seq[Setting[_]] = | ||
Seq(addMappingsToSiteDir(mappings in packageDoc in Compile, alias)) | ||
/** Includes Jekyll generated site under the root directory. */ | ||
def jekyllSupport(alias: String = ""): Seq[Setting[_]] = | ||
JekyllSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in JekyllSupport.Jekyll, alias)) | ||
/** Includes Sphinx generated site under the root directory. */ | ||
def sphinxSupport(alias: String = ""): Seq[Setting[_]] = | ||
SphinxSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in SphinxSupport.Sphinx, alias)) | ||
/** Includes Pamflet generate site under the root directory. */ | ||
def pamfletSupport(alias: String = ""): Seq[Setting[_]] = | ||
PamfletSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PamfletSupport.Pamflet, alias)) | ||
/** Includes Nanoc generated site under the root directory. */ | ||
def nanocSupport(alias: String = ""): Seq[Setting[_]] = | ||
NanocSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in NanocSupport.Nanoc, alias)) | ||
def asciidoctorSupport(alias: String = ""): Seq[Setting[_]] = | ||
AsciidoctorSupport.settings ++ Seq(addMappingsToSiteDir(mappings in AsciidoctorSupport.Asciidoctor, alias)) | ||
def preprocessSite(alias: String = ""): Seq[Setting[_]] = | ||
PreprocessSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PreprocessSupport.Preprocess, alias)) | ||
// def preprocessSite(alias: String = ""): Seq[Setting[_]] = | ||
// PreprocessSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PreprocessSupport.Preprocess, alias)) | ||
// | ||
// /** Includes scaladoc APIS in site under a "latest/api" directory. */ | ||
// def includeScaladoc(alias: String = "latest/api"): Seq[Setting[_]] = | ||
// Seq(SiteHelpers.addMappingsToSiteDir(mappings in packageDoc in Compile, alias)) | ||
// /** Includes Jekyll generated site under the root directory. */ | ||
// def jekyllSupport(alias: String = ""): Seq[Setting[_]] = | ||
// JekyllSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in JekyllSupport.autoImports.Jekyll, alias)) | ||
// /** Includes Sphinx generated site under the root directory. */ | ||
// def sphinxSupport(alias: String = ""): Seq[Setting[_]] = | ||
// SphinxSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in SphinxSupport.Sphinx, alias)) | ||
// /** Includes Pamflet generate site under the root directory. */ | ||
// def pamfletSupport(alias: String = ""): Seq[Setting[_]] = | ||
// PamfletSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in PamfletSupport.Pamflet, alias)) | ||
// /** Includes Nanoc generated site under the root directory. */ | ||
// def nanocSupport(alias: String = ""): Seq[Setting[_]] = | ||
// NanocSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in NanocSupport.Nanoc, alias)) | ||
// def asciidoctorSupport(alias: String = ""): Seq[Setting[_]] = | ||
// AsciidoctorSupport.settings ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in AsciidoctorSupport.Asciidoctor, alias)) | ||
def publishSite(): SettingsDefinition = addArtifact(artifact in packageSite, packageSite) | ||
} | ||
|
||
// Note: We include helpers so other plugins can 'plug in' to this one without requiring users to use/configure the site plugin. | ||
override val settings = Seq( | ||
SiteKeys.siteMappings <<= SiteKeys.siteMappings ?? Seq.empty | ||
) | ||
|
||
def selectSubpaths(dir: File, filter: FileFilter): Seq[(File, String)] = Path.selectSubpaths(dir, filter).toSeq | ||
|
||
def copySite(dir: File, cacheDir: File, maps: Seq[(File, String)]): File = { | ||
val concrete = maps map { case (file, dest) => (file, dir / dest) } | ||
Sync(cacheDir / "make-site")(concrete) | ||
dir | ||
} | ||
|
||
def siteArtifact(name: String) = Artifact(name, Artifact.DocType, "zip", "site") | ||
|
||
def createSiteZip(siteDir: File, zipPath: File, s: TaskStreams): File = { | ||
IO.zip(Path.allSubpaths(siteDir), zipPath) | ||
s.log.info("Site packaged: " + zipPath) | ||
zipPath | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,45 +1,50 @@ | ||
package com.typesafe.sbt | ||
package site | ||
|
||
import sbt.Keys._ | ||
import sbt._ | ||
import Keys._ | ||
import SbtSite.SiteKeys.siteMappings | ||
object JekyllSupport extends AutoPlugin { | ||
override def requires = SbtSite | ||
override def trigger = noTrigger | ||
|
||
object JekyllSupport { | ||
val Jekyll = config("jekyll") | ||
object autoImport { | ||
val Jekyll = config("jekyll") | ||
val requiredGems = SettingKey[Map[String, String]]( | ||
"jekyll-required-gems", "Required gem + versions for this build.") | ||
val checkGems = TaskKey[Unit]( | ||
"jekyll-check-gems", "Tests whether or not all required gems are available.") | ||
} | ||
import autoImport._ | ||
override def projectSettings: Seq[Setting[_]] = | ||
SiteHelpers.directorySettings(Jekyll) ++ | ||
Seq( | ||
includeFilter in Jekyll := ("*.html" | "*.png" | "*.js" | "*.css" | "*.gif" | "CNAME" | ".nojekyll"), | ||
requiredGems := Map.empty | ||
) ++ inConfig(Jekyll)( | ||
Seq( | ||
checkGems := SiteHelpers.checkGems(requiredGems.value, streams.value), | ||
mappings := { | ||
val cg = checkGems.value | ||
generate(sourceDirectory.value, target.value, includeFilter.value, streams.value) | ||
}, | ||
SiteHelpers.addMappingsToSiteDir(mappings, "TODO") | ||
)) ++ SiteHelpers.watchSettings(Jekyll) | ||
|
||
val requiredGems = SettingKey[Map[String,String]]("jekyll-required-gems", "Required gem + versions for this build.") | ||
val checkGems = TaskKey[Unit]("jekyll-check-gems", "Tests whether or not all required gems are available.") | ||
def settings(config: Configuration = Jekyll): Seq[Setting[_]] = | ||
Generator.directorySettings(config) ++ | ||
Seq( | ||
includeFilter in config := ("*.html" | "*.png" | "*.js" | "*.css" | "*.gif" | "CNAME" | ".nojekyll"), | ||
requiredGems := Map.empty | ||
//(mappings in SiteKeys.siteMappings) <++= (mappings in Jekyll), | ||
) ++ inConfig(config)(Seq( | ||
checkGems := Generator.checkGems(requiredGems.value, streams.value), | ||
mappings := { | ||
val cg = checkGems.value | ||
JekyllImpl.generate(sourceDirectory.value, target.value, includeFilter.value, streams.value) | ||
} | ||
)) ++ Seq( | ||
siteMappings ++= (mappings in config).value | ||
) ++ | ||
Generator.watchSettings(config) // TODO - this may need to be optional. | ||
} | ||
|
||
/** Helper class with implementations of tasks. */ | ||
object JekyllImpl { | ||
// TODO - Add command line args and the like. | ||
final def generate(src: File, target: File, inc: FileFilter, s: TaskStreams): Seq[(File, String)] = { | ||
final def generate( | ||
src: File, | ||
target: File, | ||
inc: FileFilter, | ||
s: TaskStreams): Seq[(File, String)] = { | ||
// Run Jekyll | ||
sbt.Process(Seq("jekyll", "build", "-d", target.getAbsolutePath), Some(src)) ! s.log match { | ||
case 0 => () | ||
case n => sys.error("Could not run jekyll, error: " + n) | ||
} | ||
// Figure out what was generated. | ||
for { | ||
(file, name) <- (target ** inc --- target pair relativeTo(target)) | ||
(file, name) <- target ** inc --- target pair relativeTo(target) | ||
} yield file -> name | ||
} | ||
} |
Oops, something went wrong.