grache 0.0.2.pre.rc1 → 0.0.2.pre.rc4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54563f6f951fbd5e6a5aa352d4b1e6389febe767
4
- data.tar.gz: e4f7297391a1411d64941725e0438145868eca26
3
+ metadata.gz: 93545ff97508b114b9a09a388fe509f6c751f702
4
+ data.tar.gz: a7593282cb1f819f9597e3c4d3de9009c08cf398
5
5
  SHA512:
6
- metadata.gz: 5ed1038727f9233a8ec986a0f0df5bc0b554f27ce5e629ebccd789a49799b37bfada8f92f869b8ba1840aba03772d917c7f521d90872f7499d0cc74eb9c5f741
7
- data.tar.gz: cbb268c6ce2db9398aba9d8271ced93b00ef9b14aa4f626a94b88616212d6e5184d930c6300553cfc55f310e621c6f63e33b76c72a5676c2c628ef3a240a8292
6
+ metadata.gz: a93d5c72b7851d6c719dd5a5e5b6646713fcfa1de16d8a53d8bffa64605ba2666af12b3d6b319994470ed10e6603fbcb9fa803db6c5810b8fbbeb4162437ef42
7
+ data.tar.gz: 53a806717e38b958124301198b751a18fa4925793ed51a7b6df49e10dfc85baed762d686e96af1f7486249f9c63492f0a769c1ff8904932b23eb7396e7c773c2
data/lib/grache.rb CHANGED
@@ -6,3 +6,4 @@ require_relative 'grache/version'
6
6
  # Modules
7
7
  require_relative 'grache/cli/cli'
8
8
  require_relative 'grache/packer/packer'
9
+ require_relative 'grache/zip/zip'
@@ -23,5 +23,13 @@ Grache::CLI.module_eval do
23
23
  Grache::Packer.new.install
24
24
  end
25
25
  end
26
+
27
+ c.desc 'Zip created pack'
28
+ c.command :zip do |cmd|
29
+ cmd.action do |global_options, options, _args|
30
+ _opts = options.merge(global_options)
31
+ Grache::Packer.new.zip
32
+ end
33
+ end
26
34
  end
27
35
  end
@@ -1,20 +1,32 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'digest'
3
4
  require 'fileutils'
4
5
  require 'json'
6
+ require 'net/http'
5
7
  require 'tmpdir'
8
+ require 'uri'
6
9
 
7
10
  require 'rubygems'
8
11
  require 'bundler/cli'
9
12
 
13
+ require 'zip'
14
+
10
15
  require_relative '../bundler/bundler'
16
+ require_relative '../zip/zip'
11
17
 
12
18
  module Grache
13
19
  class Packer
20
+ DEFAULT_INSTALL_OPTIONS = {
21
+ }
22
+
14
23
  DEFAULT_PACK_OPTIONS = {
15
24
  dir: '.'
16
25
  }
17
26
 
