furoshiki 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c6df7eae5f4b6178c062b65d94f982f9aa5424741b33199bcd31be3be2e2f77
4
- data.tar.gz: c7f26f4ce029aaf87a3cb43a9477df216bcec4feee432bd4da0362e9ede296e7
3
+ metadata.gz: e63382b21f1841d960724ff462e12b8df250fc7094e47e6603de086999ebe5f9
4
+ data.tar.gz: ab1e14b3e6c931d660754a97010aefb74726e7f6aaf94013b4e5c02ab9c8aa41
5
5
  SHA512:
6
- metadata.gz: a92923698d16efa5299953828bdb93cd8d99e951a677ff21b0a38a93877b1e8c4945a2597d557a7d7fa7cabd30c66a27454159080c6a41c8d40a1a77b128f427
7
- data.tar.gz: 5089838464681db8b4e196da72c730cbea89e76058373369181bca21121b90304765f5f0d4ba859bfb97d6a34b8b6115d6c4421783e21487c288d86e7d85f6b7
6
+ metadata.gz: 27fbff8f947bcfa96a7a58d4b0c646ce08a33d46833ff230af0fecae5eb54b882bb6004b4886db163fb875e174afe96f8db0b2bca257031731d5a3e4f9dcb7fe
7
+ data.tar.gz: 01b6f85ff5e974a2bfd393fa01bc64b86b028f064e7522c1af4323dd3aea667318f4686d52b80676ef214803ace7dc569a8f15d1b2735d25dd555177b0f8c7c7
@@ -1,10 +1,11 @@
1
1
  require 'furoshiki/configuration'
2
2
  require 'furoshiki/exceptions'
3
- require 'furoshiki/zip/directory'
4
3
  require 'furoshiki/jar'
5
4
  require 'fileutils'
6
5
  require 'open-uri'
7
6
  require 'net/http'
7
+ require 'rubygems/package'
8
+ require 'rubygems/package/tar_writer'
8
9
 
9
10
  module Furoshiki
10
11
  class BaseApp
@@ -24,6 +25,7 @@ module Furoshiki
24
25
  @package_dir = default_package_dir
25
26
  @default_template_path = cache_dir.join(template_filename)
26
27
  @template_path = default_template_path
28
+ @archive_path = @package_dir.join(archive_name)
27
29
  @tmp = @package_dir.join('tmp')
28
30
  end
29
31
 
@@ -38,8 +40,7 @@ module Furoshiki
38
40
  inject_jar
39
41
  after_built
40
42
 
41
- move_to_package_dir tmp_app_path
42
- after_moved
43
+ create_archive tmp_app_path
43
44
  ensure
44
45
  remove_tmp
45
46
  end
@@ -53,6 +54,9 @@ module Furoshiki
53
54
  # @return [Pathname] default path to app template
54
55
  attr_reader :default_template_path
55
56
 
57
+ # @return [Pathname] path to resulting archive file
58
+ attr_accessor :archive_path
59
+
56
60
  # @return [Pathname] path to app template
57
61
  attr_accessor :template_path
58
62
 
@@ -72,6 +76,10 @@ module Furoshiki
72
76
  raise NotImplementedError
73
77
  end
74
78
 
79
+ def archive_name
80
+ raise NotImplementedError
81
+ end
82
+
75
83
  def template_basename
76
84
  raise NotImplementedError
77
85
  end
@@ -96,6 +104,10 @@ module Furoshiki
96
104
  tmp.join app_name
97
105
  end
98
106
 
107
+ def tmp_files
108
+ Dir[tmp_app_path.join("**/*")]
109
+ end
110
+
99
111
  def app_path
100
112
  package_dir.join app_name
101
113
  end
@@ -104,6 +116,11 @@ module Furoshiki
104
116
  config.working_dir
105
117
  end
106
118
 
119
+ def executable_path
120
+ # Expected to be overridden on *nix systems
121
+ ""
122
+ end
123
+
107
124
  # Temp helpers
108
125
  def create_tmp
109
126
  tmp.mkpath
@@ -182,13 +199,14 @@ module Furoshiki
182
199
  def after_built
183
200
  end
184
201
 
