zipbundler 0.2.0 → 0.2.1

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: '0368dd29edd6b16d0591927891ba34bc871cf884'
4
- data.tar.gz: 6983437e6e3cc87fd1a713fb7460835d5d39365c
3
+ metadata.gz: 07ff986041a1dc0f5fed2f0c59858004d6db4d8b
4
+ data.tar.gz: fe5ad44cf0310e7ae46556b9e8dc14af4775f6c2
5
5
  SHA512:
6
- metadata.gz: d8fec8fafec3cb56c2757257a2e6c3733f590b102260707bb37ca6ebf108d91d4fc4ff8cfd929d8fa2fe95846b6fa7f2499aa44e6f5f6804cd3fef4f2bb62684
7
- data.tar.gz: 62dba7fbb13fc87dd1c7118714025f126fac9dfc436b946949898f412e02f4c7cb2c6857812e626dcbf4a0420171a96630d3d856de5f68aefdb195b312ed301b
6
+ metadata.gz: 75619a877e38642bfa40f17b01d93a1220e164e56bd76316548c052602fceb154d4ee2923d03606ffaa39574ecd87e0f75c69b32798b92e1e72093d5b27af40c
7
+ data.tar.gz: a2c261fd7d7813446598853ac83fe9ee1b9c958f1284aa445026fd2ab096ffb30f718390135000ff27cb411e5366979f6e1754feef41f285b56803d72a275544
@@ -0,0 +1,11 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "name": "Debug Local",
6
+ "type": "Ruby",
7
+ "request": "launch",
8
+ "program": "${workspaceRoot}/bin/console"
9
+ }
10
+ ]
11
+ }
data/README.md CHANGED
@@ -20,11 +20,11 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- First you need to create an instance of `ZipFileGenerator`:
23
+ It is possible to run utility form console:
24
24
 
25
- ZipFileGenerator.new(json_config)
25
+ zipbundler zip config.json
26
26
 
27
- `json_config` is a hash variable which can be simply created from a json file. It should has the following structure:
27
+ Configuration file `config.json` should has the following structure:
28
28
 
29
29
  {
30
30
  "name": "out.zip",
@@ -51,6 +51,14 @@ First you need to create an instance of `ZipFileGenerator`:
51
51
  ]
52
52
  }
53
53
 
54
+ Please refer [this link](https://github.com/Le0Michine/zipper/config_schema.json) to find full json schema of the configuration.
55
+
56
+ Or you can do it from code `ZipFileGenerator`:
57
+
58
+ ZipFileGenerator.new(json_config).write
59
+
60
+ `json_config` is a hash variable which should have the same structure as json config file above.
61
+
54
62
  ## Development
55
63
 
56
64
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -59,7 +67,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
59
67
 
60
68
  ## Contributing
61
69
 
62
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zipper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Le0Michine/zipper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
63
71
 
64
72
 
65
73
  ## License
data/exe/zipbundler ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "zipper"
4
+
5
+ Zipper::CLI.start( ARGV )
data/lib/zipper/cli.rb ADDED
@@ -0,0 +1,18 @@
1
+ require "zipper"
2
+ require "thor"
3
+ require "json"
4
+ require "zipper"
5
+
6
+ module Zipper
7
+ class CLI < Thor
8
+ desc "zip CONFIG [options]", "creates a zip package according to given configuration file"
9
+ def zip( config )
10
+ puts "Build with config #{config}"
11
+ file = File.read(config)
12
+ json_config = JSON.parse(file)
13
+
14
+ generator = Zipper::ZipFileGenerator.new(json_config)
15
+ generator.write
16
+ end
17
+ end
18
+ end
@@ -1,29 +1,24 @@
1
1
  module Zipper
2
2
  class FileEntry
3
- def initialize(file_name, entry_type = FileEntryType::FILE, flatten_structure = false)
4
- @type = entry_type
3
+ def initialize(file_name, flatten_structure = false, file_path = nil)
5
4
  @name = file_name
5
+ @path = file_path
6
6
  @flatten = flatten_structure
7
7
  end
8
8
 
9
- def add_buffer(buffer)
10
- @buffer = buffer
11
- end
12
-
13
- def type
14
- @type
15
- end
16
-
9
+ # Entry name, used as a real path in file system
17
10
  def name
18
11
  @name
19
12
  end
20
13
 
14
+ # True if existing directory structure shouldn't be preserved'
21
15
  def flatten
22
16
  @flatten
23
17
  end
24
18
 
25
- def buffer
26
- @buffer
19
+ # Path of entry in a zip archive
20
+ def path
21
+ @path
27
22
  end
28
23
  end
29
24
  end
@@ -1,3 +1,3 @@
1
1
  module Zipper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/zipper.rb CHANGED
@@ -3,6 +3,7 @@ require "zipper/fileEntryType"
3
3
  require "zipper/fileEntry"
4
4
  require "zipper/zipEntry"
5
5
  require "zipper/JsonConfigKey"
6
+ require "zipper/cli"
6
7
  require "zip"
7
8
 
8
9
  module Zipper
@@ -45,7 +46,7 @@ module Zipper
45
46
  if File.directory? directory_or_file
46
47
  get_dir_entries_recursively(directory_or_file, entry_path, ignore_entries)
47
48
  else
48
- FileEntry.new(directory_or_file, FileEntryType::FILE, false, entry_path)
49
+ FileEntry.new(directory_or_file, false, entry_path)
49
50
  end
50
51
  end
51
52
 
@@ -61,7 +62,7 @@ module Zipper
61
62
  get_dir_entries_recursively(path, entry_path, ignore_entries, replace_path)
62
63
  else
63
64
  entry_path_in_zip = (entry_path.nil? ? path : path.sub(replace_path, entry_path)).gsub(/^[\/\\]+/, "")
64
- FileEntry.new(path, FileEntryType::FILE, false, entry_path_in_zip)
65
+ FileEntry.new(path, false, entry_path_in_zip)
65
66
  end
66
67
  }