27
+ DEFAULT_ZIP_OPTIONS = {
28
+ }
29
+
18
30
  CMDS = {
19
31
  # gemfile path
20
32
  'bundle-install-no-deployment' => 'bundle install --gemfile=%s --no-deployment',
@@ -57,6 +69,61 @@ module Grache
57
69
  def get_gemfile_meta(path)
58
70
  end
59
71
 
72
+ def install(opts = DEFAULT_INSTALL_OPTIONS)
73
+ opts = DEFAULT_INSTALL_OPTIONS.merge(opts)
74
+
75
+ puts "Installing pack: #{JSON.pretty_generate(opts)}"
76
+
77
+ dir = opts[:dir]
78
+ fail ArgumentError, 'No directory specified' unless dir
79
+
80
+ dir = File.expand_path(dir)
81
+
82
+ gemfile = find_gemfile(dir)
83
+ return unless gemfile
84
+
85
+ gem_dir = File.dirname(gemfile)
86
+ vendor_dir = File.join(gem_dir, 'vendor/')
87
+
88
+ unless File.directory?(vendor_dir)
89
+ puts "Creating #{vendor_dir}"
90
+ FileUtils.mkdir_p vendor_dir
91
+ end
92
+
93
+ FileUtils.rm_rf File.join(vendor_dir, 'cache')
94
+
95
+ gemfile_lock = "#{gemfile}.lock"
96
+ sha = Digest::SHA2.file(gemfile_lock).hexdigest
97
+
98
+ uri = URI.parse("https://gdc-ms-grache.s3.amazonaws.com/grache-#{sha}.zip")
99
+ puts "Looking for #{uri.to_s}"
100
+
101
+ begin
102
+ name = uri.path.split('/').last
103
+ Net::HTTP.start(uri.host) do |http|
104
+ resp = http.get(uri.path)
105
+ open(name, 'wb') do |file|
106
+ file.write(resp.body)
107
+ end
108
+ end
109
+ rescue => e
110
+ puts e.inspect
111
+ end
112
+
113
+ Zip::File.open(name) do |zip_file|
114
+ # Handle entries one by one
115
+ zip_file.each do |entry|
116
+ # Extract to file/directory/symlink
117
+ puts "Extracting #{entry.name}"
118
+ out_path = "vendor/#{entry.name}"
119
+ entry.extract(out_path)
120
+ end
121
+ end
122
+
123
+ puts "Removing old #{zip_file}"
124
+ FileUtils.rm_rf zip_file
125
+ end
126
+
60
127
  def pack(opts = DEFAULT_PACK_OPTIONS)
61
128
  opts = DEFAULT_PACK_OPTIONS.merge(opts)
62
129
 
@@ -100,6 +167,39 @@ module Grache
100
167
  cmd = CMDS['bundle-pack'] % gemfile
101
168
  exec_cmd(cmd)
102
169
  end
170
+
171
+ def zip(opts = DEFAULT_ZIP_OPTIONS)
172
+ opts = DEFAULT_ZIP_OPTIONS.merge(opts)
173
+
174
+ puts "Zipping pack: #{JSON.pretty_generate(opts)}"
175
+
176
+ dir = opts[:dir]
177
+ fail ArgumentError, 'No directory specified' unless dir
178
+
179
+ dir = File.expand_path(dir)
180
+ puts "Zipping #{dir}"
181
+
182
+ gemfile = find_gemfile(dir)
183
+ return unless gemfile
184
+
185
+ gem_dir = File.dirname(gemfile)
186
+ vendor_dir = File.join(gem_dir, 'vendor/')
187
+
188
+ unless File.directory?(vendor_dir)
189
+ puts "Vendor directory does not exists. Run 'grache pack build' first!"
190
+ return
191
+ end
192
+
193
+ gemfile_lock = "#{gemfile}.lock"
194
+ sha = Digest::SHA2.file(gemfile_lock).hexdigest
195
+
196
+ archive = "grache-#{sha}.zip"
197
+ FileUtils.rm archive, :force => true
198
+
199
+ ZipGenerator.new(vendor_dir, archive).write
200
+
201
+ puts "Created #{archive}"
202
+ end
103
203
  end
104
204
 
105
205
 
@@ -111,12 +211,22 @@ module Grache
111
211
  Packer.get_checksum(path)
112
212
  end
113
213
 
114
- def install(opts = {})
115
- puts "Installing pack: #{JSON.pretty_generate(opts)}"
214
+ def install(opts = DEFAULT_INSTALL_OPTIONS)
215
+ opts = DEFAULT_PACK_OPTIONS.merge(opts)
216
+
217
+ Packer.install(opts)
116
218
  end
117
219
 
118
220
  def pack(opts = DEFAULT_PACK_OPTIONS)
221
+ opts = DEFAULT_PACK_OPTIONS.merge(opts)
222
+
119
223
  Packer.pack(opts)
120
224
  end
225
+
226
+ def zip(opts = DEFAULT_ZIP_OPTIONS)
227
+ opts = DEFAULT_PACK_OPTIONS.merge(opts)
228
+
229
+ Packer.zip(opts)
230
+ end
121
231
  end
122
232
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Grache
4
- VERSION = '0.0.2-rc1'
4
+ VERSION = '0.0.2-rc4'
5
5
  end
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'zip_generator'
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'zip'
4
+
5
+ module Grache
6
+ # This is a simple example which uses rubyzip to
7
+ # recursively generate a zip file from the contents of
8
+ # a specified directory. The directory itself is not
9
+ # included in the archive, rather just its contents.
10
+ #
11
+ # Usage:
12
+ # require /path/to/the/ZipFileGenerator/Class
13
+ # directoryToZip = "/tmp/input"
14
+ # outputFile = "/tmp/out.zip"
15
+ # zf = ZipFileGenerator.new(directoryToZip, outputFile)
16
+ # zf.write()
17
+
18
+ class ZipGenerator
19
+ # Initialize with the directory to zip and the location of the output archive.
20
+ def initialize(inputDir, outputFile)
21
+ @inputDir = inputDir
22
+ @outputFile = outputFile
23
+ end
24
+
25
+ # Zip the input directory.
26
+ def write()
27
+ entries = Dir.entries(@inputDir); entries.delete('.'); entries.delete('..')
28
+ io = Zip::File.open(@outputFile, Zip::File::CREATE);
29
+ writeEntries(entries, '', io)
30
+ io.close();
31
+ end
32
+
33
+ # A helper method to make the recursion work.
34
+ private
35
+ def writeEntries(entries, path, io)
36
+ entries.each { |e|
37
+ zipFilePath = path == '' ? e : File.join(path, e)
38
+ diskFilePath = File.join(@inputDir, zipFilePath)
39
+ puts 'Deflating ' + diskFilePath
40
+
41
+ if File.directory?(diskFilePath)
42
+ io.mkdir(zipFilePath)
43
+ subdir =Dir.entries(diskFilePath); subdir.delete('.'); subdir.delete('..')
44
+ writeEntries(subdir, zipFilePath, io)
45
+ else
46
+ io.get_output_stream(zipFilePath) { |f| f.print(File.open(diskFilePath, 'rb').read()) }
47
+ end
48
+ }
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.pre.rc1
4
+ version: 0.0.2.pre.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Korcak
@@ -528,6 +528,8 @@ files:
528
528
  - lib/grache/cli/shared.rb
529
529
  - lib/grache/packer/packer.rb
530
530
  - lib/grache/version.rb
531
+ - lib/grache/zip/zip.rb
532
+ - lib/grache/zip/zip_generator.rb
531
533
  - spec/spec_helper.rb
532
534
  homepage: http://github.com/korczis/grache
533
535
  licenses: