@salefronts/cli 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/env.sh +48 -0
- package/commands/help.js +1 -0
- package/package.json +1 -1
package/commands/env.sh
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail # Safe mode
|
|
4
|
+
|
|
5
|
+
# Ensure required dependencies are installed
|
|
6
|
+
for cmd in yq; do
|
|
7
|
+
if ! command -v "$cmd" >/dev/null 2>&1; then
|
|
8
|
+
echo "❌ Error: $cmd is required but not installed."
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
done
|
|
12
|
+
|
|
13
|
+
# Prompt or get file argument
|
|
14
|
+
if [ -z "${1:-}" ]; then
|
|
15
|
+
echo -n "📄 Enter path to the secret file (e.g., secret.yaml): "
|
|
16
|
+
read -r SECRET_FILE
|
|
17
|
+
else
|
|
18
|
+
SECRET_FILE=$1
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
# Check file exists
|
|
22
|
+
if [ ! -f "$SECRET_FILE" ]; then
|
|
23
|
+
echo "❌ Error: File not found: $SECRET_FILE"
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Validate kind
|
|
28
|
+
KIND=$(yq eval '.kind' "$SECRET_FILE")
|
|
29
|
+
if [ "$KIND" != "Secret" ]; then
|
|
30
|
+
echo "❌ Error: File is not a Kubernetes Secret (found kind: $KIND)"
|
|
31
|
+
exit 1
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# Determine env filename
|
|
35
|
+
BASENAME=$(basename "$SECRET_FILE")
|
|
36
|
+
DIRNAME=$(dirname "$SECRET_FILE")
|
|
37
|
+
|
|
38
|
+
if [ "$BASENAME" = "secret.yaml" ]; then
|
|
39
|
+
ENV_PATH="$DIRNAME/.env"
|
|
40
|
+
else
|
|
41
|
+
NAME_PREFIX=$(echo "$BASENAME" | sed -E 's/-?secret\.ya?ml$//' | sed -E 's/\..*$//')
|
|
42
|
+
ENV_PATH="$DIRNAME/.env-$NAME_PREFIX"
|
|
43
|
+
fi
|
|
44
|
+
|
|
45
|
+
# Convert stringData to .env format
|
|
46
|
+
yq -o=json '.stringData // {}' "$SECRET_FILE" | jq -r 'to_entries[] | "\(.key)=\(.value)"' > "$ENV_PATH"
|
|
47
|
+
|
|
48
|
+
echo "✅ Done! Generated .env file at: $ENV_PATH"
|
package/commands/help.js
CHANGED
|
@@ -16,6 +16,7 @@ function showHelp() {
|
|
|
16
16
|
console.log(' uuidv7 Generate a UUID v7');
|
|
17
17
|
console.log(' seal Seal Kubernetes secrets');
|
|
18
18
|
console.log(' unseal Unseal Kubernetes secrets');
|
|
19
|
+
console.log(' env Generate .env file from K8s secret.yaml');
|
|
19
20
|
console.log(' tag Tagging version for the latest commit on main')
|
|
20
21
|
}
|
|
21
22
|
|