From d0d45a18e3cbb40b7c36dc26ae4be0cb7178f894 Mon Sep 17 00:00:00 2001 From: Mostafa Ahangarha Date: Wed, 15 Feb 2023 08:48:56 +0330 Subject: [PATCH] Fix bin dev scripts (#1519) * Fix scripts * Ensure the scripts are executable * Update tests --- lib/generators/react_on_rails/bin/dev | 5 +---- lib/generators/react_on_rails/bin/dev-static | 5 +---- lib/generators/react_on_rails/install_generator.rb | 9 +++++++++ spec/react_on_rails/binstubs/dev_spec.rb | 8 ++++---- spec/react_on_rails/binstubs/dev_static_spec.rb | 8 ++++---- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/generators/react_on_rails/bin/dev b/lib/generators/react_on_rails/bin/dev index 25e09e1a8..afb5de213 100755 --- a/lib/generators/react_on_rails/bin/dev +++ b/lib/generators/react_on_rails/bin/dev @@ -8,10 +8,7 @@ rescue Errno::ENOENT end def run(process) - args = [*ARGV] - args.shift - puts "Using #{process}" - exec "#{process} start -f Procfile.dev", args.join(" ") + system "#{process} start -f Procfile.dev" rescue Errno::ENOENT warn <<~MSG ERROR: diff --git a/lib/generators/react_on_rails/bin/dev-static b/lib/generators/react_on_rails/bin/dev-static index d54eba724..58dc10b59 100755 --- a/lib/generators/react_on_rails/bin/dev-static +++ b/lib/generators/react_on_rails/bin/dev-static @@ -8,10 +8,7 @@ rescue Errno::ENOENT end def run(process) - args = [*ARGV] - args.shift - puts "Using #{process}" - exec "#{process} start -f Procfile.dev-static", args.join(" ") + system "#{process} start -f Procfile.dev-static" rescue Errno::ENOENT warn <<~MSG ERROR: diff --git a/lib/generators/react_on_rails/install_generator.rb b/lib/generators/react_on_rails/install_generator.rb index ad19413b7..a2c21a10e 100644 --- a/lib/generators/react_on_rails/install_generator.rb +++ b/lib/generators/react_on_rails/install_generator.rb @@ -79,6 +79,15 @@ def missing_node? def add_bin_scripts directory "#{__dir__}/bin", "bin" + + # Make these and only these files executable + files_to_copy = [] + Dir.chdir("#{__dir__}/bin") do + files_to_copy.concat(Dir.glob("*")) + end + files_to_become_excutable = files_to_copy.map { |filename| "bin/#{filename}" } + + File.chmod(0o755, *files_to_become_excutable) end end end diff --git a/spec/react_on_rails/binstubs/dev_spec.rb b/spec/react_on_rails/binstubs/dev_spec.rb index 49618f05d..89d46272c 100644 --- a/spec/react_on_rails/binstubs/dev_spec.rb +++ b/spec/react_on_rails/binstubs/dev_spec.rb @@ -19,7 +19,7 @@ it "with Overmind installed, uses Overmind" do allow(IO).to receive(:popen).with("overmind -v").and_return("Some truthy result") - expect_any_instance_of(Kernel).to receive(:exec).with("overmind start -f Procfile.dev", "") + expect_any_instance_of(Kernel).to receive(:system).with("overmind start -f Procfile.dev") load script_path end @@ -28,7 +28,7 @@ allow(IO).to receive(:popen).with("overmind -v").and_raise(Errno::ENOENT) allow(IO).to receive(:popen).with("foreman -v").and_return("Some truthy result") - expect_any_instance_of(Kernel).to receive(:exec).with("foreman start -f Procfile.dev", "") + expect_any_instance_of(Kernel).to receive(:system).with("foreman start -f Procfile.dev") load script_path end @@ -50,8 +50,8 @@ allow(IO).to receive(:popen).with("overmind -v").and_return("Some truthy result") allow_any_instance_of(Kernel) - .to receive(:exec) - .with("overmind start -f Procfile.dev", "") + .to receive(:system) + .with("overmind start -f Procfile.dev") .and_raise(Errno::ENOENT) allow_any_instance_of(Kernel).to receive(:exit!) diff --git a/spec/react_on_rails/binstubs/dev_static_spec.rb b/spec/react_on_rails/binstubs/dev_static_spec.rb index cc217347a..891dcc09d 100644 --- a/spec/react_on_rails/binstubs/dev_static_spec.rb +++ b/spec/react_on_rails/binstubs/dev_static_spec.rb @@ -19,7 +19,7 @@ it "with Overmind installed, uses Overmind" do allow(IO).to receive(:popen).with("overmind -v").and_return("Some truthy result") - expect_any_instance_of(Kernel).to receive(:exec).with("overmind start -f Procfile.dev-static", "") + expect_any_instance_of(Kernel).to receive(:system).with("overmind start -f Procfile.dev-static") load script_path end @@ -28,7 +28,7 @@ allow(IO).to receive(:popen).with("overmind -v").and_raise(Errno::ENOENT) allow(IO).to receive(:popen).with("foreman -v").and_return("Some truthy result") - expect_any_instance_of(Kernel).to receive(:exec).with("foreman start -f Procfile.dev-static", "") + expect_any_instance_of(Kernel).to receive(:system).with("foreman start -f Procfile.dev-static") load script_path end @@ -50,8 +50,8 @@ allow(IO).to receive(:popen).with("overmind -v").and_return("Some truthy result") allow_any_instance_of(Kernel) - .to receive(:exec) - .with("overmind start -f Procfile.dev-static", "") + .to receive(:system) + .with("overmind start -f Procfile.dev-static") .and_raise(Errno::ENOENT) allow_any_instance_of(Kernel).to receive(:exit!)