dnnbundler 0.1.2 → 0.1.3

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: be1ded2536ad48400fd2401ca807e19951ba755d
4
- data.tar.gz: ee84075cd70088d65c6e687f7937a7a4e11db7bb
3
+ metadata.gz: 3b9f2169cf7b0cf3c9f2998da2fbe237522c4ba0
4
+ data.tar.gz: dfaaef66e533b1ad6433e0daa3aabca7d67b53bb
5
5
  SHA512:
6
- metadata.gz: b0f5e29a8205259daa1cf6fd3726ed50105ce50b77851f78e5eaa02bb631845634c0d2418afa5d7b897a69c8f651fe0370ee2f6044dd7240bfb5bab54a011f26
7
- data.tar.gz: '08ad0537cc6972e9ae44531eb0952be26005e83d2f97e9ea270b31ad15c6ba9a2b8f4cb3da34ab78ada2e03b41253c19b956880e0440851a3edf091d2f898c8d'
6
+ metadata.gz: 7a084e3e6a8aefd2796a3a3b43cfe82c95b4ec84540024bbf36b8abafa6fe4eacdd0e8d5b6a3c1142113facc8bac402711bd6e6e5edc7d6b1b55d1955aa36fd4
7
+ data.tar.gz: 4900d4dfc6787e31091b0790ce884769f686e180e71876802483c326784f8a0d8a1045a32512c58460a934351a834d9a0679642fd90af9ae788523c82ec60e9f
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at leomichine@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at leomichine@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in dnnbundler.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dnnbundler.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Le0Michine
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Le0Michine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,65 +1,70 @@
1
- # Dnnbundler
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dnnbundler`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'dnnbundler'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install dnnbundler
22
-
23
- ## Usage
24
-
25
- To configure packaging create a json config with the following schema:
26
-
27
- {
28
- "entries": [
29
- "path_to_file"
30
- "path_to_directory",
31
- {
32
- "type": "file",
33
- "name": "test.json"
34
- },
35
- {
36
- "type": "zip",
37
- "name": "test.zip",
38
- "entries": [
39
- "file",
40
- "dir",
41
- ...
42
- ]
43
- }
44
- ],
45
- "excludeEntries": [
46
- ".DS_Store"
47
- ],
48
- "outFileName": "out.zip"
49
- }
50
-
51
- ## Development
52
-
53
- 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.
54
-
55
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
-
57
- ## Contributing
58
-
59
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dnnbundler. 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.
60
-
61
-
62
- ## License
63
-
64
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
65
-
1
+ # Dnnbundler
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dnnbundler`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dnnbundler'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dnnbundler
22
+
23
+ ## Usage
24
+
25
+ To configure packaging create a json config with the following schema:
26
+
27
+ {
28
+ "entries": [
29
+ "path_to_file",
30
+ "path_to_directory", // real path in file system to file or directory
31
+ {
32
+ "type": "file", // type of entry
33
+ "name": "test.json", // real path in file system to file or directory
34
+ "path": "new_path_in_zip" // optional
35
+ },
36
+ {
37
+ "type": "zip", // nested zip archive
38
+ "name": "test.zip", // name of nested zip archive, can include directories
39
+ "entries": [ // array of entries for nested zip file, same format as above
40
+ "file",
41
+ "dir",
42
+ ...
43
+ ]
44
+ }
45
+ ],
46
+ "excludeEntries": [
47
+ ".DS_Store"
48
+ ],
49
+ "outFileName": "out.zip"
50
+ }
51
+
52
+ to create package run:
53
+
54
+ dnnbundler path_to_config.json
55
+
56
+ ## Development
57
+
58
+ 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
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Le0Michine/dnnbundler. 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.
65
+
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
70
+
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "dnnbundler"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dnnbundler"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dnnbundler.gemspec CHANGED
@@ -1,30 +1,30 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'dnnbundler/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "dnnbundler"
8
- spec.version = Dnnbundler::VERSION
9
- spec.authors = ["Le0Michine"]
10
- spec.email = ["leomichine@gmail.com"]
11
-
12
- spec.summary = %q{Creates zip packages for DNN.}
13
- spec.description = %q{Creates zip packages with complex structure.}
14
- spec.homepage = "https://github.com/Le0Michine/dnnbundler"
15
- spec.license = "MIT"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
- f.match(%r{^(test|spec|features)/})
19
- end
20
- spec.bindir = "exe"
21
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
- spec.require_paths = ["lib"]
23
-
24
- spec.add_dependency "thor"
25
- spec.add_dependency "rubyzip"
26
- spec.add_dependency "json"
27
-
28
- spec.add_development_dependency "bundler", "~> 1.14"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dnnbundler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dnnbundler"
8
+ spec.version = Dnnbundler::VERSION
9
+ spec.authors = ["Le0Michine"]
10
+ spec.email = ["leomichine@gmail.com"]
11
+
12
+ spec.summary = %q{Creates zip packages for DNN.}
13
+ spec.description = %q{Creates zip packages with complex structure.}
14
+ spec.homepage = "https://github.com/Le0Michine/dnnbundler"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "thor"
25
+ spec.add_dependency "rubyzip"
26
+ spec.add_dependency "json"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.14"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ end
data/exe/dnnbundler CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "dnnbundler"
4
-
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dnnbundler"
4
+
5
5
  Dnnbundler::CLI.start( ARGV )
