From 291fa89db3351e6af22e98690a0b7f7b3d0565f1 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 17 Sep 2024 06:18:21 +0000 Subject: [PATCH] wip: feat: add sqlc --- sqlc/README.md | 23 ++++++++++++++++++ sqlc/install.ps1 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ sqlc/install.sh | 44 ++++++++++++++++++++++++++++++++++ sqlc/releases.js | 17 +++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 sqlc/README.md create mode 100644 sqlc/install.ps1 create mode 100644 sqlc/install.sh create mode 100644 sqlc/releases.js diff --git a/sqlc/README.md b/sqlc/README.md new file mode 100644 index 000000000..c3513f90e --- /dev/null +++ b/sqlc/README.md @@ -0,0 +1,23 @@ +--- +title: sqlc +homepage: https://github.com/sqlc-dev/sqlc +tagline: | + sqlc: generate code from SQL (not the other way around) +--- + +To update or switch versions, run `webi sqlc@stable` (or `@v1.27`, `@beta`, +etc). + +### Files + +These are the files / directories that are created and/or modified with this +install: + +```text +~/.config/envman/PATH.env +~/.local/bin/sqlc +``` + +## Cheat Sheet + +TODO diff --git a/sqlc/install.ps1 b/sqlc/install.ps1 new file mode 100644 index 000000000..04ba44bec --- /dev/null +++ b/sqlc/install.ps1 @@ -0,0 +1,62 @@ +#!/usr/bin/env pwsh + +################ +# Install sqlc # +################ + +# Every package should define these variables +$pkg_cmd_name = "sqlc" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\sqlc.exe" +$pkg_dst_bin = "$Env:USERPROFILE\.local\bin" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\sqlc-v$Env:WEBI_VERSION\bin\sqlc.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\sqlc-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\sqlc-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download_dir = "$Env:USERPROFILE\Downloads\webi\$pkg_cmd_name\$Env:WEBI_VERSION" +$pkg_download_file = "$pkg_download_dir\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$pkg_download_file")) { + New-Item "$pkg_download_dir" -ItemType Directory -Force | Out-Null + Write-Output " Downloading $pkg_cmd_name v$Env:WEBI_VERSION from $Env:WEBI_PKG_URL to $pkg_download_file" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download_file.part" + & Move-Item "$pkg_download_file.part" "$pkg_download_file" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) { + Write-Output " Installing sqlc v$Env:WEBI_VERSION" + + # Remove any leftover tmp cruft and recreate the unpack + Remove-Item -Path ".local\tmp\sqlc-v$Env:WEBI_VERSION" -Recurse -ErrorAction Ignore + New-Item ".local\tmp\sqlc-v$Env:WEBI_VERSION" -ItemType Directory -Force | Out-Null + + # Unpack archive file into this temporary directory + Push-Location ".local\tmp\sqlc-v$Env:WEBI_VERSION" + # Windows BSD-tar handles zip. Imagine that. + Write-Output " Unpacking $pkg_download_file" + & tar xf "$pkg_download_file" + Pop-Location + + # Settle unpacked archive into place + Write-Output " Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force | Out-Null + Move-Item -Path ".local\tmp\sqlc-v$Env:WEBI_VERSION.\sqlc.exe" -Destination "$pkg_src_bin" + + # Remove any leftover tmp cruft & exit tmp + Remove-Item -Path ".local\tmp\sqlc-v$Env:WEBI_VERSION" -Recurse -ErrorAction Ignore + Pop-Location +} + +Write-Output " Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | Out-Null +New-Item "$pkg_dst_bin" -ItemType Directory -Force | Out-Null +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse + +$version_output = & "$pkg_dst_cmd" version +$version_line = $version_output | + Select-String -Pattern 'v\d+\.\d+' +Write-Output " Installed $version_line" diff --git a/sqlc/install.sh b/sqlc/install.sh new file mode 100644 index 000000000..38b9b435d --- /dev/null +++ b/sqlc/install.sh @@ -0,0 +1,44 @@ +#!/bin/sh +# shellcheck disable=SC2034 +set -x + +__init_sqlc() { + set -e + set -u + + ################ + # Install sqlc # + ################ + + # Every package should define these 6 variables + pkg_cmd_name="sqlc" + + pkg_dst_cmd="$HOME/.local/bin/sqlc" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/sqlc-v$WEBI_VERSION/bin/sqlc" + pkg_src_dir="$HOME/.local/opt/sqlc-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + pkg_install() { + # mkdir -p "$HOME/.local/opt/sqlc-v1.27.0/bin" + mkdir -p "$(dirname "$pkg_src_cmd")" + + # mv ./sqlc* "$HOME/.local/opt/sqlc-v1.27.0/bin/sqlc" + mv ./"$pkg_cmd_name"* "$pkg_src_cmd" + + # chmod a+x "$HOME/.local/opt/sqlc-v1.27.0/bin/sqlc" + chmod a+x "$pkg_src_cmd" + } + + pkg_get_current_version() { + # 'sqlc version' has output in this format: + # v1.27.0 + # This trims it down to just the version number: + # 1.27.0 + sqlc version 2> /dev/null | + head -n 1 | + sed 's:^v::' + } +} +__init_sqlc diff --git a/sqlc/releases.js b/sqlc/releases.js new file mode 100644 index 000000000..b6c710e7e --- /dev/null +++ b/sqlc/releases.js @@ -0,0 +1,17 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'sqlc-dev'; +var repo = 'sqlc'; + +module.exports = async function () { + let all = await github(null, owner, repo); + return all; +}; + +if (module === require.main) { + module.exports().then(function (all) { + all = require('../_webi/normalize.js')(all); + console.info(JSON.stringify(all)); + }); +}