diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 000000000..7642287a3
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "scripts/website"]
+ path = scripts/website
+ url = https://github.com/coursier/docusaurus-mdoc-scripts.git
diff --git a/.travis.yml b/.travis.yml
index f21b30066..d74cb1d3e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -9,7 +9,7 @@ cache:
git:
depth: false
before_install:
- - source scripts/setup-build-tools.sh
+ - source scripts/website/setup-build-tools.sh
sudo: required
stages:
- name: test
@@ -17,6 +17,8 @@ stages:
if: (branch = master AND type = push) OR (tag IS present)
- name: upload-launcher
if: tag IS present
+ - name: update-versioned-docs
+ if: tag IS present
- name: update-website
if: (branch = master AND type = push) OR (tag IS present)
jobs:
@@ -41,15 +43,24 @@ jobs:
- scala: 2.12.8
jdk: openjdk11
- name: "Website"
- script: scripts/update-website.sh
+ script: amm scripts/site.sc --publishLocal true
- stage: release
script: sbt ci-release
- - stage: update-website
- env: PUSH_WEBSITE=1
- script: scripts/update-website.sh
- stage: upload-launcher
name: "Upload launcher"
script: scripts/upload-launcher.sh
+ - stage: update-versioned-docs
+ env: WEBSITE_DIR=docs/website VERSIONED_DOCS_REPO=almond-sh/versioned-docs
+ script:
+ - amm scripts/site.sc --publishLocal true --npmInstall true --yarnRunBuild true
+ - scripts/website/versioned-docs.sh --update
+ - stage: update-website
+ env: WEBSITE_DIR=docs/website REPO=almond-sh/almond VERSIONED_DOCS_REPO=almond-sh/versioned-docs
+ name: "Push website"
+ script:
+ - scripts/website/versioned-docs.sh
+ - amm scripts/site.sc --publishLocal true --npmInstall true --yarnRunBuild true --relativize true
+ - scripts/website/push-website.sh
branches:
only:
- master
diff --git a/docs/website/pages/en/versions.js b/docs/website/pages/en/versions.js
new file mode 100644
index 000000000..30eb3c8e9
--- /dev/null
+++ b/docs/website/pages/en/versions.js
@@ -0,0 +1,112 @@
+/**
+ * Copyright (c) 2017-present, Facebook, Inc.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+const React = require('react');
+
+const CompLibrary = require('../../core/CompLibrary');
+
+const Container = CompLibrary.Container;
+
+const CWD = process.cwd();
+
+const siteConfig = require(process.cwd() + '/siteConfig.js');
+try {
+ var versions = require(`${CWD}/versions.json`);
+} catch (e) {
+ var versions = [];
+}
+
+function Versions() {
+ const latestVersion = versions[0] || '';
+ const language = '';
+ const repoUrl = `https://github.com/${siteConfig.organizationName}/${
+ siteConfig.projectName
+ }`;
+ return (
+
+
+
+
+ {siteConfig.title} Versions
+
+
Current version
+
+
Latest Version
+ Here you can find the latest documentation and unreleased code.
+
+
Past Versions
+
+ Here you can find documentation for previous versions.
+
+
+
+ You can find past versions of this project on{' '}
+ GitHub.
+
+
+
+
+ );
+}
+
+Versions.title = 'Versions';
+
+module.exports = Versions;
diff --git a/scripts/generate-website.sh b/scripts/generate-website.sh
deleted file mode 100755
index af5cb9265..000000000
--- a/scripts/generate-website.sh
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-# FIXME Lots of duplications with https://github.com/coursier/coursier/blob/3309b64102678550b1393c524dddf2b71fb9d931/scripts/generate-website.sh
-
-if [ "$1" == "--watch" ]; then
- WATCH=1
-else
- WATCH=0
-fi
-
-cd "$(dirname "${BASH_SOURCE[0]}")"
-
-# Assumes 'sbt interpreter-api/exportVersions' has been run
-
-VERSION="$(cat ../modules/shared/interpreter-api/target/version)"
-echo "Current version is $VERSION"
-
-AMMONITE_VERSION="$(cat ../modules/shared/interpreter-api/target/ammonite-version)"
-SCALA_VERSION="$(cat ../modules/shared/interpreter-api/target/scala-version)"
-
-if echo "$VERSION" | grep -q -- '-SNAPSHOT$'; then
- EXTRA_COURSIER_ARGS="-r sonatype:snapshots "
-else
- EXTRA_COURSIER_ARGS=""
-fi
-
-echo "Processing Markdown files"
-
-if [ "$WATCH" = 1 ]; then
- EXTRA_OPTS="--watch"
-else
- EXTRA_OPTS=""
-fi
-
-# first processing md files via https://github.com/olafurpg/mdoc
-# requires the cache modules and its dependencies to have been published locally
-# with
-# sbt interpreter-api/publishLocal scala-kernel-api/publishLocal almond-spark/publishLocal
-../scripts/coursier.sh launch \
- -r sonatype:releases \
- -r jitpack \
- "com.geirsson:mdoc_$SCALA_VERSION:0.7.0" \
- "sh.almond:scala-kernel-api_$SCALA_VERSION:$VERSION" \
- -- \
- --in ../docs/pages \
- --out ../docs/processed-pages \
- --site.VERSION "$VERSION" \
- --site.AMMONITE_VERSION "$AMMONITE_VERSION" \
- --site.SCALA_VERSION "$SCALA_VERSION" \
- --site.EXTRA_COURSIER_ARGS "$EXTRA_COURSIER_ARGS" \
- $EXTRA_OPTS
-
-if [ "$WATCH" = 1 ]; then
- exit 0
-fi
-
-echo "Generating website"
-
-cd ../docs/website
-npm install
-yarn run build
-cd -
-
-../scripts/relativize.sh ../docs/website/build
-
-DIR="$(cd ../docs/website/build/almond; pwd)"
-
-echo
-echo "Generated website available under $DIR"
-
-
-cat << EOF
-Open the generated website with
-
- npx http-server docs/website/build/almond
-
-EOF
diff --git a/scripts/push-website.sh b/scripts/push-website.sh
deleted file mode 100755
index 12da9a34f..000000000
--- a/scripts/push-website.sh
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/env bash
-set -eu
-
-# FIXME Lots of duplications with https://github.com/coursier/coursier/blob/3309b64102678550b1393c524dddf2b71fb9d931/scripts/push-website.sh
-
-cd "$(dirname "${BASH_SOURCE[0]}")/.."
-
-if [ ! -e docs/website/build/almond/index.html ]; then
- echo "Generated website not found under docs/website/build/almond"
- exit 1
-fi
-
-FULL_VERSION="$(cat modules/shared/interpreter-api/target/version)"
-VERSION="$(echo "$FULL_VERSION" | sed 's/+.*-SNAPSHOT$/-SNAPSHOT/')"
-echo "Current version is $FULL_VERSION (shortened: $VERSION)"
-
-mkdir -p target
-cd target
-
-if [ -d gh-pages ]; then
- echo "Removing former gh-pages clone"
- rm -rf gh-pages
-fi
-
-echo "Cloning"
-git clone "https://${GH_TOKEN}@github.com/almond-sh/almond.git" -q -b gh-pages gh-pages
-cd gh-pages
-
-git config user.name "Travis-CI"
-git config user.email "invalid@travis-ci.com"
-
-UPDATE="0"
-
-if [ -d "$VERSION" ]; then
- echo "Cleaning-up $VERSION directory"
- git rm -r "$VERSION"
- UPDATE="1"
-fi
-
-mkdir -p "$VERSION"
-echo "Copying new website"
-cp -pR ../../docs/website/build/almond/* "$VERSION/"
-git add "$VERSION"
-
-DIRS=()
-
-if [[ ${VERSION} = *-SNAPSHOT || ${VERSION} = *+* ]]; then
- DIRS=("snapshot")
-elif [[ ${VERSION} = *-M* || ${VERSION} = *-RC* ]]; then
- DIRS=("snapshot" "latest")
-else
- DIRS=("snapshot" "latest" "stable")
-fi
-
-for dir in "${DIRS[@]}"; do
- rm -f "$dir"
- ln -s "$VERSION" "$dir"
- git add "$dir"
-done
-
-if [ "$UPDATE" = 1 ]; then
- MSG="Update doc for version $VERSION"
-else
- MSG="Add doc for version $VERSION"
-fi
-
-# probably not fine with i18n
-if git status | grep "nothing to commit" >/dev/null 2>&1; then
- echo "Nothing changed"
-else
- git commit -m "$MSG"
-
- echo "Pushing changes"
- git push origin gh-pages
-fi
diff --git a/scripts/relativize.sc b/scripts/relativize.sc
deleted file mode 100644
index 8d215d687..000000000
--- a/scripts/relativize.sc
+++ /dev/null
@@ -1,86 +0,0 @@
-// from https://github.com/olafurpg/sbt-docusaurus/blob/15e548280117d3fcd8db4c244f91f089470b8ee7/plugin/src/main/scala/sbtdocusaurus/internal/Relativize.scala
-// FIXME Also in https://github.com/coursier/coursier/blob/3309b64102678550b1393c524dddf2b71fb9d931/scripts/relativize.sc
-
-import $ivy.`org.jsoup:jsoup:1.10.3`
-
-import java.net.URI
-import java.nio.charset.Charset
-import java.nio.charset.StandardCharsets
-import java.nio.file.FileVisitResult
-import java.nio.file.Files
-import java.nio.file.Path
-import java.nio.file.Paths
-import java.nio.file.SimpleFileVisitor
-import java.nio.file.attribute.BasicFileAttributes
-import org.jsoup.Jsoup
-import org.jsoup.nodes.Element
-import scala.collection.JavaConverters._
-
-object Relativize {
-
- def htmlSite(site: Path): Unit = {
- Files.walkFileTree(
- site,
- new SimpleFileVisitor[Path] {
- override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
- if (file.getFileName.toString.endsWith(".html")) {
- processHtmlFile(site, file)
- }
- super.visitFile(file, attrs)
- }
- }
- )
- }
-
- // actual host name doesn't matter
- private val baseUri = URI.create("http://example.com/")
-
- def processHtmlFile(site: Path, file: Path): Unit = {
- val originRelativeUri = relativeUri(site.relativize(file))
- val originUri = baseUri.resolve(originRelativeUri)
- val originPath = Paths.get(originUri.getPath).getParent
- def relativizeAttribute(element: Element, attribute: String): Unit = {
- val absoluteHref = URI.create(element.attr(s"abs:$attribute"))
- if (absoluteHref.getHost == baseUri.getHost) {
- val hrefPath = Paths.get(absoluteHref.getPath)
- val relativeHref = originPath.relativize(hrefPath)
- val fragment =
- if (absoluteHref.getFragment == null) ""
- else "#" + absoluteHref.getFragment
- val newHref = relativeUri(relativeHref).toString + fragment
- element.attr(attribute, newHref)
- } else if (element.attr(attribute).startsWith("//")) {
- // We force "//hostname" links to become "https://hostname" in order to make
- // the site browsable without file server. If we keep "//hostname" unchanged
- // then users will try to load "file://hostname" which results in 404.
- // We hardcode https instead of http because it's OK to load https from http
- // but not the other way around.
- element.attr(attribute, "https:" + element.attr(attribute))
- }
- }
- val doc = Jsoup.parse(file.toFile, StandardCharsets.UTF_8.name(), originUri.toString)
- def relativizeElement(element: String, attribute: String): Unit =
- doc.select(element).forEach { element =>
- relativizeAttribute(element, attribute)
- }
- relativizeElement("a", "href")
- relativizeElement("link", "href")
- relativizeElement("img", "src")
- val renderedHtml = doc.outerHtml()
- Files.write(file, renderedHtml.getBytes(StandardCharsets.UTF_8))
- }
-
- private def relativeUri(relativePath: Path): URI = {
- require(!relativePath.isAbsolute, relativePath)
- val names = relativePath.iterator().asScala
- val uris = names.map { name =>
- new URI(null, null, name.toString, null)
- }
- URI.create(uris.mkString("", "/", ""))
- }
-}
-
-@main
-def main(args: String*): Unit =
- for (path <- args)
- Relativize.htmlSite(Paths.get(path))
diff --git a/scripts/relativize.sh b/scripts/relativize.sh
deleted file mode 100755
index d90dea7fe..000000000
--- a/scripts/relativize.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-"$(dirname "${BASH_SOURCE[0]}")/coursier.sh" launch com.lihaoyi:ammonite_2.12.6:1.2.1 -M ammonite.Main -- \
- "$(dirname "${BASH_SOURCE[0]}")/relativize.sc" "$@"
diff --git a/scripts/site.sc b/scripts/site.sc
new file mode 100644
index 000000000..ad7b85611
--- /dev/null
+++ b/scripts/site.sc
@@ -0,0 +1,89 @@
+
+import java.io.File
+import java.nio.file._
+
+import $file.website.Website, Website.{Mdoc, Relativize, Util}
+
+lazy val version = Util.cached("version") {
+ Util.outputOf(Seq("sbt", "export channels/version"))
+ .linesIterator
+ .map(_.trim)
+ .filter(_.nonEmpty)
+ .toSeq
+ .last
+}
+
+lazy val scalaVersion = Util.cached("scala-version") {
+ Util.outputOf(Seq("sbt", "export channels/scalaVersion"))
+ .linesIterator
+ .map(_.trim)
+ .filter(_.nonEmpty)
+ .toSeq
+ .last
+}
+
+lazy val ammoniteVersion = Util.cached("ammonite-version") {
+ Util.runCmd(Seq("sbt", "interpreter-api/exportVersions"))
+ new String(Files.readAllBytes(Paths.get("modules/shared/interpreter-api/target/ammonite-version")), "UTF-8").trim
+}
+
+lazy val mdocProps: Map[String, String] = {
+ val isSnapshot = version.endsWith("SNAPSHOT")
+ val extraSbt =
+ if (isSnapshot)
+ """resolvers += Resolver.sonatypeRepo("snapshots")""" + "\n"
+ else
+ ""
+ val extraCoursierArgs =
+ if (isSnapshot)
+ "-r sonatype:snapshots "
+ else
+ ""
+ Map(
+ "VERSION" -> version,
+ "EXTRA_SBT" -> extraSbt,
+ "AMMONITE_VERSION" -> ammoniteVersion,
+ "SCALA_VERSION" -> scalaVersion,
+ "EXTRA_COURSIER_ARGS" -> extraCoursierArgs
+ )
+}
+
+@main
+def main(publishLocal: Boolean = false, npmInstall: Boolean = false, yarnRunBuild: Boolean = false, watch: Boolean = false, relativize: Boolean = false): Unit = {
+
+ assert(!(watch && relativize), "Cannot specify both --watch and --relativize")
+
+ if (publishLocal)
+ Util.runCmd(Seq("sbt", "set version in ThisBuild := \"" + version + "\"", "interpreter-api/publishLocal", "scala-kernel-api/publishLocal", "almond-spark/publishLocal"))
+
+ // be sure to adjust that
+ val websiteDir = new File("docs/website")
+
+ val yarnRunBuildIn =
+ if (yarnRunBuild)
+ Some(websiteDir)
+ else
+ None
+
+ if (npmInstall)
+ Util.runCmd(Seq("npm", "install"), dir = websiteDir)
+
+ val mdoc = new Mdoc(
+ new File("docs/pages"),
+ new File("docs/processed-pages"),
+ scalaVersion,
+ dependencies = Seq(
+ s"sh.almond:scala-kernel-api_$scalaVersion:$version",
+ "-r", "jitpack"
+ ),
+ mdocProps = mdocProps
+ )
+
+ if (watch)
+ mdoc.watch(yarnRunStartIn = yarnRunBuildIn)
+ else {
+ mdoc.run(yarnRunBuildIn = yarnRunBuildIn)
+ if (relativize)
+ Relativize.relativize(websiteDir.toPath.resolve("build"))
+ }
+}
diff --git a/scripts/update-website.sh b/scripts/update-website.sh
deleted file mode 100755
index 53bab03ef..000000000
--- a/scripts/update-website.sh
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/env bash
-set -e
-
-cd "$(dirname "${BASH_SOURCE[0]}")/.."
-
-export FORCE_SIMPLE_VERSION=1
-
-sbt \
- interpreter-api/exportVersions \
- interpreter-api/publishLocal \
- scala-kernel-api/publishLocal
-
-./scripts/generate-website.sh
-
-if [ "${PUSH_WEBSITE:-""}" = 1 ]; then
- ./scripts/push-website.sh
-fi
-
diff --git a/scripts/website b/scripts/website
new file mode 160000
index 000000000..641b6f9e8
--- /dev/null
+++ b/scripts/website
@@ -0,0 +1 @@
+Subproject commit 641b6f9e87990c67430e4c188925390117ae3d57