185
- def after_moved
186
- end
187
-
188
- def move_to_package_dir(path)
189
- dest = package_dir.join(app_name)
190
- dest.rmtree if dest.exist?
191
- mv path.to_s, dest
202
+ def create_archive(source_path)
203
+ destination = package_dir.join(archive_name)
204
+ open_archive(destination) do |tar|
205
+ tmp_files.each do |source_item|
206
+ destination_item = source_item.sub(source_path.to_s, app_name)
207
+ write_item_to_archive(source_item, destination_item, tar)
208
+ end
209
+ end
192
210
  end
193
211
 
194
212
  def ensure_jar_exists
@@ -197,5 +215,35 @@ module Furoshiki
197
215
  jar.package(tmp) unless File.exist?(path)
198
216
  path
199
217
  end
218
+
219
+ def destination_mode(destination)
220
+ if executable_path.to_s.end_with?(destination)
221
+ 0755
222
+ else
223
+ 0644
224
+ end
225
+ end
226
+
227
+ def open_archive(destination)
228
+ File.open(destination, "wb") do |file|
229
+ Zlib::GzipWriter.wrap(file) do |gz|
230
+ Gem::Package::TarWriter.new(gz) do |tar|
231
+ yield tar
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+ def write_item_to_archive(source_item, destination_item, tar)
238
+ if File.directory?(source_item)
239
+ tar.mkdir(destination_item, 0755)
240
+ else
241
+ contents = File.binread(source_item)
242
+ mode = destination_mode(destination_item)
243
+ tar.add_file_simple(destination_item, mode, contents.length) do |destination|
244
+ destination.write(contents)
245
+ end
246
+ end
247
+ end
200
248
  end
201
249
  end
@@ -1,5 +1,4 @@
1
1
  require 'furoshiki/base_app'
2
- require 'plist'
3
2
 
4
3
  module Furoshiki
5
4
  class LinuxApp < BaseApp
@@ -9,6 +8,10 @@ module Furoshiki
9
8
  "#{config.name}-linux"
10
9
  end
11
10
 
11
+ def archive_name
12
+ "#{app_name}.tar.gz"
13
+ end
14
+
12
15
  def template_basename
13
16
  'linux-app-template'
14
17
  end
@@ -30,10 +33,6 @@ module Furoshiki
30
33
  mv File.join(tmp_app_path, "app"), File.join(tmp_app_path, config.name)
31
34
  end
32
35
 
33
- def after_moved
34
- executable_path.chmod 0755
35
- end
36
-
37
36
  def executable_path
38
37
  app_path.join(config.name)
39
38
  end
@@ -9,6 +9,10 @@ module Furoshiki
9
9
  "#{config.name}.app"
10
10
  end
11
11
 
12
+ def archive_name
13
+ "#{config.name}-mac.tar.gz"
14
+ end
15
+
12
16
  def template_basename
13
17
  'mac-app-template'
14
18
  end
@@ -51,10 +55,6 @@ module Furoshiki
51
55
  end
52
56
  end
53
57
 
54
- def after_moved
55
- executable_path.chmod 0755
56
- end
57
-
58
58
  def executable_path
59
59
  app_path.join('Contents/MacOS/app')
60
60
  end
@@ -1,4 +1,4 @@
1
1
  module Furoshiki
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
4
4
 
@@ -1,4 +1,5 @@
1
1
  require 'furoshiki/base_app'
2
+ require 'zip'
2
3
 
3
4
  module Furoshiki
4
5
  class WindowsApp < BaseApp
@@ -8,6 +9,10 @@ module Furoshiki
8
9
  "#{config.name}-windows"
9
10
  end
10
11
 
12
+ def archive_name
13
+ "#{app_name}.zip"
14
+ end
15
+
11
16
  def template_basename
12
17
  'windows-app-template'
13
18
  end
@@ -32,5 +37,16 @@ module Furoshiki
32
37
  def tmp_app_path
33
38
  tmp.join "#{template_basename}"
34
39
  end
40
+
41
+ def create_archive(source_path)
42
+ dest = package_dir.join(archive_name)
43
+ rm_f dest
44
+ ::Zip::File.open(dest, ::Zip::File::CREATE) do |zipfile|
45
+ tmp_files.each do |source_item|
46
+ dest_item = source_item.sub(source_path.to_s, app_name)
47
+ zipfile.add(dest_item, source_item)
48
+ end
49
+ end
50
+ end
35
51
  end