67
68
  end
@@ -71,10 +72,10 @@ module Zipper
71
72
  # +entries+:: array of +FileEntry+ and +ZipEntry+ objects
72
73
  def compress(entries)
73
74
  puts "\nadding the following entries into zip package"
74
- puts "#{ entries.map{ |x| x.name + ", " + x.path.to_s + ", " + x.type.to_s }.join("\n")}"
75
+ puts "#{ entries.map{ |x| x.name }.join("\n")}"
75
76
  buffer = Zip::File.add_buffer do |zio|
76
77
  entries.each do |file|
77
- if file.is_a FileEntry
78
+ if file.is_a? FileEntry
78
79
  zio.add(file.path == nil ? file.name : file.path, file.name)
79
80
  else
80
81
  zio.get_output_stream(file.name) { |os| os.write file.buffer.string }
@@ -96,7 +97,7 @@ module Zipper
96
97
  elsif x[JsonConfigKey::Type].casecmp(FileEntryType::ZIP) == 0
97
98
  ZipEntry.new(x[JsonConfigKey::Name], create_zip(x[JsonConfigKey::Entries], x[JsonConfigKey::IgnoreEntries]))
98
99
  end
99
- }.flatten.select{ |f| filter_entries(f.name, f.type, ignore_entries) }.uniq{ |f| f.name })
100
+ }.flatten.select{ |f| f.is_a?(ZipEntry) || filter_entries(f.name, FileEntryType::FILE, ignore_entries) }.uniq{ |f| f.name })
100
101
  end
101
102
  end
102
103
  end
data/zipper.gemspec CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ["lib"]
23
23
 
24
24
  spec.add_dependency "rubyzip"
25
+ spec.add_dependency "thor"
26
+ spec.add_dependency "json"
25
27
 
26
28
  spec.add_development_dependency "bundler", "~> 1.14"
27
29
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Le0Michine
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -55,11 +83,13 @@ dependencies:
55
83
  description: Creates zip packages with complex structure.
56
84
  email:
57
85
  - leomichine@gmail.com
58
- executables: []
86
+ executables:
87
+ - zipbundler
59
88
  extensions: []
60
89
  extra_rdoc_files: []
61
90
  files:
62
91
  - ".gitignore"
92
+ - ".vscode/launch.json"
63
93
  - CODE_OF_CONDUCT.md
64
94
  - Gemfile
65
95
  - LICENSE.txt
@@ -68,7 +98,9 @@ files:
68
98
  - bin/console
69
99
  - bin/setup
70
100
  - config_schema.json
101
+ - exe/zipbundler
71
102
  - lib/zipper.rb
103
+ - lib/zipper/cli.rb
72
104
  - lib/zipper/fileEntry.rb
73
105
  - lib/zipper/fileEntryType.rb
74
106
  - lib/zipper/jsonConfigKey.rb