@@ -1,21 +1,21 @@
1
- require "dnnbundler/zipFileGenerator"
2
- require "thor"
3
- require "json"
4
-
5
- module Dnnbundler
6
- class CLI < Thor
7
- desc "build CONFIG", ""
8
- option :bumpBuild
9
- def build( config )
10
- puts "Build with config #{config}"
11
- file = File.read(config)
12
- data_hash = JSON.parse(file)
13
-
14
- input_entries = data_hash["entries"]
15
- ignore_entries = data_hash["excludeEntries"]
16
- zip_file_name = data_hash["outFileName"]
17
- generator = ZipFileGenerator.new(input_entries, ignore_entries, zip_file_name)
18
- generator.write
19
- end
20
- end
21
- end
1
+ require "dnnbundler/zipFileGenerator"
2
+ require "thor"
3
+ require "json"
4
+
5
+ module Dnnbundler
6
+ class CLI < Thor
7
+ desc "build CONFIG", ""
8
+ option :bumpBuild
9
+ def build( config )
10
+ puts "Build with config #{config}"
11
+ file = File.read(config)
12
+ data_hash = JSON.parse(file)
13
+
14
+ input_entries = data_hash["entries"]
15
+ ignore_entries = data_hash["excludeEntries"]
16
+ zip_file_name = data_hash["outFileName"]
17
+ generator = ZipFileGenerator.new(input_entries, ignore_entries, zip_file_name)
18
+ generator.write
19
+ end
20
+ end
21
+ end
@@ -1,29 +1,40 @@
1
- module Dnnbundler
2
- class FileEntry
3
- def initialize(file_name, entry_type = FileEntryType::FILE, flatten_structure = false)
4
- @type = entry_type
5
- @name = file_name
6
- @flatten = flatten_structure
7
- end
8
-
9
- def add_buffer(buffer)
10
- @buffer = buffer
11
- end
12
-
13
- def type
14
- @type
15
- end
16
-
17
- def name
18
- @name
19
- end
20
-
21
- def flatten
22
- @flatten
23
- end
24
-
25
- def buffer
26
- @buffer
27
- end
28
- end
29
- end
1
+ module Dnnbundler
2
+ class FileEntry
3
+ def initialize(file_name, entry_type = FileEntryType::FILE, flatten_structure = false, file_path = nil)
4
+ @type = entry_type
5
+ @name = file_name
6
+ @path = file_path
7
+ @flatten = flatten_structure
8
+ end
9
+
10
+ # Saves +StringIO+ buffer into object, intended to store nested zip files in memory
11
+ def add_buffer(buffer)
12
+ @buffer = buffer
13
+ end
14
+
15
+ # Entry type: ZIP or FILE
16
+ def type
17
+ @type
18
+ end
19
+
20
+ # Entry name, used as a real path in file system
21
+ def name
22
+ @name
23
+ end
24
+
25
+ # True if existing directory structure shouldn't be preserved'
26
+ def flatten
27
+ @flatten
28
+ end
29
+
30
+ # +StringIO+ buffer with nested zip file
31
+ def buffer
32
+ @buffer
33
+ end
34
+
35
+ # Path of entry in a zip archive
36
+ def path
37
+ @path
38
+ end
39
+ end
40
+ end
@@ -1,6 +1,6 @@
1
- module Dnnbundler
2
- module FileEntryType
3
- ZIP = "ZIP"
4
- FILE = "FILE"
5
- end
6
- end
1
+ module Dnnbundler
2
+ module FileEntryType
3
+ ZIP = "ZIP"
4
+ FILE = "FILE"
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
- module Dnnbundler
2
- VERSION = "0.1.2"
3
- end
1
+ module Dnnbundler
2
+ VERSION = "0.1.3"
3
+ end
@@ -1,73 +1,91 @@
1
- require "dnnbundler/fileEntryType"
2
- require "dnnbundler/fileEntry"
3
- require "zip"
4
-
5
- module Dnnbundler
6
- class ZipFileGenerator
7
- # Initialize with the directory to zip and the location of the output archive.
8
- def initialize(entries, ignore_entries, output_file)
9
- @entries = entries
10
- @ignore_entries = ignore_entries
11
- @output_file = output_file
12
- end
13
-
14
- # Zip the input directory.
15
- def write
16
- buffer = create_zip @entries
17
- File.open(@output_file, "wb") {|f| f.write buffer.string }
18
- end
19
-
20
- private
21
-
22
- def filter_entries(fileEntry)
23
- @ignore_entries.each do |entry|
24
- return false if fileEntry.name.include? entry
25
- end
26
- end
27
-
28
- def get_entries(directory_or_file)
29
- if File.directory? directory_or_file
30
- get_dir_entries_recursively directory_or_file
31
- else
32
- FileEntry.new directory_or_file
33
- end
34
- end
35
-
36
- def get_dir_entries_recursively(dir)
37
- (Dir.entries(dir) - %w(. ..)).map { |v|
38
- path = File.join(dir, v)
39
- if File.directory? path
40
- get_dir_entries_recursively(path)
41
- else
42
- FileEntry.new path
43
- end
44
- }
45
- end
46
-
47
- def compress(entries)
48
- buffer = Zip::File.add_buffer do |zio|
49
- entries.each do |file|
50
- if file.type == FileEntryType::FILE
51
- zio.add(file.name, file.name)
52
- else
53
- zio.get_output_stream(file.name) { |os| os.write file.buffer.string }
54
- end
55
- end
56
- end
57
- end
58
-
59
- def create_zip(entries)
60
- compress entries.map { |x|
61
- if x.is_a? String
62
- get_entries x
63
- elsif x["type"].casecmp(FileEntryType::FILE) == 0
64
- get_entries x["name"]
65
- elsif x["type"].casecmp(FileEntryType::ZIP) == 0
66
- zip_file_entry = FileEntry.new x["name"], FileEntryType::ZIP
67
- zip_file_entry.add_buffer create_zip x["entries"]
68
- result = zip_file_entry
69
- end
70
- }.flatten.select{ |f| filter_entries f }.uniq{ |f| f.name }
71
- end
72
- end
1
+ require "dnnbundler/fileEntryType"
2
+ require "dnnbundler/fileEntry"
3
+ require "zip"
4
+
5
+ module Dnnbundler
6
+ class ZipFileGenerator
7
+ # Initialize with the directory to zip and the location of the output archive.
8
+ def initialize(entries, ignore_entries, output_file)
9
+ @entries = entries
10
+ @ignore_entries = ignore_entries
11
+ @output_file = output_file
12
+ end
13
+
14
+ # Zip the input directory.
15
+ def write
16
+ buffer = create_zip @entries
17
+ File.open(@output_file, "wb") {|f| f.write buffer.string }
18
+ end
19
+
20
+ private
21
+
22
+ # True if +fileEntry+ isn't included into +@ignore_entries+ array'
23
+ def filter_entries(fileEntry)
24
+ @ignore_entries.each do |entry|
25
+ return false if fileEntry.name.include? entry
26
+ end
27
+ end
28
+
29
+ # Creates +FileEntry+ for file or array of entries for directory and subdirectories
30
+ # Params:
31
+ # +directory_or_file+:: path to directory or file
32
+ # +entry_path+:: path with which the entry should be put into zip
33
+ def get_entries(directory_or_file, entry_path)
34
+ if File.directory? directory_or_file
35
+ get_dir_entries_recursively directory_or_file, entry_path
36
+ else
37
+ FileEntry.new directory_or_file, entry_path
38
+ end
39
+ end
40
+
41
+ # Collects all files from directory recursively
42
+ # Params:
43
+ # +dir+:: start directory
44
+ # +entry_path+:: path with which file should be placed into zip
45
+ # +replace_path+:: part of path which is being replaced by +entry_path+
46
+ def get_dir_entries_recursively(dir, entry_path, replace_path = nil)
47
+ replace_path = dir if replace_path == nil
48
+ (Dir.entries(dir) - %w(. ..)).map { |v|
49
+ path = File.join(dir, v)
50
+ if File.directory? path
51
+ get_dir_entries_recursively(path, entry_path, replace_path)
52
+ else
53
+ entry_path_in_zip = path.sub(replace_path, entry_path).gsub(/^[\/\\]+/, "")
54
+ FileEntry.new path, FileEntryType::FILE, false, entry_path_in_zip
55
+ end
56
+ }
57
+ end
58
+
59
+ # Creates zip file in memory from passed +FileEntry+ array, returns StringIO as result
60
+ # Params:
61
+ # +entries+:: array of +FileEntry+ objects
62
+ def compress(entries)
63
+ puts "adding the following entries into zip package"
64
+ puts "#{ entries.map{ |x| x.name + ", " + x.path.to_s }.join("\n")}"
65
+ buffer = Zip::File.add_buffer do |zio|
66
+ entries.each do |file|
67
+ if file.type == FileEntryType::FILE
68
+ zio.add(file.path == nil ? file.name : file.path, file.name)
69
+ else
70
+ zio.get_output_stream(file.path == nil ? file.name : file.path) { |os| os.write file.buffer.string }
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ # Creates from json array of entries
77
+ def create_zip(entries)
78
+ compress entries.map { |x|
79
+ if x.is_a? String
80
+ get_entries x, nil
81
+ elsif x["type"].casecmp(FileEntryType::FILE) == 0
82
+ get_entries x["name"], x["path"]
83
+ elsif x["type"].casecmp(FileEntryType::ZIP) == 0
84
+ zip_file_entry = FileEntry.new x["name"], FileEntryType::ZIP, false, x["path"]
85
+ zip_file_entry.add_buffer create_zip x["entries"]
86
+ result = zip_file_entry
87
+ end
88
+ }.flatten.select{ |f| filter_entries f }.uniq{ |f| f.name }
89
+ end
90
+ end
73
91
  end
data/lib/dnnbundler.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "dnnbundler/version"
2
- require "dnnbundler/zipFileGenerator"
3
- require "dnnbundler/cli"
4
-
5
- module Dnnbundler
6
-
7
- end
1
+ require "dnnbundler/version"
2
+ require "dnnbundler/zipFileGenerator"
3
+ require "dnnbundler/cli"
4
+
5
+ module Dnnbundler
6
+
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnnbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Le0Michine
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-17 00:00:00.000000000 Z
11
+ date: 2017-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  version: '0'
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 2.6.11
127
+ rubygems_version: 2.5.2
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: Creates zip packages for DNN.