From 00f34e0c96799220a0392787644f193984634ee4 Mon Sep 17 00:00:00 2001 From: Sergi B Date: Mon, 26 Oct 2020 10:47:55 +0100 Subject: [PATCH] Added pandoc installer --- pandoc/README.md | 30 ++++++++++++++++++++++++ pandoc/install.ps1 | 58 ++++++++++++++++++++++++++++++++++++++++++++++ pandoc/install.sh | 43 ++++++++++++++++++++++++++++++++++ pandoc/releases.js | 20 ++++++++++++++++ 4 files changed, 151 insertions(+) create mode 100644 pandoc/README.md create mode 100644 pandoc/install.ps1 create mode 100644 pandoc/install.sh create mode 100644 pandoc/releases.js diff --git a/pandoc/README.md b/pandoc/README.md new file mode 100644 index 0000000..55d1c50 --- /dev/null +++ b/pandoc/README.md @@ -0,0 +1,30 @@ +--- +title: Pandoc +homepage: https://github.com/jgm/pandoc +tagline: | + Pandoc is a Haskell library for converting from one markup format to another. +--- + +## Updating `pandoc` + +```bash +webi pandoc@stable +``` + +Use the `@beta` tag for pre-releases. + +## Cheat Sheet + +> Pandoc is a Haskell library for converting from one markup format to another, and a command-line tool that uses this library. + +```bash +pandoc -o output.html input.txt +``` + +Specifying formats + +```bash +pandoc -f markdown -t latex hello.txt +``` + +Documentation: https://pandoc.org/MANUAL.html diff --git a/pandoc/install.ps1 b/pandoc/install.ps1 new file mode 100644 index 0000000..3358d19 --- /dev/null +++ b/pandoc/install.ps1 @@ -0,0 +1,58 @@ +#!/usr/bin/env pwsh + +################### +# Install pandoc # +################### + +# Every package should define these variables +$pkg_cmd_name = "pandoc" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\pandoc.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\pandoc-v$Env:WEBI_VERSION\bin\pandoc.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\pandoc-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\pandoc-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading pandoc from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing pandoc" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\pandoc-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\pandoc.exe" -Recurse -ErrorAction Ignore + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path ".\pandoc-*\pandoc.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/pandoc/install.sh b/pandoc/install.sh new file mode 100644 index 0000000..b69a585 --- /dev/null +++ b/pandoc/install.sh @@ -0,0 +1,43 @@ +{ + set -e + set -u + + ################### + # Install pandoc # + ################### + + # Every package should define these 6 variables + pkg_cmd_name="pandoc" + + pkg_dst_cmd="$HOME/.local/bin/pandoc" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/pandoc-v$WEBI_VERSION/bin/pandoc" + pkg_src_dir="$HOME/.local/opt/pandoc-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/pandoc-v2.10.1/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./pandoc-*/pandoc ~/.local/opt/pandoc-v2.10.1/bin/pandoc + mv ./pandoc-*/bin/pandoc "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'pandoc --version' has output in this format: + # pandoc 2.10.1 + # Compiled with pandoc-types 1.21, texmath 0.12.0.3, skylighting 0.8.5 + # Default user data directory: /home/sergi/.local/share/pandoc or /home/sergi/.pandoc + # Copyright (C) 2006-2020 John MacFarlane + # Web: https://pandoc.org + # This is free software; see the source for copying conditions. + # There is no warranty, not even for merchantability or fitness + # for a particular purpose. + # This trims it down to just the version number: + # 2.10.1 + echo $(pandoc --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2) + } +} diff --git a/pandoc/releases.js b/pandoc/releases.js new file mode 100644 index 0000000..ef1257b --- /dev/null +++ b/pandoc/releases.js @@ -0,0 +1,20 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'jgm'; +var repo = 'pandoc'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); + }); +} -- 2.25.1