Skip to main content
Version: 2.x

ZIO SBT Website

WebsitePlugin compiles the documentation in the docs directory with mdoc, scaffolds, builds and previews a Docusaurus website, publishes the docs to npm and generates the README.md of the project. UnifiedScaladocPlugin is a small companion that publishes one Scaladoc for several modules.

To install the plugin, add addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.8.13") to project/plugins.sbt and enable it on the docs project with enablePlugins(WebsitePlugin), as described in Installation.

Tasksโ€‹

The plugin defines these tasks. Run them on the docs project, for example sbt docs/compileDocs.

TaskTypeDescription
compileDocsInputKeyCompiles the documentation inside docs with mdoc into website/docs. With --watch it recompiles on every change
installWebsiteTaskKeyCreates the website for the project inside website with @zio.dev/create-zio-website, pinned by createZioWebsiteVersion, then runs npm install. It does nothing when website/package.json exists
buildWebsiteTaskKeyRuns installWebsite and compileDocs, installs the npm dependencies if node_modules is missing, then builds the site into website/build
previewWebsiteTaskKeyCompiles the docs with --watch and runs npm run start, which serves the website on http://localhost:3000 and reloads it when the docs change
checkDocsOnFreshWebsiteTaskKeyBuilds the compiled docs in a freshly scaffolded website, the way the ZIO website builds them. It is skipped when the project has no committed website
publishToNpmInputKeyCompiles the docs and publishes website/docs to npm under the version given by docsVersion
publishSnapshotToNpmInputKeyCompiles the docs and publishes them with the project version under the snapshot dist-tag, replacing + with -- in the version
publishHashverToNpmInputKeyCompiles the docs and publishes them with a hash version, a date plus the short git hash, under the hash dist-tag
generateReadmeTaskKeyGenerates README.md from docs/index.md and the readme* settings
checkReadmeTaskKeyRuns generateReadme and fails when git diff shows that README.md changed

publishToNpm puts a prerelease version, such as 1.0.0-beta.1, under its own dist-tag (beta) only when the latest tag already points at a stable release. Otherwise the version goes to latest, published with an explicit --tag latest because npm refuses a prerelease without a tag. The publishToNpm, publishSnapshotToNpm and publishHashverToNpm tasks need scmInfo to be set, because they record the repository URL in the package.

The website/docs directory is generated output, not source. mdocOut points there, so compileDocs, and anything that runs it, including generateReadme, writes compiled documentation into it. To keep it out of version control, add these lines to .gitignore:

/website/docs
/website/build
/website/node_modules
/website/.docusaurus

Committing website/docs leaves a website directory that holds generated output but no Docusaurus scaffold, and buildWebsite then has no package.json to install from.

Settingsโ€‹

SettingTypeDefaultDescription
websiteDirPath<root>/websiteThe website directory
projectNameStringThe project name, such as ZIO SBT, used in the README title and badges. Set it on the docs project
mainModuleNameStringThe main module, such as zio-sbt, used for the artifact in badges. Set it on the docs project
projectStageProjectStageThe stage badge: ProductionReady, Development, Experimental, Research, Concept or Deprecated
projectHomePageStringDeclared by the plugin, but nothing reads it. The README documentation link uses sbt's homepage instead
badgeArtifactIdStringmainModuleName plus _ plus the Scala binary versionThe artifact id in the release, snapshot and javadoc badges. Override it for artifacts with other coordinates, such as sbt plugins (name_2.12_1.0)
ciWorkflowNameString"CI"The name of the CI workflow that the CI badge points at. This is not the key that names the generated workflow; that is ciWorkflowTitle of ZIO SBT CI
docsDependenciesSeq[ModuleID]Seq.emptyDependencies that the docs project adds to libraryDependencies
docsVersioningSchemeVersioningSchemeVersioningScheme.SemanticVersioningSemanticVersioning or HashVersioning
docsVersionStringderived from docsVersioningSchemeThe version of the docs npm package: the latest release with semantic versioning, a date and short git hash with hash versioning
createZioWebsiteVersionString"0.1.0"The version of the @zio.dev/create-zio-website npm package that scaffolds the website
npmTokenStringDeclared by the plugin, but its tasks do not read it. Publishing uses the credentials of the npm command

projectName and mainModuleName have no default, so the docs project must set them. projectStage is set with an object, for example ProjectStage.ProductionReady.

mdoc Variablesโ€‹

The plugin adds these variables to mdocVariables, so a documentation page can write them between @ signs:

VariableValue
0.8.13The latest release version, or the project version when there is no release
0.8.13The latest release version, or NOT RELEASED YET
0.8.13The current project version
[![Production Ready](https://img.shields.io/badge/Project%20Stage-Production%20Ready-brightgreen.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-sbt/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/maven-central/v/dev.zio/zio-sbt-website_2.12_1.0.svg?label=Sonatype%20Release)](https://central.sonatype.com/artifact/dev.zio/zio-sbt-website_2.12_1.0) [![Sonatype Snapshots](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fcentral.sonatype.com%2Frepository%2Fmaven-snapshots%2Fdev%2Fzio%2Fzio-sbt-website_2.12_1.0%2Fmaven-metadata.xml&label=Sonatype%20Snapshot)](https://central.sonatype.com/repository/maven-snapshots/dev/zio/zio-sbt-website_2.12_1.0/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-sbt-website_2.12_1.0/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-sbt-website_2.12_1.0) [![ZIO SBT](https://img.shields.io/github/stars/zio/zio-sbt?style=social)](https://github.com/zio/zio-sbt)The stage, CI, snapshot and GitHub star badges, plus the release and javadoc badges once a release exists

The plugin also passes --markdown-extensions for md, html and mdx to mdoc, so docs/index.mdx is processed like docs/index.md.

README Settingsโ€‹

generateReadme builds README.md from the introduction in docs/index.md and these settings. Each one is a String with Markdown content, except readmeShowTitle. An empty string omits the Acknowledgement, Credits and Maintainers sections. The other sections are always written, so an empty string leaves their heading with no content.

SettingDefaultSection it fills
readmeBanner""A banner above the introduction
readmeShowTitleNoneWhether the README starts with # <projectName>. None shows the title unless readmeBanner is set. The type is Option[Boolean]
readmeDocumentationA link to the homepage setting of the buildDocumentation
readmeContributionA link to the ZIO contributor's guideContributing
readmeCodeOfConductA link to the ZIO code of conductCode of Conduct
readmeSupportA Discord chat badge and linkSupport
readmeLicenseA link to the LICENSE fileLicense
readmeAcknowledgement""Acknowledgement
readmeCredits""Credits
readmeMaintainers""Maintainers

A README setting can be appended to as well as replaced:

readmeContribution := readmeContribution.value + "\n\nRun `sbt prepare` before you submit a pull request."

Unified Scaladocโ€‹

UnifiedScaladocPlugin requires the sbt-unidoc ScalaUnidocPlugin and has noTrigger, so a project enables it explicitly. It sets Compile / doc to ScalaUnidoc / doc, so doc produces one Scaladoc for every module that unidoc includes:

lazy val docs = project
.enablePlugins(WebsitePlugin, UnifiedScaladocPlugin)
.settings(ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(core))

ZIO Chat

๐ŸŽ‰ Hey there, ZIO aficionado! ๐ŸŽ‰ Step into the ZIO wonderland with me as your guide. Whether you're a functional fanatic or just dipping your toes into the ZIO ecosystem, I'm here to make your journey smooth. Got ZIO questions? I've got answers! Let's navigate the ZIO universe together and unlock its infinite possibilities!