smol-dev-js icon indicating copy to clipboard operation
smol-dev-js copied to clipboard

code fences around generated files

Open christiangenco opened this issue 2 years ago • 1 comments

Any time I ask smol-dev-js to create or modify a file it adds code fences at the top and bottom of the file (```javascript at the beginning and ``` at the end).

I can ask smol-dev-js to remove them but then it adds them back with the next command.

christiangenco avatar Oct 22 '23 02:10 christiangenco

Here's a ruby script I had ChatGPT write to tidy those up:

#!/usr/bin/env ruby
require 'fileutils'

# Glob all JavaScript files in the current directory
Dir.glob('src/**/*.js').each do |filename|
  p filename

  lines = File.readlines(filename)

  # Check if the first line is a starting code fence and the last line is an ending code fence
  if lines.first.chomp.index("```") === 0 && lines.last.chomp == "```"
    # Remove the first and last lines
    lines.shift
    lines.pop

    # Write the modified lines back to the file
    File.open(filename, 'w') do |file|
      file.puts(lines)
    end
  end
end

christiangenco avatar Oct 22 '23 02:10 christiangenco