@@ -39,14 +39,64 @@ check_version_manager() {
3939 echo " mise"
4040 elif command -v asdf & > /dev/null; then
4141 echo " asdf"
42+ elif command -v rvm & > /dev/null && command -v nvm & > /dev/null; then
43+ echo " rvm+nvm"
44+ elif command -v rvm & > /dev/null; then
45+ echo " rvm"
46+ elif command -v nvm & > /dev/null; then
47+ echo " nvm"
4248 else
43- print_error " No version manager found. Please install mise or asdf :"
49+ print_error " No version manager found. Please install one of :"
4450 echo " mise (recommended): https://mise.jdx.dev/"
45- echo " asdf (legacy): https://asdf-vm.com/"
51+ echo " asdf: https://asdf-vm.com/"
52+ echo " rvm + nvm: https://rvm.io/ + https://github.com/nvm-sh/nvm"
4653 exit 1
4754 fi
4855}
4956
57+ set_ruby_version () {
58+ local version=" $1 "
59+ local version_manager=" $2 "
60+
61+ case " $version_manager " in
62+ mise|asdf)
63+ # Handled via .tool-versions
64+ ;;
65+ rvm|rvm+nvm)
66+ print_header " Setting Ruby $version with rvm"
67+ if ! rvm list strings | grep -q " ^ruby-${version} $" ; then
68+ print_warning " Ruby $version not installed. Installing..."
69+ rvm install " $version "
70+ fi
71+ rvm use " $version "
72+ ;;
73+ esac
74+ }
75+
76+ set_node_version () {
77+ local version=" $1 "
78+ local version_manager=" $2 "
79+
80+ case " $version_manager " in
81+ mise|asdf)
82+ # Handled via .tool-versions
83+ ;;
84+ nvm|rvm+nvm)
85+ print_header " Setting Node $version with nvm"
86+ # Source nvm if not already loaded
87+ if [ -z " ${NVM_DIR:- } " ]; then
88+ export NVM_DIR=" $HOME /.nvm"
89+ [ -s " $NVM_DIR /nvm.sh" ] && \. " $NVM_DIR /nvm.sh"
90+ fi
91+ if ! nvm list " $version " & > /dev/null; then
92+ print_warning " Node $version not installed. Installing..."
93+ nvm install " $version "
94+ fi
95+ nvm use " $version "
96+ ;;
97+ esac
98+ }
99+
50100show_status () {
51101 print_header " Current Configuration"
52102 echo " "
@@ -121,12 +171,17 @@ switch_to_minimum() {
121171 fi
122172
123173 # Set Ruby and Node versions
124- print_header " Setting runtime versions in .tool-versions"
125- cat > " $PROJECT_ROOT /.tool-versions" << EOF
174+ if [[ " $VERSION_MANAGER " == " mise" ]] || [[ " $VERSION_MANAGER " == " asdf" ]]; then
175+ print_header " Setting runtime versions in .tool-versions"
176+ cat > " $PROJECT_ROOT /.tool-versions" << EOF
126177ruby 3.2.8
127178nodejs 20.18.1
128179EOF
129- print_success " Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
180+ print_success " Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
181+ fi
182+
183+ set_ruby_version " 3.2.8" " $VERSION_MANAGER "
184+ set_node_version " 20.18.1" " $VERSION_MANAGER "
130185
131186 # Run conversion script
132187 print_header " Running script/convert to downgrade dependencies"
@@ -158,22 +213,44 @@ EOF
158213
159214 # Reload version manager to pick up new versions
160215 print_header " Reloading $VERSION_MANAGER to use new versions"
161- if [[ " $VERSION_MANAGER " == " mise" ]]; then
162- # mise will auto-detect .tool-versions on next cd
163- :
164- elif [ -f " $HOME /.asdf/asdf.sh" ]; then
165- source " $HOME /.asdf/asdf.sh"
166- fi
216+ case " $VERSION_MANAGER " in
217+ mise)
218+ # mise will auto-detect .tool-versions on next cd
219+ ;;
220+ asdf)
221+ if [ -f " $HOME /.asdf/asdf.sh" ]; then
222+ source " $HOME /.asdf/asdf.sh"
223+ fi
224+ ;;
225+ rvm|rvm+nvm)
226+ # Versions already set via rvm use
227+ ;;
228+ nvm)
229+ # Version already set via nvm use
230+ ;;
231+ esac
167232
168233 echo " "
169234 print_success " Switched to MINIMUM configuration"
170235 print_warning " Run these commands to reload your shell and verify:"
171236 echo " cd $PROJECT_ROOT "
172- if [[ " $VERSION_MANAGER " == " mise" ]]; then
173- echo " mise current"
174- else
175- echo " asdf current"
176- fi
237+ case " $VERSION_MANAGER " in
238+ mise)
239+ echo " mise current"
240+ ;;
241+ asdf)
242+ echo " asdf current"
243+ ;;
244+ rvm+nvm)
245+ echo " rvm current && nvm current"
246+ ;;
247+ rvm)
248+ echo " rvm current"
249+ ;;
250+ nvm)
251+ echo " nvm current"
252+ ;;
253+ esac
177254 echo " "
178255 print_warning " Next steps to build and test:"
179256 echo " rake node_package"
@@ -201,12 +278,17 @@ restore_to_latest() {
201278 fi
202279
203280 # Set Ruby and Node versions
204- print_header " Setting runtime versions in .tool-versions"
205- cat > " $PROJECT_ROOT /.tool-versions" << EOF
281+ if [[ " $VERSION_MANAGER " == " mise" ]] || [[ " $VERSION_MANAGER " == " asdf" ]]; then
282+ print_header " Setting runtime versions in .tool-versions"
283+ cat > " $PROJECT_ROOT /.tool-versions" << EOF
206284ruby 3.4.3
207285nodejs 22.12.0
208286EOF
209- print_success " Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
287+ print_success " Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
288+ fi
289+
290+ set_ruby_version " 3.4.3" " $VERSION_MANAGER "
291+ set_node_version " 22.12.0" " $VERSION_MANAGER "
210292
211293 # Restore files from git
212294 print_header " Restoring dependency files from git"
@@ -238,22 +320,44 @@ EOF
238320
239321 # Reload version manager to pick up new versions
240322 print_header " Reloading $VERSION_MANAGER to use new versions"
241- if [[ " $VERSION_MANAGER " == " mise" ]]; then
242- # mise will auto-detect .tool-versions on next cd
243- :
244- elif [ -f " $HOME /.asdf/asdf.sh" ]; then
245- source " $HOME /.asdf/asdf.sh"
246- fi
323+ case " $VERSION_MANAGER " in
324+ mise)
325+ # mise will auto-detect .tool-versions on next cd
326+ ;;
327+ asdf)
328+ if [ -f " $HOME /.asdf/asdf.sh" ]; then
329+ source " $HOME /.asdf/asdf.sh"
330+ fi
331+ ;;
332+ rvm|rvm+nvm)
333+ # Versions already set via rvm use
334+ ;;
335+ nvm)
336+ # Version already set via nvm use
337+ ;;
338+ esac
247339
248340 echo " "
249341 print_success " Restored to LATEST configuration"
250342 print_warning " Run these commands to reload your shell and verify:"
251343 echo " cd $PROJECT_ROOT "
252- if [[ " $VERSION_MANAGER " == " mise" ]]; then
253- echo " mise current"
254- else
255- echo " asdf current"
256- fi
344+ case " $VERSION_MANAGER " in
345+ mise)
346+ echo " mise current"
347+ ;;
348+ asdf)
349+ echo " asdf current"
350+ ;;
351+ rvm+nvm)
352+ echo " rvm current && nvm current"
353+ ;;
354+ rvm)
355+ echo " rvm current"
356+ ;;
357+ nvm)
358+ echo " nvm current"
359+ ;;
360+ esac
257361 echo " "
258362 print_warning " Next steps to build and test:"
259363 echo " rake node_package"
0 commit comments