chore: add onboarding experience when entering the Nix shell

This commit is contained in:
Lucien Cartier-Tilet 2024-06-27 07:57:36 +02:00
parent f335b610ea
commit aefe2b0766
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 50 additions and 0 deletions

48
misc/enter-shell-hook.sh Executable file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# $1 subcommand
display_command() {
echo -e "\t{{ Bold (Color \"#00FF00\" \"npm $1\") }}" | gum format -t template
echo ''
}
# $1 emoji, $2 text, $3 subcommand
display_command_and_comment() {
echo "$1 {{ Italic \"$2\" }}" | gum format -t template | gum format -t emoji
display_command "$3"
echo ''
}
what_next() {
echo ''
display_command_and_comment ':rocket:' 'Run the project in development mode' 'run dev'
display_command_and_comment ':wrench:' 'Build the project' 'run build'
display_command_and_comment ':eyes:' 'Preview the built project' 'run preview'
echo ''
}
setup() {
gum spin --spinner dot --title 'Installing dependencies with npm' --show-output -- npm i
echo ':wrench: All your dependencies are now installed! You can now use any of the following commands:' | gum format -t emoji
what_next
}
just_info() {
echo ''
echo 'No problem, you can always run this command later do install them:'
display_command 'install'
echo ''
echo 'You will then be able to execute the following commands:'
what_next
}
echo ''
echo ':stars: Welcome to the {{ Bold "alys.phundrak.com" }} development environment!' | gum format -t template | gum format -t emoji
if [ -d "node_modules" ]; then
echo ':star2: Your dependencies are already installed I see!' | gum format -t emoji
echo ':wrench: You can now run the following commands to run the project:' | gum format -t emoji
what_next
elif gum confirm 'Would you like to install the NPM dependencies of the project right now?'; then
setup
else
just_info
fi

View File

@ -2,7 +2,9 @@
pkgs.mkShell { pkgs.mkShell {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
nodejs_20 nodejs_20
gum
]; ];
shellHook = '' shellHook = ''
bash misc/enter-shell-hook.sh
''; '';
} }