Class: Gaudi::Gem
- Inherits:
-
Object
- Object
- Gaudi::Gem
- Defined in:
- lib/gaudi/version.rb,
lib/gaudi/scaffolding.rb
Overview
Gaudi follows SemVer and so does it’s gem, but they’re two separate things
Defined Under Namespace
Modules: Version
Constant Summary collapse
- MAIN_CONFIG =
"system.cfg".freeze
- REPO =
"https://github.com/damphyr/gaudi".freeze
Instance Attribute Summary collapse
-
#gaudi_home ⇒ Object
readonly
Returns the value of attribute gaudi_home.
-
#project_root ⇒ Object
readonly
Returns the value of attribute project_root.
Class Method Summary collapse
-
.options(arguments) ⇒ Object
:nodoc:.
-
.run(args) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #api_doc ⇒ Object
- #archive(version, clone_path, prj_root, lib_items) ⇒ Object
-
#check_for_git ⇒ Object
:stopdoc:.
- #core(url, version, lib_items) ⇒ Object
- #directory_structure ⇒ Object
-
#initialize(project_root) ⇒ Gem
constructor
A new instance of Gem.
- #library(lib, source_url, version) ⇒ Object
- #main_config ⇒ Object
- #project(version) ⇒ Object
- #pull_from_repo(repository, tmp) ⇒ Object
- #rakefile ⇒ Object
- #unpack(pkg, home) ⇒ Object
- #update(version) ⇒ Object
Constructor Details
#initialize(project_root) ⇒ Gem
Returns a new instance of Gem.
99 100 101 102 |
# File 'lib/gaudi/scaffolding.rb', line 99 def initialize(project_root) @project_root = project_root @gaudi_home = File.join(project_root, "tools", "build") end |
Instance Attribute Details
#gaudi_home ⇒ Object (readonly)
Returns the value of attribute gaudi_home.
15 16 17 |
# File 'lib/gaudi/scaffolding.rb', line 15 def gaudi_home @gaudi_home end |
#project_root ⇒ Object (readonly)
Returns the value of attribute project_root.
15 16 17 |
# File 'lib/gaudi/scaffolding.rb', line 15 def project_root @project_root end |
Class Method Details
.options(arguments) ⇒ Object
:nodoc:
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/gaudi/scaffolding.rb', line 18 def self.(arguments) = OpenStruct.new .project_root = Dir.pwd .verbose = false .scaffold = false .update = false .library = false .revision = "HEAD" opt_parser = OptionParser.new do |opts| opts. = "Usage: gaudi [options]" opts.separator "Make sure GitHub is accessible via https and git is on the PATH environment" opts.separator "" opts.separator "Commands:" opts.on("-s", "--scaffold PROJECT_PATH", "Create a Gaudi scaffold in PROJECT_PATH") do |proot| .project_root = File.(proot) .scaffold = true .update = false end opts.on("-u", "--update PROJECT_PATH", "Update Gaudi core from GitHub on project at PROJECT_PATH") do |proot| .project_root = File.(proot) .update = true .scaffold = false end opts.on("-l", "--lib NAME URL PROJECT_PATH", "Pull/Update Gaudi library from URL on project at PROJECT_PATH") do |name| .library = true .update = false .scaffold = false .lib = name raise GemError, "Missing parameters!" if ARGV.size < 2 url = ARGV.shift proot = ARGV.shift .url = url .project_root = File.(proot) end opts.separator "" opts.separator "Common options:" # Boolean switch. opts.on("-v", "--[no-]verbose", "Run verbosely") do |v| .verbose = v end opts.on("-r", "--revision REVISION", "Revision of source repository to use") do |rev| .revision = rev end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end opts.on_tail("--version", "Show version") do puts "Gaudi Gem v#{Gaudi::Gem::Version::STRING}" exit end end begin opt_parser.parse!(arguments) rescue GemError puts $!. exit 1 end return end |
.run(args) ⇒ Object
:nodoc:
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gaudi/scaffolding.rb', line 83 def self.run(args) opts = (args) begin if opts.scaffold Gaudi::Gem.new(opts.project_root).project(opts.revision) elsif opts.update Gaudi::Gem.new(opts.project_root).update(opts.revision) elsif opts.library Gaudi::Gem.new(opts.project_root).library(opts.lib, opts.url, opts.revision) end rescue Gaudi::GemError puts $!. exit 1 end end |
Instance Method Details
#api_doc ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/gaudi/scaffolding.rb', line 168 def api_doc puts "Generating build system API doc" config_file = File.join(project_root, "doc/BUILDSYSTEM.md") if File.exist?(config_file) puts "BUILDSYSTEM.md exists, skipping generation" else configuration_content = File.read(File.join(File.dirname(__FILE__), "templates/doc.md.template")) File.open(config_file, "wb") { |f| f.write(configuration_content) } end end |
#archive(version, clone_path, prj_root, lib_items) ⇒ Object
200 201 202 203 204 205 206 207 208 |
# File 'lib/gaudi/scaffolding.rb', line 200 def archive(version, clone_path, prj_root, lib_items) pkg = File.(File.join(prj_root, "gaudipkg.tar")) Dir.chdir(clone_path) do |d| puts "Packing #{version} gaudi version in #{pkg}" cmdline = "git archive --format=tar -o \"#{pkg}\" #{version} #{lib_items}" raise GemError, "Failed to extract library from git" unless system(cmdline) end return pkg end |
#check_for_git ⇒ Object
:stopdoc:
134 135 136 |
# File 'lib/gaudi/scaffolding.rb', line 134 def check_for_git raise GemError, "Could not find git. Make sure it is in the PATH" unless system("git --version") end |
#core(url, version, lib_items) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/gaudi/scaffolding.rb', line 179 def core(url, version, lib_items) Dir.mktmpdir do |tmp| raise GemError, "Cloning the Gaudi repo failed. Check that git is on the PATH and that #{REPO} is accessible" unless pull_from_repo(url, tmp) lib_items.each do |items| unpack_target = gaudi_home unpack_target = File.(File.join(gaudi_home, "../..")) if /tools\/build/ =~ items pkg = archive(version, File.join(tmp, "gaudi"), project_root, items) unpack(pkg, unpack_target) rescue GemError next end end end |
#directory_structure ⇒ Object
138 139 140 141 142 143 144 |
# File 'lib/gaudi/scaffolding.rb', line 138 def directory_structure puts "Creating Gaudi filesystem structure at #{project_root}" structure = ["doc", "tools/build/config", "tools/templates"] structure.each do |dir| FileUtils.mkdir_p File.join(project_root, dir), :verbose => false end end |
#library(lib, source_url, version) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/gaudi/scaffolding.rb', line 124 def library(lib, source_url, version) raise GemError, "#{gaudi_home} is missing! Try creating a new Gaudi project first." unless File.exist?(gaudi_home) puts "Removing old #{lib} installation" FileUtils.rm_rf(File.join(gaudi_home, "lib/#{lib}")) puts "Pulling #{version} from #{source_url}" core(source_url, version, ["lib/#{lib}", "tools/build/lib/#{lib}"]) end |
#main_config ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/gaudi/scaffolding.rb', line 157 def main_config puts "Generating initial configuration file" config_file = File.join(project_root, "tools/build/#{MAIN_CONFIG}") if File.exist?(config_file) puts "#{MAIN_CONFIG} exists, skipping generation" else configuration_content = File.read(File.join(File.dirname(__FILE__), "templates/main.cfg.template")) File.open(config_file, "wb") { |f| f.write(configuration_content) } end end |
#project(version) ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gaudi/scaffolding.rb', line 104 def project(version) raise GemError, "#{project_root} already exists!" if File.exist?(project_root) && project_root != Dir.pwd check_for_git directory_structure rakefile main_config api_doc core(REPO, version, ["lib/gaudi.rb lib/gaudi"]) end |
#pull_from_repo(repository, tmp) ⇒ Object
194 195 196 197 198 |
# File 'lib/gaudi/scaffolding.rb', line 194 def pull_from_repo(repository, tmp) tmp_dir = File.join(tmp, "gaudi") FileUtils.rm_rf(tmp_dir) if File.exist?(tmp_dir) system "git clone #{repository} \"#{tmp_dir}\"" end |
#rakefile ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gaudi/scaffolding.rb', line 146 def rakefile puts "Generating main Rakefile" rakefile = File.join(project_root, "Rakefile") if File.exist?(rakefile) puts "Rakefile exists, skipping generation" else rakefile_content = File.read(File.join(File.dirname(__FILE__), "templates/rakefile.rb.template")) File.open(rakefile, "wb") { |f| f.write(rakefile_content) } end end |
#unpack(pkg, home) ⇒ Object
210 211 212 213 214 215 216 217 |
# File 'lib/gaudi/scaffolding.rb', line 210 def unpack(pkg, home) puts "Unpacking in #{home}" Dir.chdir(home) do |d| Minitar.unpack(pkg, home) end FileUtils.rm_rf(pkg) FileUtils.rm_rf(File.join(home, "pax_global_header")) end |
#update(version) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/gaudi/scaffolding.rb', line 115 def update(version) raise GemError, "#{gaudi_home} is missing! Try creating a new Gaudi project first." unless File.exist?(gaudi_home) check_for_git puts "Removing old gaudi installation" FileUtils.rm_rf(File.join(gaudi_home, "lib/gaudi")) core(REPO, version, ["lib/gaudi lib/gaudi.rb"]) end |