36
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: furoshiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Shoes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-17 00:00:00.000000000 Z
12
+ date: 2017-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -129,10 +129,6 @@ files:
129
129
  - lib/furoshiki/version.rb
130
130
  - lib/furoshiki/warbler_extensions.rb
131
131
  - lib/furoshiki/windows_app.rb
132
- - lib/furoshiki/zip.rb
133
- - lib/furoshiki/zip/directory.rb
134
- - lib/furoshiki/zip/directory_contents.rb
135
- - lib/furoshiki/zip/recursive.rb
136
132
  - lib/warbler/traits/furoshiki.rb
137
133
  - vendor/appbundler-1.0.jar
138
134
  homepage: http://github.com/shoes/furoshiki
@@ -1,2 +0,0 @@
1
- require 'furoshiki/zip/directory'
2
- require 'furoshiki/zip/directory_contents'
@@ -1,19 +0,0 @@
1
- require 'furoshiki/zip/recursive'
2
-
3
- module Furoshiki
4
- module Zip
5
- class Directory
6
- # @param [#to_s] input_dir the directory to zip
7
- # @param [#to_s] output_file the location of the output archive
8
- def initialize(input_dir, output_file)
9
- @input_dir = Pathname.new(input_dir)
10
- @zip = Recursive.new(output_file)
11
- end
12
-
13
- # Zip the whole input directory, including the root
14
- def write
15
- @zip.write [@input_dir.basename], @input_dir.parent, ''
16
- end
17
- end
18
- end
19
- end
@@ -1,20 +0,0 @@
1
- require 'furoshiki/zip/recursive'
2
-
3
- module Furoshiki
4
- module Zip
5
- class DirectoryContents
6
- # @param [#to_s] input_dir the directory to zip
7
- # @param [#to_s] output_file the location of the output archive
8
- def initialize(input_dir, output_file)
9
- @input_dir = Pathname.new(input_dir)
10
- @zip = Recursive.new(output_file)
11
- end
12
-
13
- # Zip the contents of the input directory, without the root.
14
- def write
15
- entries = @input_dir.children(false)
16
- @zip.write entries, @input_dir, ''
17
- end
18
- end
19
- end
20
- end
@@ -1,58 +0,0 @@
1
- require 'pathname'
2
- require 'zip'
3
-
4
- module Furoshiki
5
- module Zip
6
- # Adapted from rubyzip's sample, ZipFileGenerator
7
- #
8
- # This is a utility class that uses rubyzip to recursively
9
- # generate a zip file containing the given entries and all of
10
- # their children.
11
- #
12
- # Best used through frontend classes Furoshiki::Zip::Directory or
13
- # Furoshiki::Zip::DirectoryContents
14
- #
15
- # @example
16
- # To zip the directory "/tmp/input" so that unarchiving
17
- # gives you a single directory "input":
18
- #
19
- # output_file = '/tmp/out.zip'
20
- #
21
- # zip = Furoshiki::Zip::Recursive(output_file)
22
- # entries = Pathname.new("/tmp/input").entries
23
- # zip_prefix = ''
24
- # disk_prefix = '/tmp'
25
- # zf.write(entries, disk_prefix, zip_prefix, output_file)
26
- class Recursive
27
- def initialize(output_file)
28
- @output_file = output_file.to_s
29
- end
30
-
31
- # @param [Array<Pathname>] entries the initial set of files to include
32
- # @param [Pathname] disk_prefix a path prefix for existing entries
33
- # @param [Pathname] zip_prefix a path prefix to add within archive
34
- def write(entries, disk_prefix, zip_prefix)
35
- io = ::Zip::File.open(@output_file, ::Zip::File::CREATE);
36
- write_entries(entries, disk_prefix, zip_prefix, io)
37
- io.close();
38
- end
39
-
40
- # A helper method to make the recursion work.
41
- private
42
- def write_entries(entries, disk_prefix, path, io)
43
- entries.each do |e|
44
- zip_path = path.to_s == "" ? e.basename : path.join(e.basename)
45
- disk_path = disk_prefix.join(zip_path)
46
- puts "Deflating #{disk_path}"
47
- if disk_path.directory?
48
- io.mkdir(zip_path)
49
- subdir = disk_path.children(false)
50
- write_entries(subdir, disk_prefix, zip_path, io)
51
- else
52
- io.get_output_stream(zip_path) { |f| f.puts(File.open(disk_path, "rb").read())}
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end