diff --git a/src/common-utils/_install-bin.sh b/src/common-utils/_install-bin.sh new file mode 100755 index 0000000..a149988 --- /dev/null +++ b/src/common-utils/_install-bin.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +### Init directories +caller_filename=$(ps -o args= $PPID) +caller_filepath=$(readlink -f ${caller_filename##/bin/sh}) +export source=$(dirname $caller_filepath) +export feature=$(basename $source | sed 's/_.*$//') +export target=${1:-/usr/local/share}/$feature + +### Create links to utils in /usr/local/bin +find $target -type f -name "_*.sh" -exec echo {} \; -exec chmod +x {} \; | while read file +do + link=/usr/local/bin/$(basename $file | sed 's/^_//;s/.sh$//') + ln -sf $file $link +done diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index 07406f0..deb36fc 100755 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "name": "Common Utils", - "version": "1.1.5", + "version": "1.1.6", "description": "Common utils for tomgrv/devcontainer-features", "dependsOn": { "ghcr.io/devcontainers/features/common-utils": {} diff --git a/src/common-utils/install-bin.sh b/src/common-utils/install-bin.sh deleted file mode 100755 index 9753252..0000000 --- a/src/common-utils/install-bin.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -set -e - -### Create links to utils in /usr/bin -find $target -type f -name "_*.sh" -exec echo {} \; -exec chmod +x {} \; | while read file -do - link=/usr/bin/$(basename $file | sed -e 's/^_//' -e 's/.sh$//') - rm -f $link || true - ln -s $file $link || true -done diff --git a/src/common-utils/install.sh b/src/common-utils/install.sh index 4071f86..5d1527a 100755 --- a/src/common-utils/install.sh +++ b/src/common-utils/install.sh @@ -22,3 +22,4 @@ done ### Install this feature $(dirname $0)/_install-feature.sh +$(dirname $0)/_install-bin.sh diff --git a/src/gitutils/install-stubs.sh b/src/gitutils/install-stubs.sh deleted file mode 100755 index 9d1adc7..0000000 --- a/src/gitutils/install-stubs.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -set -e - -### Merge all files from stub folder to root with git merge-file -echo "Merging stubs files..." -for file in $(find $source/stubs -type f); do - - ### Get middle part of the path - folder=$(dirname ${file#$source/stubs/}) - - ### Create folder if not exists - mkdir -p $folder - - ### Merge file - echo "Merge $folder/$(basename $file)" - git merge-file -p $file $folder/$(basename $file) ${folder#$source/}/$(basename $file) >$folder/$(basename $file) - - ### Apply rights - chmod $(stat -c "%a" $file) $folder/$(basename $file) -done - -### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash -echo "Add files to .gitignore..." -for file in $(find . -type f -name "#*" -not -path "./stubs/*" -not -path "./node_modules/*" -not -path "./vendors/*"); do - - echo "Add $file to .gitignore" - - ### Remove trailing # and leading ./# - clean=${file#./#} - - ### Add to .gitignore if not already there - grep -qxF $clean .gitignore || echo "$clean" >>.gitignore - - ### Rename file - mv $file $clean -done diff --git a/src/gitutils/install.sh b/src/gitutils/install.sh index 9f524e9..3d8594b 100755 --- a/src/gitutils/install.sh +++ b/src/gitutils/install.sh @@ -3,3 +3,4 @@ set -e ### Install this feature install-feature +install-stubs diff --git a/src/gitversion/devcontainer-feature.json b/src/gitversion/devcontainer-feature.json index 385ba00..7da5b81 100755 --- a/src/gitversion/devcontainer-feature.json +++ b/src/gitversion/devcontainer-feature.json @@ -1,6 +1,6 @@ { "name": "GitVersion feature", - "version": "3.0.1", + "version": "3.0.2", "description": "Add gitversion to your devcontainer", "dependsOn": { "ghcr.io/devcontainers/features/dotnet": "", diff --git a/src/gitversion/install-stubs.sh b/src/gitversion/install-stubs.sh deleted file mode 100755 index da24087..0000000 --- a/src/gitversion/install-stubs.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -set -e - -### Merge all files from stub folder to root with git merge-file -echo "Merging stubs files" -for file in $(find $source/stubs -type f); do - - ### Get middle part of the path - folder=$(dirname ${file#$source/stubs/}) - - ### Create folder if not exists - mkdir -p $folder - - ### Merge file - echo "Merge $folder/$(basename $file)" - git merge-file -p $file $folder/$(basename $file) ${folder#$source/}/$(basename $file) >$folder/$(basename $file) - - ### Apply rights - chmod $(stat -c "%a" $file) $folder/$(basename $file) -done - -### Find all file with a trailing slash outside dist folder, make sure they are added to .gitignore and remove the trailing slash -echo "Add files to .gitignore" -for file in $(find . -type f -name "#*" ! -path "*/stubs/*" ! -path "./node_modules/*" ! -path "./vendors/*"); do - - echo "Add $file to .gitignore" - - ### Remove # occurences in file path - clean=${file#./#} - - ### Add to .gitignore if not already there - grep -qxF $clean .gitignore || echo "$clean" >>.gitignore - - ### Rename file - mv $file $clean -done diff --git a/src/gitversion/install.sh b/src/gitversion/install.sh index ddeec3a..72b9228 100755 --- a/src/gitversion/install.sh +++ b/src/gitversion/install.sh @@ -3,3 +3,4 @@ set -e ### Install feature install-feature +install-stubs diff --git a/src/larasets/_art.sh b/src/larasets/_art.sh new file mode 100755 index 0000000..a171308 --- /dev/null +++ b/src/larasets/_art.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +workspace=${containerWorkspaceFolder:-${CODESPACE_VSCODE_FOLDER:-.}} +[ -n "$LARAVEL_SAIL" ] && [ "$LARAVEL_SAIL" -eq 1 ] && sail artisan "$@" || php -d xdebug.mode=off $workspace/artisan "$@" diff --git a/src/larasets/_init.sh b/src/larasets/_init.sh new file mode 100644 index 0000000..dc513e3 --- /dev/null +++ b/src/larasets/_init.sh @@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +workspace=${containerWorkspaceFolder:-${CODESPACE_VSCODE_FOLDER:-.}} + +### Install composer dependencies if composer.json exists +if [ -f $workspace/composer.json ]; then + echo "Install composer dependencies" | npx --yes chalk-cli --stdin blue + composer install --ansi --ignore-platform-reqs --no-interaction --no-progress +fi + +### Install npm dependencies if package.json exists +if [ -f $workspace/package.json ]; then + echo "Install npm dependencies" | npx --yes chalk-cli --stdin blue + npm install --ws --if-present --include-workspace-root || npm install +fi + +### Init db if sqlite and not exists +if [ -n "$DB_CONNECTION" ] && [ "$DB_CONNECTION" = "sqlite" ]; then + + ### Set default sqlite db + if [ -z "$DB_DATABASE" ]; then + export DB_DATABASE=database/database.sqlite + fi + + echo "Ensure sqlite db $DB_DATABASE exist" | npx --yes chalk-cli --stdin blue + touch $workspace/$DB_DATABASE +fi + +### Init env +echo "Init dotenv" | npx --yes chalk-cli --stdin blue +touch $workspace/.env + +### Add APP_KEY to .env if it does not exist, in one line +grep -q "APP_KEY" $workspace/.env || echo APP_KEY=null >>$workspace/.env diff --git a/src/larasets/_run.sh b/src/larasets/_run.sh new file mode 100755 index 0000000..330283a --- /dev/null +++ b/src/larasets/_run.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +workspace=${containerWorkspaceFolder:-${CODESPACE_VSCODE_FOLDER:-.}} +[ -n "$LARAVEL_SAIL" ] && [ "$LARAVEL_SAIL" -eq 1 ] && sail npm run "$@" || npm run "$@" diff --git a/src/larasets/_sail.sh b/src/larasets/_sail.sh new file mode 100755 index 0000000..ad4bb98 --- /dev/null +++ b/src/larasets/_sail.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e + +workspace=${containerWorkspaceFolder:-${CODESPACE_VSCODE_FOLDER:-.}} +sh $([ -f "sail" ] && echo sail || [ -f "$workspace/vendor/bin/sail" ] && echo $workspace/vendor/bin/sail) "$@" diff --git a/src/larasets/_seed.sh b/src/larasets/_seed.sh new file mode 100644 index 0000000..1fff405 --- /dev/null +++ b/src/larasets/_seed.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +art key:generate --force +art migrate --seed --graceful --no-interaction +art config:cache +art view:cache +art route:cache +art event:cache +art optimize:clear diff --git a/src/larasets/configure-aliases.sh b/src/larasets/configure-aliases.sh deleted file mode 100755 index 1661c83..0000000 --- a/src/larasets/configure-aliases.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -set -e - -#### Do not use sudo if on mingw -if [ $(uname) = "Linux" ] || [ $(uname) = "Darwin" ]; then - SUDO=sudo -else - SUDO= -fi - -#### Create aliases -$SUDO cat <~/.bash_aliases - -alias gitv='gitversion' -alias sail='sh $([ -f sail ] && echo sail || echo ${containerWorkspaceFolder:-.}/vendor/bin/sail)' - -art() { - test -n "\$LARAVEL_SAIL" && test "\$LARAVEL_SAIL" -eq 1 && sail artisan "\$@" || php -d xdebug.mode=off \${CODESPACE_VSCODE_FOLDER:-.}/artisan "\$@" -} && export -f art - -srv() { - test -n "\$LARAVEL_SAIL" && test "\$LARAVEL_SAIL" -eq 1 && sail npx --yes pm2 "\$@" || npx --yes pm2 "\$@" -} && export -f srv - -run() { - srv restart server_\$1 || srv --name server_\$1 start npm -- run \$1 -} && export -f run - -log() { - srv logs server_\$1 -} && export -f log - -refresh() { - art config:cache - art view:cache - art route:cache - art optimize:clear -} && export -f refresh - -init() { - test -f \${CODESPACE_VSCODE_FOLDER:-.}/artisan || return 1 - test -n "\$LARAVEL_SAIL" && test "\$LARAVEL_SAIL" -eq 1 && sail up --build -d - art key:generate --force - refresh - art migrate --graceful --no-interaction - run dev -} && export -f init - -EOF diff --git a/src/larasets/configure-project.sh b/src/larasets/configure-project.sh deleted file mode 100755 index 3475a15..0000000 --- a/src/larasets/configure-project.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/sh -set -e - -### Install composer dependencies if composer.json exists -if [ -f ${containerWorkspaceFolder:-.}/composer.json ]; then - echo "Install composer dependencies" | npx --yes chalk-cli --stdin blue - composer install --ansi --ignore-platform-reqs --no-interaction --no-progress -fi - -### Install npm dependencies if package.json exists -if [ -f ${containerWorkspaceFolder:-.}/package.json ]; then - echo "Install npm dependencies" | npx --yes chalk-cli --stdin blue - npm install --ws --if-present --include-workspace-root || npm install -fi - -### Init db if sqlite and not exists -if [ -n "$DB_CONNECTION" ] && [ "$DB_CONNECTION" = "sqlite" ]; then - - ### Set default sqlite db - if [ -z "$DB_DATABASE" ]; then - export DB_DATABASE=database/database.sqlite - fi - - echo "Ensure sqlite db $DB_DATABASE exist" | npx --yes chalk-cli --stdin blue - touch ${containerWorkspaceFolder:-.}/$DB_DATABASE -fi - -### Init env -echo "Init dotenv" | npx --yes chalk-cli --stdin blue -touch ${containerWorkspaceFolder:-.}/.env - -### Add APP_KEY to .env if it does not exist, in one line -grep -q "APP_KEY" ${containerWorkspaceFolder:-.}/.env || echo APP_KEY=null >>${containerWorkspaceFolder:-.}/.env - -### Init laravel -if [ -f ${containerWorkspaceFolder:-.}/vendor/bin/sail ] && [ "${LARAVEL_SAIL}" -eq "1" ]; then - - echo "Init laravel with sail" | npx --yes chalk-cli --stdin green - ${containerWorkspaceFolder:-.}/vendor/bin/sail up --build -d - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan key:generate --force - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan config:cache - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan view:cache - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan route:cache - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan optimize:clear - ${containerWorkspaceFolder:-.}/vendor/bin/sail artisan migrate --seed --graceful --no-interaction - ${containerWorkspaceFolder:-.}/vendor/bin/sail npx --yes pm2 --name server_dev start npm -- run dev - -elif [ -f ${containerWorkspaceFolder:-.}/artisan ]; then - - echo "Init laravel with artisan" | npx --yes chalk-cli --stdin green - php -d xdebug.mode=off artisan key:generate --force - php -d xdebug.mode=off artisan config:cache - php -d xdebug.mode=off artisan view:cache - php -d xdebug.mode=off artisan route:cache - php -d xdebug.mode=off artisan optimize:clear - php -d xdebug.mode=off artisan migrate --seed --graceful --no-interaction - npx --yes pm2 --name server_dev start npm -- run dev -else - echo "No laravel project found" | npx --yes chalk-cli --stdin yellow -fi diff --git a/src/larasets/configure-sail.sh b/src/larasets/configure-sail.sh new file mode 100644 index 0000000..0216471 --- /dev/null +++ b/src/larasets/configure-sail.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +### Init workspace +init + +### Build sail if needed +if [ -n "$LARAVEL_SAIL" ] && [ "$LARAVEL_SAIL" -eq 1 ]; then + sail build --no-cache +fi diff --git a/src/larasets/devcontainer-feature.json b/src/larasets/devcontainer-feature.json index cc466a7..530cb99 100755 --- a/src/larasets/devcontainer-feature.json +++ b/src/larasets/devcontainer-feature.json @@ -1,42 +1,147 @@ { "name": "Laravel settings", - "version": "3.0.2", + "version": "3.0.11", "description": "A feature to add useful laravel settings to your shell.", "containerEnv": { "APP_DEBUG": "true", "APP_ENV": "local", - "APP_PORT": "80", - "APP_URL": "https://${localEnv:CODESPACE_NAME}-${containerEnv:APP_PORT}.${localEnv:GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}", - "ASSET_URL": "${containerEnv:APP_URL}", "LARAVEL_SAIL": "1", "DB_CONNECTION": "sqlite", "DB_DATABASE": "database/database.sqlite", "SAIL_XDEBUG_MODE": "develop,debug", "SAIL_XDEBUG_CONFIG": "client_host=host.docker.internal idekey=vscode", - "XDEBUG_MODE": "off", - "MAIL_MAILER": "smtp", - "MAIL_HOST": "mailpit", - "MAIL_PORT": "1025", - "MAIL_USERNAME": "null", - "MAIL_PASSWORD": "null", - "MAIL_ENCRYPTION": "null" + "XDEBUG_MODE": "off" }, "customizations": { "vscode": { "settings": { "triggerTaskOnSave.tasks": { - "php-refresh-config": [ + "art-cache-config": [ "**/config.php", "config/*.php", ".env" ], - "php-refresh-views": [ + "art-cache-views": [ "packages/**/*.blade.php" ], - "php-refresh-routes": [ + "art-cache-routes": [ "**/[Rr]outes/*.php" - ], - "php-refresh-db": [] + ] + }, + "launch": { + "configurations": [ + { + "name": "Listen for Xdebug from Laravel sail", + "type": "php", + "request": "launch", + "port": 9003, + "pathMappings": { + "/var/www/html": "${workspaceFolder}" + } + } + ] + }, + "tasks": { + "version": "2.0.0", + "tasks": [ + { + "label": "art-cache-config", + "type": "shell", + "command": "art config:cache", + "hide": true, + "presentation": { + "panel": "dedicated", + "reveal": "silent", + "close": true + } + }, + { + "label": "art-cache-views", + "type": "shell", + "command": "art view:cache", + "hide": true, + "presentation": { + "panel": "dedicated", + "reveal": "silent", + "close": true + } + }, + { + "label": "art-cache-routes", + "type": "shell", + "command": "art route:cache", + "hide": true, + "presentation": { + "panel": "dedicated", + "reveal": "silent", + "close": true + } + }, + { + "label": "up", + "dependsOn": [ + "sail up", + "art-cache-config", + "art-cache-views", + "art-cache-routes", + "queue", + "schedule", + "vite" + ], + "dependsOrder": "sequence" + }, + { + "label": "sail up", + "type": "shell", + "command": "sail up --wait && seed", + "presentation": { + "panel": "dedicated", + "reveal": "silent", + "close": true + }, + "hide": true + }, + { + "label": "sail down", + "type": "shell", + "command": "sail down", + "presentation": { + "panel": "dedicated", + "reveal": "silent", + "close": true + }, + "hide": true + }, + { + "label": "queue", + "type": "shell", + "command": "art queue:work --queue=default --sleep=3 --tries=3", + "presentation": { + "panel": "dedicated", + "reveal": "silent" + }, + "hide": true + }, + { + "label": "schedule", + "type": "shell", + "command": "art schedule:work", + "presentation": { + "panel": "dedicated", + "reveal": "silent" + }, + "hide": true + }, + { + "label": "vite", + "type": "shell", + "command": "run dev", + "presentation": { + "panel": "dedicated", + "reveal": "always" + } + } + ] } }, "extensions": [ @@ -58,20 +163,7 @@ "davidanson.vscode-markdownlint", "pcbowers.alpine-intellisense", "laravel.vscode-laravel" - ], - "launch": { - "configurations": [ - { - "name": "Listen for Xdebug from Laravel sail", - "type": "php", - "request": "launch", - "port": 9003, - "pathMappings": { - "/var/www/html": "${workspaceFolder}" - } - } - ] - } + ] } }, "dependsOn": { @@ -84,5 +176,8 @@ "installsAfter": [ "ghcr.io/tomgrv/devcontainer-features/common-utils" ], + "legacyIds": [ + "larasets" + ], "postStartCommand": "configure-feature larasets" } diff --git a/src/larasets/install.sh b/src/larasets/install.sh index 9f524e9..10b11e1 100755 --- a/src/larasets/install.sh +++ b/src/larasets/install.sh @@ -3,3 +3,4 @@ set -e ### Install this feature install-feature +install-bin