Add script to build all examples

This commit is contained in:
Alex Clink 2022-02-02 00:31:38 -05:00
parent cef302ec1b
commit 3db76bcd44
2 changed files with 48 additions and 0 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@
# Libraries don't need dependency lock
# Dependencies will be locked in applications that use them
/shard.lock
/examples/build/*

47
scripts/build_examples.rb Executable file
View file

@ -0,0 +1,47 @@
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'
options = {
release: true,
debug: false,
clean: false,
}
OptionParser.new do |opts|
opts.banner = "Usage: build_examples.rb [options]"
opts.on("--release", "Build in release mode") do
options[:release] = true
end
opts.on("--no-release", "Build faster") do
options[:release] = false
end
opts.on("--clean", "Remove built examples") do
options[:clean] = true
end
end.parse!
unless options[:clean]
cmd = "crystal build"
flags = []
flags << "--release" if options[:release]
flags << "--no-debug" unless options[:debug]
Dir.chdir File.join(__dir__, '..')
FileUtils.mkdir_p("examples/build")
FileUtils.rm("examples/build/assets")
FileUtils.ln_s("../../assets", "examples/build/assets")
Dir.glob("examples/*.cr").each do |path|
full_cmd = %'#{cmd} #{flags.join(" ")} "#{path}"'
puts full_cmd
system full_cmd
bin_name = File.basename(path, ".cr")
FileUtils.mv(bin_name, "examples/build/#{bin_name}")
end
else
# TODO
end