Skip to content

Commit

Permalink
♻️ moving commands.d and libraries.d
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaillon committed Dec 4, 2024
1 parent fd88856 commit 7dcef0e
Show file tree
Hide file tree
Showing 59 changed files with 2,383 additions and 2,195 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*
!examples.d/*
!valet.d/*
!libraries.d/*
!commands.d/*
!extras/*
!valet
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: |
sed -i 's/copyright: "© Noyacode"/copyright: "© Noyacode for Valet v'"$(cat ./valet.d/version) updated on $(date +%F)"'"/' ./docs/i18n/en.yaml
sed -i 's/copyright: "© Noyacode"/copyright: "© Noyacode for Valet v'"$(cat ./version) updated on $(date +%F)"'"/' ./docs/i18n/en.yaml
cd docs
hugo \
--gc --minify \
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/self-test-installation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ on:
branches: [ "main" ]
paths:
- 'tests.d/1106-self-install/**'
- 'valet.d/commands.d/self-install.sh'
- 'valet.d/commands.d/self-extend.sh'
- 'commands.d/self-install.sh'
- 'commands.d/self-extend.sh'
pull_request:
paths:
- 'tests.d/1106-self-install/**'
- 'valet.d/commands.d/self-install.sh'
- 'valet.d/commands.d/self-extend.sh'
- 'commands.d/self-install.sh'
- 'commands.d/self-extend.sh'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ locale-gen ${LOCALE}.UTF-8

# ✅ copy files
COPY examples.d/ /root/.valet.d/examples.d/
COPY valet.d/ /opt/valet/valet.d/
COPY libraries.d/ /opt/valet/libraries.d/
COPY commands.d/ /opt/valet/commands.d/
COPY extras/ /opt/valet/extras/
COPY valet /opt/valet/valet

Expand All @@ -30,7 +31,7 @@ COPY valet /opt/valet/valet
RUN \
echo -e "#"'!'"/usr/bin/env bash"$'\n'"/opt/valet/valet \"\$@\"" > /usr/local/bin/valet; \
chmod +x /opt/valet/valet; \
chmod +x /opt/valet/valet.d/commands.d/self-build.sh; \
chmod +x /opt/valet/commands.d/self-build.sh; \
chmod +x /usr/local/bin/valet; \
export VALET_CONFIG_ENABLE_COLORS=true; \
valet self config --no-edit --override --export-current-values
Expand Down
6 changes: 3 additions & 3 deletions valet.d/commands.d/help.sh → commands.d/help.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
# Title: valet.d/commands.d/*
# Title: commands.d/*
# Description: this script is a valet command
# Author: github.com/jcaillon

# import the main script (should always be skipped if the command is run from valet, this is mainly for shellcheck)
if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
# shellcheck source=../core
source "$(dirname -- "$(command -v valet)")/valet.d/core"
# shellcheck source=../libraries.d/core
source "$(dirname -- "$(command -v valet)")/libraries.d/core"
fi
# --- END OF COMMAND COMMON PART

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function extractCommandYamls() {

local line content
local -i firstLineMatched=0 lastLineMatched=1 indentation=0
local IFS
while IFS= read -r line || [[ -n ${line:-} ]]; do
if [[ firstLineMatched -eq 0 ]]; then
if [[ ${line} == "${firstLine}" || ${line} == "${firstLineAlt}" ]]; then
Expand Down Expand Up @@ -254,7 +255,7 @@ _CMD_INCLUDED=1
# ====================
# Common variables
# ====================
# CMD_LIBRARY_DIRECTORIES = array of all the libs.d directories found in the user directory
# CMD_LIBRARY_DIRECTORIES = array of all the libraries.d directories found in the user directory
# CMD_ALL_FUNCTIONS_ARRAY = array of all the functions callable with a command
# CMD_ALL_FUNCTIONS = list all the functions callable with a command
# CMD_ALL_COMMANDS_ARRAY = array of all the commands
Expand Down Expand Up @@ -301,7 +302,8 @@ _CMD_INCLUDED=1
# shellcheck disable=SC2086
io::invoke declare -p ${!CMD_*}
local line
while read -r -d $'\n' line; do
local IFS
while IFS=$'\n' read -r -d $'\n' line; do
printf '%s\n' "${line#declare -? }"
done <<< "${RETURNED_VALUE}"
} >"${outputFile}"
Expand Down
54 changes: 31 additions & 23 deletions valet.d/commands.d/self-build.sh → commands.d/self-build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
# author: github.com/jcaillon
# Title: valet.d/build
# Title: libraries.d/build
# Description: This script is called during development to build the commands script.
# It reads all the files in which we could find command definitions and generates commands script.
# You can call this script directly in case calling ⌜valet self build⌝ is broken:
# $ ./valet.d/commands.d/self-build.sh
# $ ./commands.d/self-build.sh

#===============================================================
# >>> command: self build
Expand All @@ -28,11 +28,11 @@ set -Eeu -o pipefail
# - Makes a list of all the eligible files in which we could find command definitions.
# - For each file in this list, extract the command definitions.
# - Build your commands file (in your valet user directory) from these definitions.
# - Makes a list of all `libs.d` directories found in the user directory.
# - Makes a list of all `libraries.d` directories found in the user directory.
#
# You can call this script directly in case calling ⌜valet self build⌝ is broken:
#
#valet.d/commands.d/self-build.sh
# → commands.d/self-build.sh
# options:
# - name: -d, --user-directory <path>
# description: |-
Expand Down Expand Up @@ -99,11 +99,19 @@ function selfBuild() {
core::checkParseResults "${help:-}" "${parsingErrors:-}"
fi

log::debug "Building the valet user commands."

local originalLogLevel
if [[ ${silent:-} == "true" ]]; then
log::debug "Building the valet user commands silently."
log::getLevel && originalLogLevel="${RETURNED_VALUE}"
log::setLevel warning true
log::getLevel
if [[ ${RETURNED_VALUE} == "debug" || ${RETURNED_VALUE} == "trace" ]]; then
log::info "The silent option has been ignored because of the current log level."
silent=false
else
log::debug "Building the valet user commands silently."
log::getLevel && originalLogLevel="${RETURNED_VALUE}"
log::setLevel warning true
fi
fi

core::getUserDirectory
Expand All @@ -117,7 +125,7 @@ function selfBuild() {
local -a libraryDirectories=()
local -a commandDefinitionFiles=(
"${GLOBAL_VALET_HOME}/valet"
"${GLOBAL_VALET_HOME}/valet.d/commands.d"/*.sh
"${GLOBAL_VALET_HOME}/commands.d"/*.sh
)
if [[ ${coreOnly:-} != "true" ]]; then
if [[ -d "${userDirectory}" ]]; then
Expand All @@ -137,9 +145,9 @@ function selfBuild() {
local fileBasename="${file##*/}"
if [[ -d ${file} && ${fileBasename} != "."* && ${fileBasename} != "tests.d" ]]; then
# if directory we need to add it to the search list
# except if it starts with a . or if it is a tests.d or libs.d directory
if [[ ${fileBasename} == "libs.d" ]]; then
# if directory is named libs.d, we need to add it to libraryDirectories
# except if it starts with a . or if it is a tests.d or libraries.d directory
if [[ ${fileBasename} == "libraries.d" ]]; then
# if directory is named libraries.d, we need to add it to libraryDirectories
libraryDirectories+=("${file}")
else
listOfDirectories+="${file}"$'\n'
Expand Down Expand Up @@ -245,7 +253,7 @@ function bumpValetBuildVersion() {

string::bumpSemanticVersion "${currentVersion}" "patch" "false"

printf '%s' "${RETURNED_VALUE}" >"${GLOBAL_VALET_HOME}/valet.d/version"
printf '%s' "${RETURNED_VALUE}" >"${GLOBAL_VALET_HOME}/version"

log::info "The valet build version has been bumped to ⌜${RETURNED_VALUE}⌝."
}
Expand Down Expand Up @@ -674,28 +682,28 @@ if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
# do not read the commands in that case
_CMD_INCLUDED=1

