Sunday, 15 September 2013

ruby - Best way to handle OS differences with rake sh command -



ruby - Best way to handle OS differences with rake sh command -

i'm trying write build script rake run on windows , linux. assume have next rake task:

task:check sh "dir" end

this work on windows not in other operating systems. best way handle operating scheme differences sh command? want create next task work between operating systems on works on windows:

task:check %w(npm bower kpm gulp).each |cmd| begin sh "#{cmd} --version > nul" rescue raise "#{cmd} doesn't exists globally" end end end

check out os gem. wrap task definitions in checks platform, or utilize of helpers write more generic tasks.

something may handy:

>> os.dev_null => "nul" # or "/dev/null" depending on platform

or create them specific os:

if os.windows? task :whatever # ... end elsif os.linux? task :whatever # ... end end

ruby rake

No comments:

Post a Comment