Skip to content

Commit

Permalink
Fix newline scrambling of single file libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kfischer-okarin committed Oct 6, 2023
1 parent 43fe897 commit 29fbc3b
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions scripts/build-single-file-libs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ LIBS = {
]
}.freeze

NEWLINE = "\n"
EMPTY_LINE = "\n"

def main
prepare_output_directory
license_header_lines = comment_lines File.readlines('LICENSE')
license_header_lines << NEWLINE
license_header_lines << EMPTY_LINE

LIBS.each do |lib_name, lib_files|
result_lines = license_header_lines.dup
lib_files.each do |lib_file|
file_lines = File.readlines(LIB_DIR / lib_file)
result_lines.concat strip_dragon_skeleton_module(file_lines)
result_lines << NEWLINE
result_lines << EMPTY_LINE
end

File.write OUTPUT_DIR / "#{lib_name}.rb", result_lines.join.chomp
File.write OUTPUT_DIR / "#{lib_name}.rb", result_lines.join
end
end

Expand All @@ -61,7 +61,13 @@ def prepare_output_directory
end

def comment_lines(lines)
lines.map { |line| "# #{line}" }
lines.map { |line|
if line.strip.empty?
"#\n"
else
"# #{line}"
end
}
end

def strip_dragon_skeleton_module(file_lines)
Expand All @@ -70,7 +76,13 @@ def strip_dragon_skeleton_module(file_lines)
end

def unindent(lines)
lines.map { |line| line[2..] }
lines.map { |line|
if line.strip.empty?
EMPTY_LINE
else
line[2..]
end
}
end

main if $PROGRAM_NAME == __FILE__

0 comments on commit 29fbc3b

Please sign in to comment.