Batch scrambling

Apparently there is a way to scramble a whole subfolder of rb files.
My new extension has 26 rb files. I’m doing them one at a time.
But maybe for future updates it would be handy.
How do you call an external exe and loop through a folder of files?

Just pass in multiple parameters :older_man:

Too bad that it doesn’t handle wildcards (at least in the *#:skull_and_crossbones:↯!* Windows cmd)…
SketchUpRubyScrambler *.rb
…but you could instead drag and drop all files into the command prompt, create your own script, use a better command prompt (maybe PowerShell) or use a loop:

for %i in (dir subfolder/*.rb) do SketchUpRubyScramblerWindows.exe %i
1 Like

Here is an extract of the Ruby script I use to build one of my extension:

  puts "Scrambling RB files..."

  rb_files_pattern = File.join(build_path, extension_name, "**/**/*.rb")
  rb_files = Dir.glob(rb_files_pattern)

  scrambler_exec = File.join(__dir__, "scrambler")
  scambler_command = "#{scrambler_exec} #{rb_files.join(" ")}"
  p system(scambler_command)

  FileUtils.remove(rb_files)

After that it also builds the RBZ package:

### Package ####################################################################

puts "Creating ZIP archive..."
puts "Source: #{build_path}"
puts "Destination: #{archive}"

if File.exist?(archive)
  puts "Archive already exist. Deleting existing archive."
  File.delete(archive)
end

Zip::File.open(archive, Zip::File::CREATE) do |zipfile|
  build_files = Dir.glob(build_files_pattern)
  build_files.each { |file_item|
    next if File.directory?(file_item)
    pathname = Pathname.new(file_item)
    relative_name = pathname.relative_path_from(build_pathname)
    puts "Archiving: #{relative_name}"
    zipfile.add(relative_name, file_item)
  }
end

puts "Packing done!"
puts "#{archive}"

I’ve been meaning to extract the gist of it into an example and put it on GitHub.

Attaching the whole script:
PackageExtension.rb (3.7 KB)

The nice thing about making the build tools in ruby instead of system shell scripts is that you can run them on both platform. On OSX they run out of the box, on Windows you just use the Windows Ruby installer.

Terrific! Thank you.

I just drop a copy the scrambler.exe file into the folder, then grab all the rb files via selection and hold+drag and drop them all onto the executable. The shell does the loop for us.

1 Like

Gosh. I didn’t realize that Bill Gates was so smart!
We have to avoid the old pitfall:
“When you own a hammer (like ruby script) everything looks like a nail.”

1 Like