_VALETD_DIR="${BASH_SOURCE[0]:-"${0}"}"
if [[ "${_VALETD_DIR}" != /* ]]; then
if pushd "${_VALETD_DIR%/*}" &>/dev/null; then
_VALETD_DIR="${PWD}"
_COMMANDS_DIR="${BASH_SOURCE[0]:-"${0}"}"
if [[ "${_COMMANDS_DIR}" != /* ]]; then
if pushd "${_COMMANDS_DIR%/*}" &>/dev/null; then
_COMMANDS_DIR="${PWD}"
popd &>/dev/null || :
else _VALETD_DIR="${PWD}"; fi
else _VALETD_DIR="${_VALETD_DIR%/*}"; fi
else _COMMANDS_DIR="${PWD}"; fi
else _COMMANDS_DIR="${_COMMANDS_DIR%/*}"; fi

# shellcheck source=../core
source "${_VALETD_DIR%/*}/core"
# shellcheck source=../libraries.d/core
source "${_COMMANDS_DIR%/*}/libraries.d/core"
else
unset _NOT_EXECUTED_FROM_VALET
fi
# --- END OF COMMAND COMMON PART

# shellcheck source=self-build-utils
source self-build-utils
# shellcheck source=../lib-array
# shellcheck source=../libraries.d/lib-array
source array
# shellcheck source=../lib-io
# shellcheck source=../libraries.d/lib-io
source io
# shellcheck source=../lib-string
# shellcheck source=../libraries.d/lib-string
source string

# if this script is run directly, execute the function, otherwise valet will do it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
# Title: valet.d/commands.d/*
# Title: commands.d/*
# Description: this script is a valet command
# Author: github.com/jcaillon

# import the main script (should always be skipped if the command is run from valet, this is mainly for shellcheck)
if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
# shellcheck source=../core
source "$(dirname -- "$(command -v valet)")/valet.d/core"
# shellcheck source=../libraries.d/core
source "$(dirname -- "$(command -v valet)")/libraries.d/core"
fi
# --- END OF COMMAND COMMON PART

Expand Down
40 changes: 20 additions & 20 deletions valet.d/commands.d/self-document.sh → commands.d/self-document.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
# Title: valet.d/commands.d/*
# Title: commands.d/*
# Description: this script is a valet command
# Author: github.com/jcaillon

# import the main script (should always be skipped if the command is run from valet, this is mainly for shellcheck)
if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
# shellcheck source=../core
source "$(dirname -- "$(command -v valet)")/valet.d/core"
# shellcheck source=../libraries.d/core
source "$(dirname -- "$(command -v valet)")/libraries.d/core"
fi
# --- END OF COMMAND COMMON PART

# shellcheck source=../lib-string
# shellcheck source=../libraries.d/lib-string
source string
# shellcheck source=../lib-system
# shellcheck source=../libraries.d/lib-system
source system
# shellcheck source=../lib-array
# shellcheck source=../libraries.d/lib-array
source array

#===============================================================
Expand Down Expand Up @@ -122,8 +122,8 @@ function selfDocument::getAllFunctionsDocumentation() {
log::info "Generating documentation for all the functions."
fi

# get all the files in the valet.d directory
io::listFiles "${GLOBAL_VALET_HOME}/valet.d"
# get all the files in the libraries.d directory
io::listFiles "${GLOBAL_VALET_HOME}/libraries.d"
local -a filesToAnalyze=("${RETURNED_ARRAY[@]}")

# add each file of each user library directory
Expand Down Expand Up @@ -281,12 +281,12 @@ function selfRelease_writeAllFunctionsToCodeSnippets() {
body+="\$0"

content+="
\"${functionName}\": {
\"prefix\": \"${functionName}\",
\"description\": \"${firstSentence}...\",
\"scope\": \"\",
\"body\": [ \"${body//\"/\\\"}\" ]
},"$'\n'
\"${functionName}\": {
\"prefix\": \"${functionName}\",
\"description\": \"${firstSentence}...\",
\"scope\": \"\",
\"body\": [ \"${body//\"/\\\"}\" ]
},"$'\n'

commentedDocumentation=""
while IFS=$'\n' read -rd $'\n' line; do
Expand All @@ -298,12 +298,12 @@ function selfRelease_writeAllFunctionsToCodeSnippets() {
commentedDocumentation="${commentedDocumentation//$'\n'/\\n}"

content+="
\"${functionName}#withdoc\": {
\"prefix\": \"${functionName}#withdoc\",
\"description\": \"${firstSentence}...\",
\"scope\": \"\",
\"body\": [ \"${commentedDocumentation}${body//\"/\\\"}\" ]
},"$'\n'
\"${functionName}#withdoc\": {
\"prefix\": \"${functionName}#withdoc\",
\"description\": \"${firstSentence}...\",
\"scope\": \"\",
\"body\": [ \"${commentedDocumentation}${body//\"/\\\"}\" ]
},"$'\n'
done

# load the existing file content
Expand Down
11 changes: 6 additions & 5 deletions valet.d/commands.d/self-export.sh → commands.d/self-export.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
set -Eeu -o pipefail
# Title: valet.d/commands.d/*
# Title: commands.d/*
# Description: this script is a valet command
# Author: github.com/jcaillon

# import the main script (should always be skipped if the command is run from valet, this is mainly for shellcheck)
if [[ -z "${GLOBAL_CORE_INCLUDED:-}" ]]; then
# shellcheck source=../core
source "$(dirname -- "$(command -v valet)")/valet.d/core"
# shellcheck source=../libraries.d/core
source "$(dirname -- "$(command -v valet)")/libraries.d/core"
fi
# --- END OF COMMAND COMMON PART

Expand Down Expand Up @@ -66,11 +66,12 @@ function selfExport() {
# export all libraries
if [[ ${exportAll:-} == "true" ]]; then
local library
for library in "${GLOBAL_VALET_HOME}/valet.d/lib-"*; do
for library in "${GLOBAL_VALET_HOME}/libraries.d/lib-"*; do
local -i lineNumber=0

# read the library file line by line
while IFS=$'\n' read -r line|| [[ -n ${line:-} ]]; do
local IFS
while IFS=$'\n' read -r -d $'\n' line|| [[ -n ${line:-} ]]; do
if [[ ${lineNumber} -gt 1 && ${line} != "source "* ]]; then
output+="${line}"$'\n'
fi
Expand Down
Loading

0 comments on commit 7dcef0e

Please sign in to comment.