From 912c9c8f06590f06a2a9df1c03d8ead43e96ec70 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 20 Oct 2020 00:20:15 +0000 Subject: [PATCH] add dotenv --- dotenv/README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++ dotenv/install.ps1 | 57 ++++++++++++++++++++++++++++++++++++++++++++ dotenv/install.sh | 42 +++++++++++++++++++++++++++++++++ dotenv/releases.js | 19 +++++++++++++++ 4 files changed, 177 insertions(+) create mode 100644 dotenv/README.md create mode 100644 dotenv/install.ps1 create mode 100644 dotenv/install.sh create mode 100644 dotenv/releases.js diff --git a/dotenv/README.md b/dotenv/README.md new file mode 100644 index 0000000..a8ef1bb --- /dev/null +++ b/dotenv/README.md @@ -0,0 +1,59 @@ +--- +title: dotenv +homepage: https://github.com/therootcompany/dotenv +tagline: | + dotenv: a cross-platform tool to load a .env and run a command. +--- + +## Updating `dotenv` + +```bash +webi dotenv@stable +``` + +Use the `@beta` tag for pre-releases, or `@x.y.z` for a specific version. + +## Cheat Sheet + +> dotenv makes it easy to run a command with a set of ENVs (environment +> variables) from a .env file. It works cross platform, and with any programming +> environment (Node.js, Go, Rust, Ruby, Python, etc) + +```bash +# Usage: dotenv [-f .env.alt] -- [arguments] + +# Example: +dotenv -f .env -- node server.js --debug +``` + +## How Precedence Works + +1. command line flags + - ex: `--port 8080` +2. existing environment variables + - ex: `export PORT=8080` or `env PORT=8080 mycommand` +3. first-loaded wins for multiple or cascading .env.\* files + - ex: `dotenv -f .env,.env.local` + +## ENV syntax + +```txt +# comments and blank lines are ignored + +# you can use quotes of either style +FOO=bar +FOO2="bar2 bar3" +FOO3='bar2 bar3' + +# 'export' will be trimmed and ignored +# (yay for bash compatibility) +export FOOBAR=excellent +``` + +## Why --? + +The `--` is a common convention for arguments parsers to let them know that +everything after the `--` should be treated as an argument (a word) rather than +a flag (not something like `--help`). + +You should use this whenever one command runs another command. diff --git a/dotenv/install.ps1 b/dotenv/install.ps1 new file mode 100644 index 0000000..62d57ed --- /dev/null +++ b/dotenv/install.ps1 @@ -0,0 +1,57 @@ +#!/usr/bin/env pwsh + +################## +# Install dotenv # +################## + +# Every package should define these variables +$pkg_cmd_name = "dotenv" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\dotenv.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\dotenv-v$Env:WEBI_VERSION\bin\dotenv.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\dotenv-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\dotenv-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 dotenv 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 dotenv" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\dotenv-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\dotenv.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 + Move-Item -Path ".\dotenv.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/dotenv/install.sh b/dotenv/install.sh new file mode 100644 index 0000000..7302641 --- /dev/null +++ b/dotenv/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function __init_dotenv() { + set -e + set -u + + ################## + # Install dotenv # + ################## + + # Every package should define these 6 variables + pkg_cmd_name="dotenv" + + pkg_dst_cmd="$HOME/.local/bin/dotenv" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/dotenv-v$WEBI_VERSION/bin/dotenv" + pkg_src_dir="$HOME/.local/opt/dotenv-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + pkg_install() { + # $HOME/.local/opt/dotenv-v1.0.0/bin + mkdir -p "$pkg_src_bin" + + # mv ./dotenv* "$HOME/.local/opt/dotenv-v1.0.0/bin/dotenv" + mv ./"$pkg_cmd_name"* "$pkg_src_cmd" + + # chmod a+x "$HOME/.local/xbin/dotenv-v1.0.0/bin/dotenv" + chmod a+x "$pkg_src_cmd" + } + + pkg_get_current_version() { + # 'dotenv version' has output in this format: + # v2.1.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8= + # This trims it down to just the version number: + # 2.0.0 + echo "$(dotenv --version 2>/dev/null | head -n 1 | cut -d' ' -f2 | sed 's:^v::')" + } + +} + +__init_dotenv diff --git a/dotenv/releases.js b/dotenv/releases.js new file mode 100644 index 0000000..39bdc5a --- /dev/null +++ b/dotenv/releases.js @@ -0,0 +1,19 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'therootcompany'; +var repo = 'dotenv'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + // remove checksums and .deb + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + console.info(JSON.stringify(all)); + }); +} -- 2.25.1