PicoCreator / smol-dev-js

Smol personal AI, for smol incremental tasks in a JS project
MIT License
322 stars 52 forks source link

code fences around generated files #20

Open christiangenco opened 10 months ago

christiangenco commented 10 months ago

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 commented 10 months ago

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