diff --git a/.gitignore b/.gitignore index 0bbd4a9..4ad01a1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ # Libraries don't need dependency lock # Dependencies will be locked in applications that use them /shard.lock +/examples/build/* diff --git a/scripts/build_examples.rb b/scripts/build_examples.rb new file mode 100755 index 0000000..3e4c357 --- /dev/null +++ b/scripts/build_examples.rb @@ -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