|
1 | 1 | package com.typesafe.sbt
|
2 | 2 |
|
3 |
| -import com.typesafe.sbt.site.AsciidoctorSupport |
4 | 3 | import sbt._
|
5 | 4 | import Keys._
|
6 | 5 | import com.typesafe.sbt.site._
|
7 | 6 |
|
8 |
| - |
9 |
| -object SbtSite extends Plugin { |
10 |
| - object SiteKeys { |
| 7 | +object SbtSite extends AutoPlugin { |
| 8 | + override def trigger = allRequirements |
| 9 | + object autoImport { |
11 | 10 | val makeSite = TaskKey[File]("make-site", "Generates a static website for a project.")
|
12 | 11 | val packageSite = TaskKey[File]("package-site", "Create a zip file of the website.")
|
13 |
| - |
14 |
| - // Helper to point at mappings for the site. |
15 |
| - val siteMappings = mappings in makeSite |
16 |
| - val siteDirectory = target in makeSite |
17 |
| - val siteSources = sources in makeSite |
18 |
| - val siteSourceDirectory = sourceDirectory in makeSite |
19 |
| - |
20 |
| - val previewSite = TaskKey[Unit]("preview-site", "Launches a jetty server that serves your generated site from the target directory") |
21 |
| - val previewFixedPort = SettingKey[Option[Int]]("previewFixedPort") in previewSite |
22 |
| - val previewLaunchBrowser = SettingKey[Boolean]("previewLaunchBrowser") in previewSite |
23 | 12 | }
|
| 13 | + import autoImport._ |
| 14 | + |
| 15 | + // Helper to point at mappings for the site. |
| 16 | + private[sbt] val siteMappings = mappings in makeSite |
| 17 | + private[sbt] val siteDirectory = target in makeSite |
| 18 | + private[sbt] val siteSources = sources in makeSite |
| 19 | + private[sbt] val siteSourceDirectory = sourceDirectory in makeSite |
| 20 | + |
| 21 | + override lazy val projectSettings = Seq( |
| 22 | + siteMappings := Seq.empty, |
| 23 | + siteMappings <<= siteMappings ?? Seq.empty, |
| 24 | + siteDirectory := target.value / "site", |
| 25 | + siteSourceDirectory := sourceDirectory.value / "site", |
| 26 | + includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf", |
| 27 | + siteMappings ++= SiteHelpers.selectSubpaths(siteSourceDirectory.value, (includeFilter in makeSite).value), |
| 28 | + makeSite := SiteHelpers.copySite(siteDirectory.value, streams.value.cacheDirectory, siteMappings.value), |
| 29 | + artifact in packageSite := SiteHelpers.siteArtifact(moduleName.value), |
| 30 | + artifactPath in packageSite <<= Defaults.artifactPathSetting(artifact in packageSite), |
| 31 | + packageSite := SiteHelpers.createSiteZip(makeSite.value, (artifactPath in packageSite).value, streams.value) |
| 32 | + ) |
24 | 33 |
|
25 | 34 | object site {
|
26 |
| - import SiteKeys._ |
27 | 35 |
|
28 |
| - val settings = Seq( |
29 |
| - siteMappings := Seq.empty, |
30 |
| - siteDirectory := target.value / "site", |
31 |
| - siteSourceDirectory := sourceDirectory.value / "site", |
32 |
| - includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf", |
33 |
| - siteMappings ++= selectSubpaths(siteSourceDirectory.value, (includeFilter in makeSite).value), |
34 |
| - makeSite := copySite(siteDirectory.value, streams.value.cacheDirectory, siteMappings.value), |
35 |
| - artifact in packageSite := siteArtifact(moduleName.value), |
36 |
| - artifactPath in packageSite <<= Defaults.artifactPathSetting(artifact in packageSite), |
37 |
| - packageSite := createSiteZip(makeSite.value, (artifactPath in packageSite).value, streams.value) |
38 |
| - ) ++ Preview.settings |
39 |
| - |
40 |
| - /** Convenience functions to add a task of mappings to a site under a nested directory. */ |
41 |
| - def addMappingsToSiteDir(mappings: TaskKey[Seq[(File,String)]], nestedDirectory: String): Setting[_] = |
42 |
| - siteMappings <++= mappings map { m => |
43 |
| - for((f, d) <- m) yield (f, nestedDirectory + "/" + d) |
44 |
| - } |
45 |
| - |
46 |
| - /** Includes scaladoc APIS in site under a "latest/api" directory. */ |
47 |
| - def includeScaladoc(alias: String = "latest/api"): Seq[Setting[_]] = |
48 |
| - Seq(addMappingsToSiteDir(mappings in packageDoc in Compile, alias)) |
49 |
| - /** Includes Jekyll generated site under the root directory. */ |
50 |
| - def jekyllSupport(alias: String = ""): Seq[Setting[_]] = |
51 |
| - JekyllSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in JekyllSupport.Jekyll, alias)) |
52 |
| - /** Includes Sphinx generated site under the root directory. */ |
53 |
| - def sphinxSupport(alias: String = ""): Seq[Setting[_]] = |
54 |
| - SphinxSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in SphinxSupport.Sphinx, alias)) |
55 |
| - /** Includes Pamflet generate site under the root directory. */ |
56 |
| - def pamfletSupport(alias: String = ""): Seq[Setting[_]] = |
57 |
| - PamfletSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PamfletSupport.Pamflet, alias)) |
58 |
| - /** Includes Nanoc generated site under the root directory. */ |
59 |
| - def nanocSupport(alias: String = ""): Seq[Setting[_]] = |
60 |
| - NanocSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in NanocSupport.Nanoc, alias)) |
61 |
| - def asciidoctorSupport(alias: String = ""): Seq[Setting[_]] = |
62 |
| - AsciidoctorSupport.settings ++ Seq(addMappingsToSiteDir(mappings in AsciidoctorSupport.Asciidoctor, alias)) |
63 |
| - def preprocessSite(alias: String = ""): Seq[Setting[_]] = |
64 |
| - PreprocessSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PreprocessSupport.Preprocess, alias)) |
| 36 | +// def preprocessSite(alias: String = ""): Seq[Setting[_]] = |
| 37 | +// PreprocessSupport.settings() ++ Seq(addMappingsToSiteDir(mappings in PreprocessSupport.Preprocess, alias)) |
| 38 | +// |
| 39 | +// /** Includes scaladoc APIS in site under a "latest/api" directory. */ |
| 40 | +// def includeScaladoc(alias: String = "latest/api"): Seq[Setting[_]] = |
| 41 | +// Seq(SiteHelpers.addMappingsToSiteDir(mappings in packageDoc in Compile, alias)) |
| 42 | +// /** Includes Jekyll generated site under the root directory. */ |
| 43 | +// def jekyllSupport(alias: String = ""): Seq[Setting[_]] = |
| 44 | +// JekyllSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in JekyllSupport.autoImports.Jekyll, alias)) |
| 45 | +// /** Includes Sphinx generated site under the root directory. */ |
| 46 | +// def sphinxSupport(alias: String = ""): Seq[Setting[_]] = |
| 47 | +// SphinxSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in SphinxSupport.Sphinx, alias)) |
| 48 | +// /** Includes Pamflet generate site under the root directory. */ |
| 49 | +// def pamfletSupport(alias: String = ""): Seq[Setting[_]] = |
| 50 | +// PamfletSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in PamfletSupport.Pamflet, alias)) |
| 51 | +// /** Includes Nanoc generated site under the root directory. */ |
| 52 | +// def nanocSupport(alias: String = ""): Seq[Setting[_]] = |
| 53 | +// NanocSupport.settings() ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in NanocSupport.Nanoc, alias)) |
| 54 | +// def asciidoctorSupport(alias: String = ""): Seq[Setting[_]] = |
| 55 | +// AsciidoctorSupport.settings ++ Seq(SiteHelpers.addMappingsToSiteDir(mappings in AsciidoctorSupport.Asciidoctor, alias)) |
65 | 56 | def publishSite(): SettingsDefinition = addArtifact(artifact in packageSite, packageSite)
|
66 | 57 | }
|
67 | 58 |
|
68 |
| - // Note: We include helpers so other plugins can 'plug in' to this one without requiring users to use/configure the site plugin. |
69 |
| - override val settings = Seq( |
70 |
| - SiteKeys.siteMappings <<= SiteKeys.siteMappings ?? Seq.empty |
71 |
| - ) |
72 |
| - |
73 |
| - def selectSubpaths(dir: File, filter: FileFilter): Seq[(File, String)] = Path.selectSubpaths(dir, filter).toSeq |
74 |
| - |
75 |
| - def copySite(dir: File, cacheDir: File, maps: Seq[(File, String)]): File = { |
76 |
| - val concrete = maps map { case (file, dest) => (file, dir / dest) } |
77 |
| - Sync(cacheDir / "make-site")(concrete) |
78 |
| - dir |
79 |
| - } |
80 |
| - |
81 |
| - def siteArtifact(name: String) = Artifact(name, Artifact.DocType, "zip", "site") |
82 |
| - |
83 |
| - def createSiteZip(siteDir: File, zipPath: File, s: TaskStreams): File = { |
84 |
| - IO.zip(Path.allSubpaths(siteDir), zipPath) |
85 |
| - s.log.info("Site packaged: " + zipPath) |
86 |
| - zipPath |
87 |
| - } |
88 | 59 | }
|
0 commit comments