Class: NodeWebkitBootstrap::Rake
- Inherits:
-
Object
- Object
- NodeWebkitBootstrap::Rake
- Extended by:
- Rake::DSL
- Defined in:
- lib/node-webkit-bootstrap/rake.rb
Class Attribute Summary collapse
-
.app ⇒ Object
Returns the value of attribute app.
-
.app_path ⇒ Object
Returns the value of attribute app_path.
-
.build_deps ⇒ Object
Returns the value of attribute build_deps.
-
.build_package ⇒ Object
Returns the value of attribute build_package.
-
.nw_version ⇒ Object
Returns the value of attribute nw_version.
-
.rake_namespace ⇒ Object
Returns the value of attribute rake_namespace.
-
.run_package ⇒ Object
Returns the value of attribute run_package.
-
.test_package ⇒ Object
Returns the value of attribute test_package.
-
.test_path ⇒ Object
Returns the value of attribute test_path.
Class Method Summary collapse
- .add_tasks(&block) ⇒ Object
- .build_runtime(app, path, mode) ⇒ Object
- .download_nw(version = nw_version) ⇒ Object
- .download_url(version, platform, arch, file_extension) ⇒ Object
- .nw_targets ⇒ Object
- .register(tasks = ["*"]) {|_self| ... } ⇒ Object
- .run_app(app, mode) ⇒ Object
- .vendor_deps ⇒ Object
- .vendor_dirs(platform, arch) ⇒ Object
Class Attribute Details
.app ⇒ Object
Returns the value of attribute app.
18 19 20 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 18 def app @app end |
.app_path ⇒ Object
Returns the value of attribute app_path.
19 20 21 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 19 def app_path @app_path end |
.build_deps ⇒ Object
Returns the value of attribute build_deps.
20 21 22 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 20 def build_deps @build_deps end |
.build_package ⇒ Object
Returns the value of attribute build_package.
24 25 26 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 24 def build_package @build_package end |
.nw_version ⇒ Object
Returns the value of attribute nw_version.
22 23 24 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 22 def nw_version @nw_version end |
.rake_namespace ⇒ Object
Returns the value of attribute rake_namespace.
21 22 23 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 21 def rake_namespace @rake_namespace end |
.run_package ⇒ Object
Returns the value of attribute run_package.
23 24 25 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 23 def run_package @run_package end |
.test_package ⇒ Object
Returns the value of attribute test_package.
25 26 27 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 25 def test_package @test_package end |
.test_path ⇒ Object
Returns the value of attribute test_path.
26 27 28 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 26 def test_path @test_path end |
Class Method Details
.add_tasks(&block) ⇒ Object
256 257 258 259 260 261 262 263 264 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 256 def self.add_tasks &block if rake_namespace namespace rake_namespace do block.call end else block.call end end |
.build_runtime(app, path, mode) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 199 def self.build_runtime app, path, mode basedir = "tmp/node-webkit-bootstrap/#{app}-#{mode}" FileUtils.rm_rf basedir FileUtils.mkdir_p File.dirname(basedir) FileUtils.cp_r path, basedir case mode when :build package = NodeWebkitBootstrap::Rake.build_package when :run package = NodeWebkitBootstrap::Rake.run_package when :test package = NodeWebkitBootstrap::Rake.test_package end # If package[:main] is not a string, treat # it as a proc and pass it the application path unless package[:main].kind_of? String package[:main] = package[:main].call basedir end File.open "#{basedir}/package.json", "w" do |file| file.write JSON.pretty_generate(package) end if package[:dependencies] sh "which npm && cd 'tmp/node-webkit-bootstrap/#{app}-build' && npm install --production" end sh "touch 'tmp/node-webkit-bootstrap/#{app}-#{mode}'" end |
.download_nw(version = nw_version) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 106 def self.download_nw version = nw_version nw_targets.each do |platform, archs| case platform when :linux file_extension = "tar.gz" executables = ["nw"] when :win file_extension = "zip" executables = ["nw.exe"] when :osx file_extension = :zip executables = [ "Contents/MacOS/node-webkit", "Contents/Frameworks/node-webkit Helper.app/Contents/MacOS/node-webkit Helper" ] end archs.each do |arch| puts "Downloading node-wekbit binary for #{platform} #{arch}" directory = "tmp/node-webkit/#{platform}/#{arch}" FileUtils.rm_rf directory FileUtils.mkdir_p directory archive = "tmp/node-webkit-v#{version}-#{platform}-#{arch}.#{file_extension}" unless File.exists? archive failed = false url = download_url(version, platform, arch, file_extension) puts "Downloading #{url} to #{archive}" Curl::Easy.download url, archive do |curl| curl.on_failure do failed = true end end raise "Download failed for #{platform} #{arch}" if failed end puts "Decompressing #{archive}" if file_extension == "tar.gz" Gem::Package::TarReader.new(Zlib::GzipReader.open archive).each do |entry| next unless entry.file? path = entry.full_name.split("/")[1..-1].join "/" file = "#{directory}/#{path}" FileUtils.mkdir_p File.dirname(file) puts "Extracting #{path}" File.open file, "wb" do |fd| fd.write entry.read end end else Zip::ZipFile.open archive do |zipfile| zipfile.each do |file| path = file.name.split("/")[1..-1].join "/" target = "#{directory}/#{path}" FileUtils.mkdir_p File.dirname(target) puts "Extracting #{path}" zipfile.extract file, target unless File.exists? target end end end vendor_dirs(platform,arch).each do |vendordir| if File.exists? vendordir Dir["#{vendordir}/**/*"].each do |file| next if File.directory? file path = file.sub "#{vendordir}/","" target = "#{directory}/#{path}" FileUtils.mkdir_p File.dirname(target) puts "Vendoring #{path}" FileUtils.cp file, target end end end executables.each do |executable| FileUtils.chmod 0755, "#{directory}/#{executable}" end puts "Done!" puts "" end end end |
.download_url(version, platform, arch, file_extension) ⇒ Object
195 196 197 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 195 def self.download_url version, platform, arch, file_extension "https://s3.amazonaws.com/node-webkit/v#{version}/node-webkit-v#{version}-#{platform}-#{arch}.#{file_extension}" end |
.nw_targets ⇒ Object
82 83 84 85 86 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 82 def self.nw_targets { linux: [:ia32, :x64], osx: [:ia32], win: [:ia32] } end |
.register(tasks = ["*"]) {|_self| ... } ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 72 def self.register tasks = ["*"], &block yield self if block_given? tasks.each do |task| FileList["#{@here}/tasks/#{task}.rake"].each do |f| import f end end end |
.run_app(app, mode) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 236 def self.run_app app, mode case RbConfig::CONFIG["target_os"] when /darwin/i path = "tmp/node-webkit/osx/ia32/Contents/MacOS/node-webkit" when /mswin|mingw/i path = "tmp/node-webkit/win/ia32/nw.exe" when /linux/i case RbConfig::CONFIG["target_cpu"] when "x86_64" path = "tmp/node-webkit/linux/x64/nw" when "x86" path = "tmp/node-webkit/linux/ia32/nw" end end raise "Unsupported platform!" unless path sh "#{path} 'tmp/node-webkit-bootstrap/#{app}-#{mode}'" end |
.vendor_deps ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 96 def self.vendor_deps nw_targets.map do |platform, archs| archs.map do |arch| vendor_dirs(platform,arch).map do |dir| Dir["#{dir}/**/*"] end.flatten end.flatten end.flatten end |
.vendor_dirs(platform, arch) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/node-webkit-bootstrap/rake.rb', line 88 def self.vendor_dirs platform, arch here = File. "..", __FILE__ [ "#{here}/vendor/node-webkit/#{platform}/#{arch}", # This one is for the app itself. "vendor/node-webkit-bootstrap/node-webkit/#{platform}/#{arch}" ] end |