dnnbundler 0.1.3 → 0.1.4

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: 3b9f2169cf7b0cf3c9f2998da2fbe237522c4ba0
4
- data.tar.gz: dfaaef66e533b1ad6433e0daa3aabca7d67b53bb
3
+ metadata.gz: 38fb92f25f2f1562aa75bc843eefed30a8da7e67
4
+ data.tar.gz: 75d959d795f88459d38a75d4825cbfed3d235c73
5
5
  SHA512:
6
- metadata.gz: 7a084e3e6a8aefd2796a3a3b43cfe82c95b4ec84540024bbf36b8abafa6fe4eacdd0e8d5b6a3c1142113facc8bac402711bd6e6e5edc7d6b1b55d1955aa36fd4
7
- data.tar.gz: 4900d4dfc6787e31091b0790ce884769f686e180e71876802483c326784f8a0d8a1045a32512c58460a934351a834d9a0679642fd90af9ae788523c82ec60e9f
6
+ metadata.gz: ea1801bd3d89ec4b032576b978fef3db985ed9bc14f46df557cb2606bd7563f198ed29bbaa6f37b1b035590f3ff02f88573bb3b314afb1276df45a36f3f56158
7
+ data.tar.gz: 8a5218f18c49447b8fe28fe487eadd284fd082bdbc249d35b9a05d3654169b85fdcdbc85093a420d2140e71c361e2aa28271223ae6ab953b8d34fa15a629d3c4
data/README.md CHANGED
@@ -25,6 +25,7 @@ Or install it yourself as:
25
25
  To configure packaging create a json config with the following schema:
26
26
 
27
27
  {
28
+ "name": "out.zip",
28
29
  "entries": [
29
30
  "path_to_file",
30
31
  "path_to_directory", // real path in file system to file or directory
@@ -36,6 +37,7 @@ To configure packaging create a json config with the following schema:
36
37
  {
37
38
  "type": "zip", // nested zip archive
38
39
  "name": "test.zip", // name of nested zip archive, can include directories
40
+ "ignoreEntries": [ ... ] // local array of entries to ignore
39
41
  "entries": [ // array of entries for nested zip file, same format as above
40
42
  "file",
41
43
  "dir",
@@ -43,10 +45,9 @@ To configure packaging create a json config with the following schema:
43
45
  ]
44
46
  }
45
47
  ],
46
- "excludeEntries": [
48
+ "ignoreEntries": [
47
49
  ".DS_Store"
48
- ],
49
- "outFileName": "out.zip"
50
+ ]
50
51
  }
51
52
 
52
53
  to create package run:
@@ -14,7 +14,7 @@ module Dnnbundler
14
14
  input_entries = data_hash["entries"]
15
15
  ignore_entries = data_hash["excludeEntries"]
16
16
  zip_file_name = data_hash["outFileName"]
17
- generator = ZipFileGenerator.new(input_entries, ignore_entries, zip_file_name)
17
+ generator = ZipFileGenerator.new(data_hash)
18
18
  generator.write
19
19
  end
20
20
  end
@@ -0,0 +1,10 @@
1
+ module Dnnbundler
2
+ module JsonConfig
3
+ Type = "type"
4
+ Name = "name"
5
+ Path = "path"
6
+ Flatten = "flatten"
7
+ Entries = "entries"
8
+ IgnoreEntries = "ignoreEntries"
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Dnnbundler
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -1,28 +1,30 @@
1
1
  require "dnnbundler/fileEntryType"
2
2
  require "dnnbundler/fileEntry"
3
+ require "dnnbundler/jsonConfig"
3
4
  require "zip"
4
5
 
5
6
  module Dnnbundler
6
7
  class ZipFileGenerator
7
8
  # 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
9
+ def initialize(data)
10
+ @entries = data[JsonConfig::Entries]
11
+ @ignore_entries = data[JsonConfig::IgnoreEntries]
12
+ @output_file = data[JsonConfig::Name]
12
13
  end
13
14
 
14
15
  # Zip the input directory.
15
16
  def write
16
- buffer = create_zip @entries
17
+ buffer = create_zip @entries, @ignore_entries
17
18
  File.open(@output_file, "wb") {|f| f.write buffer.string }
18
19
  end
19
20
 
20
21
  private
21
22
 
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
23
+ # True if +fileEntry+ isn't included into +ignore_entries+ array'
24
+ def filter_entries(fileEntry, ignore_entries)
25
+ return true if ignore_entries == nil
26
+ ignore_entries.each do |entry|
27
+ return false if (fileEntry.type.casecmp(FileEntryType::FILE) != 0) && (fileEntry.name.include? entry)
26
28
  end
27
29
  end
28
30
 
@@ -64,7 +66,7 @@ module Dnnbundler
64
66
  puts "#{ entries.map{ |x| x.name + ", " + x.path.to_s }.join("\n")}"
65
67
  buffer = Zip::File.add_buffer do |zio|
66
68
  entries.each do |file|
67
- if file.type == FileEntryType::FILE
69
+ if file.type.casecmp(FileEntryType::FILE) == 0
68
70
  zio.add(file.path == nil ? file.name : file.path, file.name)
69
71
  else
70
72
  zio.get_output_stream(file.path == nil ? file.name : file.path) { |os| os.write file.buffer.string }
@@ -74,18 +76,18 @@ module Dnnbundler
74
76
  end
75
77
 
76
78
  # Creates from json array of entries
77
- def create_zip(entries)
79
+ def create_zip(entries, ignore_entries)
78
80
  compress entries.map { |x|
79
81
  if x.is_a? String
80
82
  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"]
83
+ elsif x[JsonConfig::Type].casecmp(FileEntryType::FILE) == 0
84
+ get_entries x[JsonConfig::Name], x[JsonConfig::Path]
85
+ elsif x[JsonConfig::Type].casecmp(FileEntryType::ZIP) == 0
86
+ zip_file_entry = FileEntry.new x[JsonConfig::Name], FileEntryType::ZIP, false, x[JsonConfig::Path]
87
+ zip_file_entry.add_buffer create_zip x[JsonConfig::Entries], x[JsonConfig::IgnoreEntries]
86
88
  result = zip_file_entry
87
89
  end
88
- }.flatten.select{ |f| filter_entries f }.uniq{ |f| f.name }
90
+ }.flatten.select{ |f| filter_entries f, ignore_entries }.uniq{ |f| f.name }
89
91
  end
90
92
  end
91
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnnbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Le0Michine
@@ -102,6 +102,7 @@ files:
102
102
  - lib/dnnbundler/cli.rb
103
103
  - lib/dnnbundler/fileEntry.rb
104
104
  - lib/dnnbundler/fileEntryType.rb
105
+ - lib/dnnbundler/jsonConfig.rb
105
106
  - lib/dnnbundler/version.rb
106
107
  - lib/dnnbundler/zipFileGenerator.rb
107
108
  homepage: https://github.com/Le0Michine/dnnbundler