Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing 'ForemanPluginTemplate' in rename.rb is not applied #63

Open
gsdcadmin opened this issue Apr 17, 2024 · 3 comments
Open

replacing 'ForemanPluginTemplate' in rename.rb is not applied #63

gsdcadmin opened this issue Apr 17, 2024 · 3 comments

Comments

@gsdcadmin
Copy link

  # Change content on all files
  tmp_file = "#{path}.tmp"
  system(%(sed 's/foreman_plugin_template/#{snake}/g' #{path} > #{tmp_file}))
  system(%(sed 's/ForemanPluginTemplate/#{camel}/g' #{tmp_file} > #{path}))
  system(%(sed 's/foremanPluginTemplate/#{camel_lower}/g' #{tmp_file} > #{path}))
  system(%(rm #{tmp_file}))

third changes replace second changes.

@ekohl
Copy link
Member

ekohl commented Apr 17, 2024

We're talking about these lines:

# Change content on all files
tmp_file = "#{path}.tmp"
system(%(sed 's/foreman_plugin_template/#{snake}/g' #{path} > #{tmp_file}))
system(%(sed 's/ForemanPluginTemplate/#{camel}/g' #{tmp_file} > #{path}))
system(%(sed 's/foremanPluginTemplate/#{camel_lower}/g' #{tmp_file} > #{path}))
system(%(rm #{tmp_file}))

This was added in 65e6437.

I don't really see the problem. Note that it's ForemanPluginTemplate vs foremanPluginTemplate: the first letter is uppercase vs lowercase.

@gsdcadmin
Copy link
Author

gsdcadmin commented Apr 19, 2024

for example:

module ForemanPluginTemplate
class Engine < ::Rails::Engine
isolate_namespace ForemanPluginTemplate
engine_name 'foreman_plugin_template'

foreman_plugin_template is changed.
ForemanPluginTemplate is not changed.

And path rename logic has another problem.
app/views/foreman_plugin_template/layouts/new_layout.html.erb produce duplicated new_layout.html.erb file.

I modified the code as follows for my case:

Find.find('.') do |path|
  next unless File.file?(path)
  next if path =~ /\.git/
  next if path == './rename.rb'

  # Change content on all files
  tmp_file_1 = "#{path}.1.tmp"
  tmp_file_2 = "#{path}.2.tmp"
  system(%(sed 's/foreman_plugin_template/#{snake}/g' #{path} > #{tmp_file_1}))
  system(%(sed 's/ForemanPluginTemplate/#{camel}/g' #{tmp_file_1} > #{tmp_file_2}))
  system(%(sed 's/foremanPluginTemplate/#{camel_lower}/g' #{tmp_file_2} > #{path}))
  system(%(rm #{tmp_file_1}))
  system(%(rm #{tmp_file_2}))
end

old_dirs = []
Find.find('.') do |path|
  next unless File.directory?(path)
  next if path =~ /\.git/

  if path =~ /foreman_plugin_template$/i
    new = path.gsub('foreman_plugin_template', snake)
    FileUtils.cp_r(path, new)
    old_dirs << path
  end
end
FileUtils.rm_rf(old_dirs)

Find.find('.') do |path|
  next unless File.file?(path)
  next if path =~ /\.git/

  if path =~ /foreman_plugin_template/i
    new = path.gsub('foreman_plugin_template', snake)
    FileUtils.mv(path, new)
  end
end

FileUtils.mv('README.plugin.md', 'README.md')

@ekohl
Copy link
Member

ekohl commented Apr 22, 2024

Oh, now I see it! I wonder why it's not using sed -i to avoid temporary files. And a single sed statement could alsobe implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants