node-webkit-bootstrap 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,266 @@
1
+ require "curb"
2
+ require "json"
3
+ require "rake"
4
+ require "rbconfig"
5
+ require "rubygems/package"
6
+ require "zlib"
7
+ require "zip/zip"
8
+
9
+ # Entry point for Rakefile
10
+
11
+ DSL = Rake::DSL
12
+
13
+ module NodeWebkitBootstrap
14
+ class Rake
15
+ class << self
16
+ include DSL
17
+
18
+ attr_accessor :app
19
+ attr_accessor :app_path
20
+ attr_accessor :build_deps
21
+ attr_accessor :rake_namespace
22
+ attr_accessor :nw_version
23
+ attr_accessor :run_package
24
+ attr_accessor :build_package
25
+ attr_accessor :test_package
26
+ attr_accessor :test_path
27
+ end
28
+
29
+ @here = File.expand_path "..", __FILE__
30
+
31
+ @app = "node-webkit-bootstrap"
32
+
33
+ @rake_namespace = "node-webkit-bootstrap"
34
+
35
+ @build_deps = []
36
+
37
+ @run_package = {
38
+ name: @app,
39
+ main: "index.html",
40
+ window: {
41
+ toolbar: true,
42
+ width: 660,
43
+ height: 500
44
+ }
45
+ }
46
+
47
+ @build_package = {
48
+ name: @app,
49
+ main: "index.html",
50
+ window: {
51
+ toolbar: false,
52
+ width: 660,
53
+ height: 500
54
+ }
55
+ }
56
+
57
+ @test_package = {
58
+ name: @app,
59
+ main: "index.html",
60
+ window: {
61
+ toolbar: false,
62
+ show: false,
63
+ width: 660,
64
+ height: 500
65
+ }
66
+ }
67
+
68
+ @app_path = "#{@here}/bootstrap"
69
+ @test_path = "#{@here}/test"
70
+ @nw_version = "0.5.1"
71
+
72
+ def self.register tasks = ["*"], &block
73
+ yield self if block_given?
74
+
75
+ tasks.each do |task|
76
+ FileList["#{@here}/tasks/#{task}.rake"].each do |f|
77
+ import f
78
+ end
79
+ end
80
+ end
81
+
82
+ def self.nw_targets
83
+ { linux: [:ia32, :x64],
84
+ osx: [:ia32],
85
+ win: [:ia32] }
86
+ end
87
+
88
+ def self.vendor_dirs platform, arch
89
+ here = File.expand_path "..", __FILE__
90
+
91
+ [ "#{here}/vendor/node-webkit/#{platform}/#{arch}",
92
+ # This one is for the app itself.
93
+ "vendor/node-webkit-bootstrap/node-webkit/#{platform}/#{arch}" ]
94
+ end
95
+
96
+ def self.vendor_deps
97
+ nw_targets.map do |platform, archs|
98
+ archs.map do |arch|
99
+ vendor_dirs(platform,arch).map do |dir|
100
+ Dir["#{dir}/**/*"]
101
+ end.flatten
102
+ end.flatten
103
+ end.flatten
104
+ end
105
+
106
+ def self.download_nw version = nw_version
107
+ nw_targets.each do |platform, archs|
108
+ case platform
109
+ when :linux
110
+ file_extension = "tar.gz"
111
+ executables = ["nw"]
112
+ when :win
113
+ file_extension = "zip"
114
+ executables = ["nw.exe"]
115
+ when :osx
116
+ file_extension = :zip
117
+ executables = [
118
+ "Contents/MacOS/node-webkit",
119
+ "Contents/Frameworks/node-webkit Helper.app/Contents/MacOS/node-webkit Helper"
120
+ ]
121
+ end
122
+
123
+ archs.each do |arch|
124
+ puts "Downloading node-wekbit binary for #{platform} #{arch}"
125
+ directory = "tmp/node-webkit/#{platform}/#{arch}"
126
+ FileUtils.rm_rf directory
127
+ FileUtils.mkdir_p directory
128
+
129
+ archive = "tmp/node-webkit-v#{version}-#{platform}-#{arch}.#{file_extension}"
130
+
131
+ unless File.exists? archive
132
+ failed = false
133
+ url = download_url(version, platform, arch, file_extension)
134
+ puts "Downloading #{url} to #{archive}"
135
+ Curl::Easy.download url, archive do |curl|
136
+ curl.on_failure do
137
+ failed = true
138
+ end
139
+ end
140
+ raise "Download failed for #{platform} #{arch}" if failed
141
+ end
142
+
143
+ puts "Decompressing #{archive}"
144
+ if file_extension == "tar.gz"
145
+ Gem::Package::TarReader.new(Zlib::GzipReader.open archive).each do |entry|
146
+ next unless entry.file?
147
+
148
+ path = entry.full_name.split("/")[1..-1].join "/"
149
+ file = "#{directory}/#{path}"
150
+ FileUtils.mkdir_p File.dirname(file)
151
+
152
+ puts "Extracting #{path}"
153
+ File.open file, "wb" do |fd|
154
+ fd.write entry.read
155
+ end
156
+ end
157
+ else
158
+ Zip::ZipFile.open archive do |zipfile|
159
+ zipfile.each do |file|
160
+ path = file.name.split("/")[1..-1].join "/"
161
+ target = "#{directory}/#{path}"
162
+ FileUtils.mkdir_p File.dirname(target)
163
+
164
+ puts "Extracting #{path}"
165
+ zipfile.extract file, target unless File.exists? target
166
+ end
167
+ end
168
+ end
169
+
170
+ vendor_dirs(platform,arch).each do |vendordir|
171
+ if File.exists? vendordir
172
+ Dir["#{vendordir}/**/*"].each do |file|
173
+ next if File.directory? file
174
+
175
+ path = file.sub "#{vendordir}/",""
176
+ target = "#{directory}/#{path}"
177
+ FileUtils.mkdir_p File.dirname(target)
178
+
179
+ puts "Vendoring #{path}"
180
+ FileUtils.cp file, target
181
+ end
182
+ end
183
+ end
184
+
185
+ executables.each do |executable|
186
+ FileUtils.chmod 0755, "#{directory}/#{executable}"
187
+ end
188
+
189
+ puts "Done!"
190
+ puts ""
191
+ end
192
+ end
193
+ end
194
+
195
+ def self.download_url version, platform, arch, file_extension
196
+ "https://s3.amazonaws.com/node-webkit/v#{version}/node-webkit-v#{version}-#{platform}-#{arch}.#{file_extension}"
197
+ end
198
+
199
+ def self.build_runtime app, path, mode
200
+ basedir = "tmp/node-webkit-bootstrap/#{app}-#{mode}"
201
+
202
+ FileUtils.rm_rf basedir
203
+ FileUtils.mkdir_p File.dirname(basedir)
204
+ FileUtils.cp_r path, basedir
205
+
206
+ case mode
207
+ when :build
208
+ package = NodeWebkitBootstrap::Rake.build_package
209
+ when :run
210
+ package = NodeWebkitBootstrap::Rake.run_package
211
+ when :test
212
+ package = NodeWebkitBootstrap::Rake.test_package
213
+ end
214
+
215
+ # If package[:main] is not a string, treat
216
+ # it as a proc and pass it the application path
217
+ unless package[:main].kind_of? String
218
+ package[:main] = package[:main].call basedir
219
+ end
220
+
221
+ File.open "#{basedir}/package.json", "w" do |file|
222
+ file.write JSON.pretty_generate(package)
223
+ end
224
+ if package[:dependencies]
225
+ sh "which npm && cd 'tmp/node-webkit-bootstrap/#{app}-build' && npm install --production"
226
+ end
227
+
228
+ sh "touch 'tmp/node-webkit-bootstrap/#{app}-#{mode}'"
229
+ end
230
+
231
+ file "tmp/node-webkit" => vendor_deps do
232
+ download_nw
233
+ sh "touch tmp/node-webkit"
234
+ end
235
+
236
+ def self.run_app app, mode
237
+ case RbConfig::CONFIG["target_os"]
238
+ when /darwin/i
239
+ path = "tmp/node-webkit/osx/ia32/Contents/MacOS/node-webkit"
240
+ when /mswin|mingw/i
241
+ path = "tmp/node-webkit/win/ia32/nw.exe"
242
+ when /linux/i
243
+ case RbConfig::CONFIG["target_cpu"]
244
+ when "x86_64"
245
+ path = "tmp/node-webkit/linux/x64/nw"
246
+ when "x86"
247
+ path = "tmp/node-webkit/linux/ia32/nw"
248
+ end
249
+ end
250
+
251
+ raise "Unsupported platform!" unless path
252
+
253
+ sh "#{path} 'tmp/node-webkit-bootstrap/#{app}-#{mode}'"
254
+ end
255
+
256
+ def self.add_tasks &block
257
+ if rake_namespace
258
+ namespace rake_namespace do
259
+ block.call
260
+ end
261
+ else
262
+ block.call
263
+ end
264
+ end
265
+ end
266
+ end
@@ -0,0 +1,120 @@
1
+ require "json"
2
+ require "zip/zip"
3
+
4
+ NodeWebkitBootstrap::Rake.add_tasks do
5
+ app = NodeWebkitBootstrap::Rake.app
6
+ build_deps = NodeWebkitBootstrap::Rake.build_deps
7
+ path = NodeWebkitBootstrap::Rake.app_path
8
+
9
+ desc "Build #{app} (platform is one of: \"win\", \"linux\", \"osx\" or \"all\", default: \"all\")."
10
+ task :build, [:platform] => ["tmp/node-webkit-bootstrap/#{app}-build", "tmp/node-webkit"] do |t, args|
11
+ platform = args[:platform] || "all"
12
+
13
+ if platform == "osx" or platform == "all"
14
+ build_osx app
15
+ end
16
+ if platform == "win" or platform == "all"
17
+ build_win app
18
+ end
19
+ if platform == "linux" or platform == "all"
20
+ build_linux app, :ia32
21
+ build_linux app, :x64
22
+ end
23
+ end
24
+
25
+ file "tmp/node-webkit-bootstrap/#{app}-build" => FileList["Rakefile", "#{path}/**/*"].concat(build_deps) do
26
+ NodeWebkitBootstrap::Rake.build_runtime app, path, :build
27
+ end
28
+
29
+ def build_osx app
30
+ build_nw app, :osx, :ia32
31
+ basedir = "tmp/node-webkit-bootstrap/#{app}-osx-ia32"
32
+
33
+ FileUtils.rm_rf basedir
34
+ FileUtils.cp_r "tmp/node-webkit/osx/ia32", basedir
35
+ FileUtils.cp "build/#{app}-osx-ia32.nw", "#{basedir}/Contents/Resources/app.nw"
36
+
37
+ archive = "build/#{app}-osx-ia32.zip"
38
+ puts "Creating #{archive}"
39
+
40
+ FileUtils.rm_f archive
41
+ Zip::ZipFile.open archive, Zip::ZipFile::CREATE do |zip|
42
+ Dir["#{basedir}/**/*"].each do |file|
43
+ file.gsub! "#{basedir}/", ""
44
+ target = "#{app}.app/#{file}"
45
+
46
+ puts "Adding #{target}"
47
+ zip.add target, "#{basedir}/#{file}"
48
+ end
49
+ end
50
+ end
51
+
52
+ def build_win app
53
+ build_nw app, :win, :ia32
54
+ basedir = "tmp/node-webkit-bootstrap/#{app}-win-ia32"
55
+
56
+ FileUtils.rm_rf basedir
57
+ FileUtils.cp_r "tmp/node-webkit/win/ia32", basedir
58
+ sh "cat '#{basedir}/nw.exe' 'build/#{app}-win-ia32.nw' > '#{basedir}/#{app}.exe'"
59
+ FileUtils.rm "#{basedir}/nw.exe"
60
+
61
+ archive = "build/#{app}-win-ia32.zip"
62
+ puts "Creating #{archive}"
63
+
64
+ FileUtils.rm_f archive
65
+ Zip::ZipFile.open archive, Zip::ZipFile::CREATE do |zip|
66
+ Dir["#{basedir}/**/*"].each do |file|
67
+ file.gsub! "#{basedir}/", ""
68
+ target = "#{app}/#{file}"
69
+
70
+ puts "Adding #{target}"
71
+ zip.add target, "#{basedir}/#{file}"
72
+ end
73
+ end
74
+ end
75
+
76
+ def build_nw app, platform, arch
77
+ archive = "build/#{app}-#{platform}-#{arch}.nw"
78
+
79
+ FileUtils.mkdir_p "build"
80
+ FileUtils.rm_rf archive
81
+
82
+ puts "Creating #{archive}"
83
+ Zip::ZipFile.open archive, Zip::ZipFile::CREATE do |zip|
84
+ FileList["tmp/node-webkit-bootstrap/#{app}-build/**/*"].each do |file|
85
+ target = file.sub("tmp/node-webkit-bootstrap/#{app}-build/","")
86
+
87
+ # Filter app platform-specific vendor stuff.
88
+ next if target.match "vendor/arch" and not target.match "vendor/arch/#{platform}/#{arch}"
89
+
90
+ puts "Adding #{target}"
91
+ zip.add target, file
92
+ end
93
+ end
94
+ end
95
+
96
+ def build_linux app, arch
97
+ build_nw app, :linux, arch
98
+ basedir = "tmp/node-webkit-bootstrap/#{app}-linux-#{arch}"
99
+
100
+ FileUtils.rm_rf basedir
101
+ FileUtils.cp_r "tmp/node-webkit/linux/#{arch}", basedir
102
+ sh "cat '#{basedir}/nw' 'build/#{app}-linux-#{arch}.nw' > '#{basedir}/#{app}'"
103
+ FileUtils.chmod 0755, "#{basedir}/#{app}"
104
+ FileUtils.rm "#{basedir}/nw"
105
+
106
+ archive = "build/#{app}-linux-#{arch}.zip"
107
+ puts "Creating #{archive}"
108
+
109
+ FileUtils.rm_f archive
110
+ Zip::ZipFile.open archive, Zip::ZipFile::CREATE do |zip|
111
+ Dir["#{basedir}/**/*"].each do |file|
112
+ file.gsub! "#{basedir}/", ""
113
+ target = "#{app}/#{file}"
114
+
115
+ puts "Adding #{target}"
116
+ zip.add target, "#{basedir}/#{file}"
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,7 @@
1
+ NodeWebkitBootstrap::Rake.add_tasks do
2
+ desc "Download latest node-webkit code (default version: #{NodeWebkitBootstrap::Rake.nw_version})."
3
+ task :download, [:version] do |t, args|
4
+ version = args[:version] || NodeWebkitBootstrap::Rake.nw_version
5
+ NodeWebkitBootstrap::Rake.download_nw version
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ NodeWebkitBootstrap::Rake.add_tasks do
2
+ app = NodeWebkitBootstrap::Rake.app
3
+ build_deps = NodeWebkitBootstrap::Rake.build_deps
4
+ app_path = NodeWebkitBootstrap::Rake.app_path
5
+
6
+ desc "Run #{app}."
7
+ task :run => [ "tmp/node-webkit",
8
+ "tmp/node-webkit-bootstrap/#{app}-run"] do
9
+ NodeWebkitBootstrap::Rake.run_app app, :run
10
+ end
11
+
12
+ file "tmp/node-webkit-bootstrap/#{app}-run" => FileList["Rakefile", "#{app_path}/**/*"].concat(build_deps) do
13
+ NodeWebkitBootstrap::Rake.build_runtime app, app_path, :run
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ NodeWebkitBootstrap::Rake.add_tasks do
2
+ next if ENV["NODE_WEBKIT_BOOTSTRAP_NO_TESTS"]
3
+
4
+ app = NodeWebkitBootstrap::Rake.app
5
+ build_deps = NodeWebkitBootstrap::Rake.build_deps
6
+ test_path = NodeWebkitBootstrap::Rake.test_path
7
+
8
+ desc "Run #{app} tests."
9
+ task :test => [ "tmp/node-webkit",
10
+ "tmp/node-webkit-bootstrap/#{app}-test"] do
11
+ NodeWebkitBootstrap::Rake.run_app app, :test
12
+ end
13
+
14
+ file "tmp/node-webkit-bootstrap/#{app}-test" => FileList["Rakefile", "#{test_path}/**/*"].concat(build_deps) do
15
+ NodeWebkitBootstrap::Rake.build_runtime app, test_path, :test
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ <html>
2
+ <head>
3
+ <title>node-webkit-bootstrap</title>
4
+
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta charset="utf-8">
7
+
8
+ <script>
9
+ console.log("Level 1 diagnostic of my positronic net all good Captain.");
10
+ console.log("I will now deactivate myself. Good Bye!");
11
+ process.exit(0);
12
+ </script>
13
+ </head>
14
+
15
+ <body></body>
16
+ </html>