diff --git a/.gitignore b/.gitignore index 2009ee7..3e7b421 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /_yardoc/ /build_test_run/ /coverage/ +/dist/ /doc/ /pkg/ diff --git a/Rakefile.rb b/Rakefile.rb index 9c69011..517313c 100644 --- a/Rakefile.rb +++ b/Rakefile.rb @@ -13,6 +13,10 @@ require "rake/clean" CLEAN.include %w[build_test_run .yardoc doc coverage] CLOBBER.include %w[pkg] +task :build_dist do + sh "ruby build_dist.rb" +end + RSpec::Core::RakeTask.new(:spec, :example_string) do |task, args| if args.example_string ENV["partial_specs"] = "1" diff --git a/build_dist.rb b/build_dist.rb new file mode 100755 index 0000000..cebfeba --- /dev/null +++ b/build_dist.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby + +require "fileutils" + +PROG_NAME = "rscons" +START_FILE = "bin/#{PROG_NAME}" +LIB_DIR = "lib" +DIST = "dist" + +files_processed = {} + +process_file = lambda do |file, fh| + File.read(file, mode: "rb").each_line do |line| + if line =~ /^\s*require(?:_relative)?\s*"(.*)"$/ + require_name = $1 + if require_name =~ %r{^#{PROG_NAME}(?:/.*)?$} + path = "#{LIB_DIR}/#{require_name}.rb" + if File.exists?(path) + unless files_processed[path] + files_processed[path] = true + process_file[path, fh] + end + else + raise "require path #{path.inspect} not found" + end + else + fh.write(line) + end + else + fh.write(line) + end + end +end + +FileUtils.mkdir_p(DIST) + +File.open("#{DIST}/#{PROG_NAME}", "wb", 0755) do |fh| + process_file[START_FILE, fh] +end