Skip to content

Commit

Permalink
Add scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
foxmk committed Mar 25, 2017
1 parent 0422348 commit 9826ce9
Show file tree
Hide file tree
Showing 32 changed files with 724 additions and 643 deletions.
3 changes: 3 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
style = default
maxColumn = 120
align.tokens = ["|", "=>", "<-", "=", "\"\"\""]
31 changes: 18 additions & 13 deletions app/src/main/scala/giter8.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,20 @@ class Giter8 extends xsbti.AppMain {
G8.Param.pattern.matcher(s).matches
} match {
case (params, options) =>
parser.parse(options, Config("")).map { config =>
helper.run(config, params, new File("."))
}.getOrElse(Left(""))
parser
.parse(options, Config(""))
.map { config =>
helper.run(config, params, new File("."))
}
.getOrElse(Left(""))
case _ => Left(parser.usage)
})
helper.cleanup()
result.fold ({ (error: String) =>
result.fold({ (error: String) =>
System.err.println(s"\n$error\n")
1
}, { (message: String) =>
println("\n%s\n" format message )
println("\n%s\n" format message)
0
})
}
Expand All @@ -56,18 +59,18 @@ class Giter8 extends xsbti.AppMain {
arg[String]("<template>") action { (repo, config) =>
config.copy(repo = repo)
} text ("git or file URL, or github user/repo")
opt[String]('b', "branch") action { (b, config) =>
opt[String]('b', "branch") action { (b, config) =>
config.copy(ref = Some(Branch(b)))
} text("Resolve a template within a given branch")
} text ("Resolve a template within a given branch")
opt[String]('t', "tag") action { (t, config) =>
config.copy(ref = Some(Tag(t)))
} text("Resolve a template within a given branch")
} text ("Resolve a template within a given branch")
opt[String]('d', "directory") action { (d, config) =>
config.copy(directory = Some(d))
} text("Resolve a template within a given directory")
} text ("Resolve a template within a given directory")
opt[Unit]('f', "force") action { (_, config) =>
config.copy(forceOverwrite = true)
} text("Force overwrite of any existing files in output directory")
} text ("Force overwrite of any existing files in output directory")
version("version").text("Display version number")
note(""" --paramname=paramval Set given parameter value and bypass interaction
|
Expand Down Expand Up @@ -100,9 +103,11 @@ class Exit(val code: Int) extends xsbti.Exit

object Giter8 extends Giter8 {
import java.io.File
val home = Option(System.getProperty("G8_HOME")).map(new File(_)).getOrElse(
new File(System.getProperty("user.home"), ".g8")
)
val home = Option(System.getProperty("G8_HOME"))
.map(new File(_))
.getOrElse(
new File(System.getProperty("user.home"), ".g8")
)

/** Main-class runner just for testing from sbt*/
def main(args: Array[String]): Unit = {
Expand Down
130 changes: 72 additions & 58 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,61 @@ import Dependencies._
val g8version = "0.7.3-SNAPSHOT"

// posterous title needs to be giter8, so both app and root are named giter8
lazy val root = (project in file(".")).
enablePlugins(TravisSitePlugin, NoPublish).
aggregate(app, lib, scaffold, plugin).
settings(
inThisBuild(List(
organization := "org.foundweekends.giter8",
version := g8version,
scalaVersion := "2.10.6",
organizationName := "foundweekends",
organizationHomepage := Some(url("http://foundweekends.org/")),
scalacOptions ++= Seq("-language:_", "-deprecation", "-Xlint", "-Xfuture"),
publishArtifact in (Compile, packageBin) := true,
homepage := Some(url("http://www.foundweekends.org/giter8/")),
publishMavenStyle := true,
publishTo :=
Some("releases" at
"https://oss.sonatype.org/service/local/staging/deploy/maven2"),
publishArtifact in Test := false,
parallelExecution in Test := false,
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
developers := List(
Developer("n8han", "Nathan Hamblen", "@n8han", url("http://github.com/n8han")),
Developer("eed3si9n", "Eugene Yokota", "@eed3si9n", url("https://github.com/eed3si9n"))
),
scmInfo := Some(ScmInfo(url("https://github.com/foundweekends/giter8"), "[email protected]:foundweekends/giter8.git"))
)),
lazy val root = (project in file("."))
.enablePlugins(TravisSitePlugin, NoPublish)
.aggregate(app, lib, scaffold, plugin)
.settings(
inThisBuild(
List(
organization := "org.foundweekends.giter8",
version := g8version,
scalaVersion := "2.10.6",
organizationName := "foundweekends",
organizationHomepage := Some(url("http://foundweekends.org/")),
scalacOptions ++= Seq("-language:_", "-deprecation", "-Xlint", "-Xfuture"),
publishArtifact in (Compile, packageBin) := true,
homepage := Some(url("http://www.foundweekends.org/giter8/")),
publishMavenStyle := true,
publishTo :=
Some("releases" at
"https://oss.sonatype.org/service/local/staging/deploy/maven2"),
publishArtifact in Test := false,
parallelExecution in Test := false,
licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
developers := List(
Developer("n8han", "Nathan Hamblen", "@n8han", url("http://github.com/n8han")),
Developer("eed3si9n", "Eugene Yokota", "@eed3si9n", url("https://github.com/eed3si9n"))
),
scmInfo := Some(
ScmInfo(url("https://github.com/foundweekends/giter8"), "[email protected]:foundweekends/giter8.git"))
)),
name := "giter8",
crossScalaVersions := List(scala210, scala211, scala212),
siteGithubRepo := "foundweekends/giter8",
siteEmail := { "eed3si9n" + "@" + "gmail.com" },
customCommands
)

lazy val app = (project in file("app")).
disablePlugins(BintrayPlugin).
enablePlugins(ConscriptPlugin, BuildInfoPlugin, SonatypePublish).
dependsOn(lib).
settings(
lazy val app = (project in file("app"))
.disablePlugins(BintrayPlugin)
.enablePlugins(ConscriptPlugin, BuildInfoPlugin, SonatypePublish)
.dependsOn(lib)
.settings(
description := "Command line tool to apply templates defined on github",
name := "giter8",
crossScalaVersions := List(scala210, scala211, scala212),
sourceDirectory in csRun := { (baseDirectory).value.getParentFile / "src" / "main" / "conscript" },
sourceDirectory in csRun := {
(baseDirectory).value.getParentFile / "src" / "main" / "conscript"
},
libraryDependencies ++= Seq(scopt, logback),
buildInfoKeys := Seq(name, version, scalaVersion, sbtVersion),
buildInfoPackage := "giter8"
)

lazy val scaffold = (project in file("scaffold")).
enablePlugins(BintrayPublish).
dependsOn(lib).
settings(
lazy val scaffold = (project in file("scaffold"))
.enablePlugins(BintrayPublish)
.dependsOn(lib)
.settings(
name := "sbt-giter8-scaffold",
description := "sbt plugin for scaffolding giter8 templates",
sbtPlugin := true,
Expand All @@ -64,16 +68,18 @@ lazy val scaffold = (project in file("scaffold")).
),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value),
scripted := ScriptedPlugin.scripted.dependsOn(publishLocal in lib).evaluated,
scripted := ScriptedPlugin.scripted
.dependsOn(publishLocal in lib)
.evaluated,
test in Test := {
scripted.toTask("").value
}
)

lazy val plugin = (project in file("plugin")).
enablePlugins(BintrayPublish).
dependsOn(lib).
settings(
lazy val plugin = (project in file("plugin"))
.enablePlugins(BintrayPublish)
.dependsOn(lib)
.settings(
name := "sbt-giter8",
scriptedSettings,
description := "sbt plugin for testing giter8 templates",
Expand All @@ -85,38 +91,46 @@ lazy val plugin = (project in file("plugin")).
),
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dplugin.version=" + version.value),
scripted := ScriptedPlugin.scripted.dependsOn(publishLocal in lib).evaluated,
scripted := ScriptedPlugin.scripted
.dependsOn(publishLocal in lib)
.evaluated,
libraryDependencies += ("org.scala-sbt" % "scripted-plugin" % sbtVersion.value),
test in Test := {
scripted.toTask("").value
}
)

lazy val lib = (project in file("library")).
disablePlugins(BintrayPlugin).
enablePlugins(SonatypePublish).
settings(
lazy val lib = (project in file("library"))
.disablePlugins(BintrayPlugin)
.enablePlugins(SonatypePublish)
.settings(
name := "giter8-lib",
description := "shared library for app and plugin",
crossScalaVersions := List(scala210, scala211, scala212),
libraryDependencies ++= Seq(
scalasti, jgit, commonsIo, plexusArchiver,
scalacheck % Test, sbtIo % Test, scalatest % Test,
scalamock % Test, "org.slf4j" % "slf4j-simple" % "1.7.12" % Test
scalasti,
jgit,
commonsIo,
plexusArchiver,
scalacheck % Test,
sbtIo % Test,
scalatest % Test,
scalamock % Test,
"org.slf4j" % "slf4j-simple" % "1.7.12" % Test
) ++
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
Seq(scalaXml, parserCombinator)
case _ => Nil
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor >= 11 =>
Seq(scalaXml, parserCombinator)
case _ => Nil
})
)
)

def customCommands: Seq[Setting[_]] = Seq(
commands += Command.command("release") { state =>
"clean" ::
"so compile" ::
"so publishSigned" ::
"reload" ::
state
"so compile" ::
"so publishSigned" ::
"reload" ::
state
}
)
Loading

0 comments on commit 9826ce9

Please sign in to comment.