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

Upd project dependencies #126

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: coursier/cache-action@v6
- name: Set up Scala
uses: olafurpg/setup-scala@v11
- uses: actions/setup-java@v2
with:
java-version: adopt@1.11
distribution: temurin
java-version: 11

- name: Build and test
run: sbt ";test ;run"
Expand Down
3 changes: 0 additions & 3 deletions .scalafmt

This file was deleted.

11 changes: 11 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version = 3.1.1
runner.dialect = scala213source3
indent.main = 2
indent.significant = 2
maxColumn = 150
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses.preset = true
rewrite.rules = [SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings.style = Asterisk
align.preset = more
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy val `scalalaz-gen` = project
.enablePlugins(AutomateHeaderPlugin, GitVersioning, SbtTwirl)
.settings(scalaVersion := Version.Scala)

addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.0" cross CrossVersion.full)
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.13.2" cross CrossVersion.full)

libraryDependencies ++= Vector(
Library.scalaTest % Test,
Expand All @@ -16,10 +16,10 @@ libraryDependencies ++= Vector(
Library.typesafeConfig
)

initialCommands := """|import ru.scalalaz.gen._
initialCommands := """|import ru.scalalaz.gen.*
|""".stripMargin

TwirlKeys.templateImports ++= Seq(
"ru.scalalaz.gen._",
"ru.scalalaz.gen.writers._"
"ru.scalalaz.gen.*",
"ru.scalalaz.gen.writers.*"
)
24 changes: 17 additions & 7 deletions project/Build.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import com.typesafe.sbt.GitPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin
import de.heikoseeberger.sbtheader._
import org.scalafmt.sbt._
import play.twirl.sbt.SbtTwirl
import sbt._
import sbt.plugins.JvmPlugin
import sbt.Keys._
import java.time.Year

object Build extends AutoPlugin {

override def requires = JvmPlugin && GitPlugin&& HeaderPlugin && SbtTwirl
override def requires = JvmPlugin && GitPlugin && HeaderPlugin && SbtTwirl

override def trigger = allRequirements

Expand All @@ -18,25 +19,34 @@ object Build extends AutoPlugin {
organization := "ru",
licenses += ("Apache-2.0", url("http://www.apache.org/licenses/LICENSE-2.0")),
Compile / packageBin / mappings += (ThisBuild / baseDirectory).value / "LICENSE" -> "LICENSE",
scalaVersion := Version.Scala,
crossScalaVersions := Vector(scalaVersion.value),
scalaVersion := Version.Scala,
crossScalaVersions := Vector(scalaVersion.value),
scalacOptions ++= Vector(
"-unchecked",
"-deprecation",
"-feature",
"-language:_",
"-Xsource:3",
"-target:jvm-1.8",
"-encoding",
"UTF-8"
),
Compile / unmanagedSourceDirectories := Vector((Compile / scalaSource).value),
Test / unmanagedSourceDirectories := Vector((Test / scalaSource).value),
Test / unmanagedSourceDirectories := Vector((Test / scalaSource).value),

// Git settings
GitPlugin.autoImport.git.useGitDescribe := true,

// Header settings
HeaderPlugin.autoImport.headerLicense := Some(HeaderPlugin.autoImport.HeaderLicense.ALv2("2016", "Scalalaz Podcast Team"))

HeaderPlugin.autoImport.headerLicense := Some(HeaderPlugin.autoImport.HeaderLicense.ALv2(Year.now.getValue.toString, "Scalalaz Podcast Team")),
HeaderPlugin.autoImport.headerMappings := Map(
FileType.scala -> CommentStyle.cStyleBlockComment.copy(
commentCreator = { (text, existingText) =>
// preserve year of old headers
val newText = CommentStyle.cStyleBlockComment.commentCreator.apply(text, existingText)
existingText.flatMap(_ => existingText.map(_.trim)).getOrElse(newText)
}
)
)
)
}
13 changes: 8 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import sbt._

object Version {
final val Scala = "2.13.6"
final val ScalaTest = "3.2.9"
final val ScalaTags = "0.9.4"
final val FastParse = "2.3.2"
final val Cats = "2.6.1"
final val Scala = "2.13.7"
final val ScalaTest = "3.2.10"
final val ScalaTags = "0.11.0"
final val FastParse = "2.3.3"
final val Cats = "2.7.0"
// both sbt-twirl and knockoff depend on scala-xml 1.x
// starting version 0.9 knockoff depends on scala-xml 2.x which makes it impossible for us to use
// for the additional context see https://github.com/playframework/twirl/blob/b2e049d993d1522249e79837ee90ad39f317a80e/build.sbt#L11-L16
final val Knockoff = "0.8.14"
final val TypesafeConfig = "1.4.1"
}
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.5")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
Expand Down
58 changes: 25 additions & 33 deletions src/main/scala/ru/scalalaz/gen/Generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package ru.scalalaz.gen

import parsing._
import writers._
import parsing.*
import writers.*

import cats.data.Validated.{Invalid, Valid}
import cats.data.{NonEmptyList, ValidatedNel}
import cats.instances.list._
import cats.syntax.traverse._
import cats.syntax.either._
import cats.instances.list.*
import cats.syntax.traverse.*
import cats.syntax.either.*

import java.nio.file.{Files, Path}

Expand Down Expand Up @@ -51,50 +51,47 @@ trait GeneratorFs {
Either.catchNonFatal(f) match {
case Left(e) =>
Left(
descr + "\n"
+ e.toString + "\n"
+ e.getStackTrace().mkString("", EOL, EOL)
descr + "\n"
+ e.toString + "\n"
+ e.getStackTrace().mkString("", EOL, EOL)
)
case Right(v) => Right(v)
}
}

class Generator(settings: SiteSettings, source: Path, target: Path)
extends GeneratorFs {
class Generator(settings: SiteSettings, source: Path, target: Path) extends GeneratorFs {

import ru.scalalaz.gen.parsing.EpisodeErrors._
import ru.scalalaz.gen.parsing.EpisodeErrors.*

val targetRssPath = target.resolve("rss")

def generate(): Either[String, Unit] = {
def generate(): Either[String, Unit] =
for {
_ <- prepare()
episodes <- parse()
_ <- eitherCatch(copyOther(), "Copy other resources: ")
_ <- generateHtml(episodes)
_ <- generateRss(episodes)
} yield Right(())
}

/**
* чистим/создаем нужные директории
*/
* чистим/создаем нужные директории
*/
def prepare(): Either[String, Unit] =
for {
_ <- eitherCatch(fs.clean(target))
last <- eitherCatch(fs.createDir(targetRssPath))
} yield last

/**
* копируем для лайка-генератора все обычные файлы
*/
def copyOther(): Unit = {
Seq("img", "css/layouts", "js").foreach(d => {
* копируем для лайка-генератора все обычные файлы
*/
def copyOther(): Unit =
Seq("img", "css/layouts", "js").foreach { d =>
val from = source.resolve(d)
val to = target.resolve(d)
fs.copyDir(from, to)
})
}
}

def parse(): Either[String, List[EpisodeFile]] =
episodeFiles(source.resolve("episodes"))
Expand All @@ -104,12 +101,11 @@ class Generator(settings: SiteSettings, source: Path, target: Path)
case Valid(ef) => Right(ef)
}

def generateHtml(episodes: List[EpisodeFile]): Either[String, Unit] = {
def generateHtml(episodes: List[EpisodeFile]): Either[String, Unit] =
eitherCatch {
val writer = new HTMLWriter(target.toString, settings.discusCode)
writer.write(episodes)
}
}

def generateRss(eps: List[EpisodeFile]): Either[String, Unit] = {
val writer = new RSSWriter(targetRssPath.toString, ITunesInfo.Scalalaz)
Expand All @@ -126,40 +122,37 @@ class Generator(settings: SiteSettings, source: Path, target: Path)
.toValidatedNel
}

def describeErrors(errors: NonEmptyList[EpisodeParseError]): String = {
def describeErrors(errors: NonEmptyList[EpisodeParseError]): String =
errors
.map(e => s"Error occurred while parsing file:\n\t $e")
.toList
.mkString("\n")
}

}

class SpecialPagesGenerator(source: Path, target: Path) extends GeneratorFs {

import ru.scalalaz.gen.parsing.SpecialPageErrors._
import ru.scalalaz.gen.parsing.SpecialPageErrors.*

def generate(): Either[String, Unit] = {
def generate(): Either[String, Unit] =
for {
pages <- parse()
_ <- generateHtml(pages)
} yield Right(())
}

def parse(): Either[String, List[PageFile]] =
specialPagesFiles(source.resolve("pages"))
.sortBy(_.getFileName.toString)
.traverse(parsePage) match {
case Invalid(e) => Left(describeErrors(e))
case Valid(ef) => Right(ef)
}
}

def generateHtml(pages: List[PageFile]): Either[String, Unit] = {
def generateHtml(pages: List[PageFile]): Either[String, Unit] =
eitherCatch {
val writer = new SpecialPagesHTMLWriter(target.toString)
writer.write(pages)
}
}

def parsePage(p: Path): ValidatedNel[PageParseError, PageFile] = {
val bytes = Files.readAllBytes(p)
Expand All @@ -171,10 +164,9 @@ class SpecialPagesGenerator(source: Path, target: Path) extends GeneratorFs {
.toValidatedNel
}

def describeErrors(errors: NonEmptyList[PageParseError]): String = {
def describeErrors(errors: NonEmptyList[PageParseError]): String =
errors
.map(e => s"Error occurred while parsing file:\n\t $e")
.toList
.mkString("\n")
}
}
2 changes: 1 addition & 1 deletion src/main/scala/ru/scalalaz/gen/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object Main extends App {

val siteSettings = SiteSettings()

val gen = new Generator(siteSettings, markdownDir, targetPath)
val gen = new Generator(siteSettings, markdownDir, targetPath)
val pgen = new SpecialPagesGenerator(markdownDir, targetPath)

gen.generate() match {
Expand Down
26 changes: 10 additions & 16 deletions src/main/scala/ru/scalalaz/gen/data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,28 @@ package ru.scalalaz.gen

import java.nio.file.Path
import java.time.format.DateTimeFormatter
import java.time.{ LocalDate, ZoneOffset }
import java.time.{LocalDate, ZoneOffset}

import knockoff.DefaultDiscounter._
import _root_.knockoff._
import knockoff.DefaultDiscounter.*
import _root_.knockoff.*

/**
* Фигня с сылкой на запись, кол-вом байт и типом
*/
* Фигня с сылкой на запись, кол-вом байт и типом
*/
case class Enclosure(url: String, length: Int, `type`: String = "audio/mpeg")

/**
* То из чего собирается rss-кусок на каждый выпуск
*/
case class EpisodeSettings(title: String,
description: String,
audio: Enclosure,
page: String,
date: LocalDate) {
* То из чего собирается rss-кусок на каждый выпуск
*/
case class EpisodeSettings(title: String, description: String, audio: Enclosure, page: String, date: LocalDate) {

def RFCDate: String = {
val dateTime = date.atStartOfDay().atOffset(ZoneOffset.UTC)
dateTime.format(DateTimeFormatter.RFC_1123_DATE_TIME)
}

def ISODate: String = {
def ISODate: String =
date.format(DateTimeFormatter.ISO_DATE)
}
}

case class Episode(settings: EpisodeSettings, content: String) {
Expand All @@ -60,9 +55,8 @@ case class Episode(settings: EpisodeSettings, content: String) {
case class EpisodeFile(path: Path, episode: Episode)

case class SpecialPageSettings(title: String, date: LocalDate) {
def ISODate: String = {
def ISODate: String =
date.format(DateTimeFormatter.ISO_DATE)
}
}

case class Page(settings: SpecialPageSettings, content: String) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/scala/ru/scalalaz/gen/fs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package ru.scalalaz.gen

import java.nio.file.{ Files, Path }
import java.nio.file.{Files, Path}

import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

object fs {

Expand All @@ -34,9 +34,8 @@ object fs {
file.delete()
}

def createDir(path: Path): Unit = {
def createDir(path: Path): Unit =
Files.createDirectories(path)
}

def copyFile(from: Path, to: Path): Path = {
val data = Files.readAllBytes(from)
Expand All @@ -49,15 +48,15 @@ object fs {
if (!to.toFile.exists()) createDir(to)
list(from)
.filter(filter)
.foreach(p => {
.foreach { p =>
if (p.toFile.isFile)
copyFile(p, to.resolve(p.asScala.last))
else {
val next = to.resolve(p.asScala.last)
createDir(next)
copyDir(p, next, filter)
}
})
}
}

}
Loading