Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redis-commander): add redis commander and cleanup based on guidelines #648

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions prettier/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env pwsh

####################
# Install prettier #
####################

function command-v-silent($cmdname) {
$my_cmd = Get-Command $command -ErrorAction SilentlyContinue
# $my_path = $my_cmd | Select-Object -ExpandProperty Definition

if ($my_cmd) {
return True
}
return False
}

function mktemp-d-t() {
# create random suffix for dirname
$my_bytes = New-Object byte[] 4
$my_rng = [Security.Cryptography.RNGCryptoServiceProvider]::Create()
$my_rng.GetBytes($bytes)
$my_hex_delimited = [BitConverter]::ToString($bytes)
$my_hex = $my_hex_delimited -replace "-", ""

# create random directory
$my_systmpdir = [System.IO.Path]::GetTempPath()
$my_tmpdir = Join-Path "$my_systmpdir" "$my_hex"
New-Item -ItemType Directory -Path "$my_tmpdir"

return "$my_tmpdir"
}

function npm-install-global($pkgname) {
# Fetch npm package manager
Write-Output "Checking for npm..."
if (-Not (command-v-silent("npm"))) {
& "$Env:USERPROFILE\.local\bin\webi-pwsh.ps1" node
}

if (command-v-silent($pkgname)) {
$my_cmd = Get-Command $pkgname
$my_cmd Select-Object -ExpandProperty Definition
Write-Host "Found '$my_cmd'"
return
}

$my_tmpdir = mktemp-d-t()

# npm install works best from a directory with no package.json
Push-Location "$my_tmpdir"
if (command-v-silent("npm")) {
& npm --location-golbal prettier
}
else {
& "$Env:USERPROFILE\.local\opt\node\npm" --location-golbal "$pkgname"
}
Pop-Location
}

npm-install-global prettier
48 changes: 48 additions & 0 deletions redis-commander/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: Redis Commander
homepage: https://joeferner.github.io/redis-commander/
tagline: |
Redis-Commander is a node.js web application used to view, edit, and manage a Redis Database.
---

To update or switch versions, run `npm install -g redis-commander@latest`.

### Files

These are the files / directories that are created and/or modified with this
install:

```text
~/.config/envman/PATH.env
~/.local/opt/node/bin/redis-commander
```

If [`node`](../node/) is not found, it will also be installed.

## Cheat Sheet

> Web-UI to display and edit data within multiple different Redis servers. It
> has support for the following data types to view, add, update and delete data:

- Strings
- Lists
- Sets
- Sorted Set
- Streams (Basic support based on HFXBus project from
<https://github.com/exocet-engineering/hfx-bus>, only view/add/delete data)
- ReJSON documents (Basic support, only for viewing values of ReJSON type keys)

List available commands:

```sh
redis-commander --help
```

Start redis commander with default settings:

```sh
redis-commander
```

This will open up web app at <http://127.0.0.1:8081> and will be connected to
local redis server at default port!
60 changes: 60 additions & 0 deletions redis-commander/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env pwsh

###########################
# Install redis-commander #
###########################

function command-v-silent($cmdname) {
$my_cmd = Get-Command $command -ErrorAction SilentlyContinue
# $my_path = $my_cmd | Select-Object -ExpandProperty Definition

if ($my_cmd) {
return True
}
return False
}

function mktemp-d-t() {
# create random suffix for dirname
$my_bytes = New-Object byte[] 4
$my_rng = [Security.Cryptography.RNGCryptoServiceProvider]::Create()
$my_rng.GetBytes($bytes)
$my_hex_delimited = [BitConverter]::ToString($bytes)
$my_hex = $my_hex_delimited -replace "-", ""

# create random directory
$my_systmpdir = [System.IO.Path]::GetTempPath()
$my_tmpdir = Join-Path "$my_systmpdir" "$my_hex"
New-Item -ItemType Directory -Path "$my_tmpdir"

return "$my_tmpdir"
}

function npm-install-global($pkgname) {
# Fetch npm package manager
Write-Output "Checking for npm..."
if (-Not (command-v-silent("npm"))) {
& "$Env:USERPROFILE\.local\bin\webi-pwsh.ps1" node
}

if (command-v-silent($pkgname)) {
$my_cmd = Get-Command $pkgname
$my_cmd Select-Object -ExpandProperty Definition
Write-Host "Found '$my_cmd'"
return
}

$my_tmpdir = mktemp-d-t()

# npm install works best from a directory with no package.json
Push-Location "$my_tmpdir"
if (command-v-silent("npm")) {
& npm --location-golbal redis-commander
}
else {
& "$Env:USERPROFILE\.local\opt\node\npm" --location-golbal "$pkgname"
}
Pop-Location
}

npm-install-global redis-commander
21 changes: 21 additions & 0 deletions redis-commander/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
set -e
set -u

__init_redis_commander() {
if test -z "$(npm --version 2> /dev/null)"; then
~/.local/bin/webi node
export PATH="$HOME/.local/opt/node/bin:$PATH"
fi

# In recent versions of node (~v18+), npm:
# - requires '--location=global' rather than '-g'
# - will modify 'package.json' when it shouldn't
my_tmpdir="$(mktemp -d -t "webi-npm-tmp.XXXXXXXXXX")"
(
cd "${my_tmpdir}" || exit 1
npm install --location=global redis-commander@latest
)
}

__init_redis_commander