compressor 0.0.2 → 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/compressor.rb +33 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56886396eac0a46fc4a7548f55fdc76800308b33
4
- data.tar.gz: bddd23186feed0228e3c334e0c210de10e0c1b26
3
+ metadata.gz: 3b9e88b6987f1b08a32f163c2d5b434e7049b07a
4
+ data.tar.gz: 249211f3d66c4196f2a2f391f35bcb03b2a5d51a
5
5
  SHA512:
6
- metadata.gz: 4c3a278dc176b6ae6aa3442ae2ddd1db2ae15ee8c9fceaa8109f60b89672103c12b74b7973c85a31f4531d336c30852044ce487707c678209895da7780a37a73
7
- data.tar.gz: 22ec027621afe42c3e3b5da334d092cacb50b37b8f62eeceafeb9c444b27b9968ceecbcefa62d722789c58f9679699af0bc5ec8157889803df6bab2a37de6224
6
+ metadata.gz: d61305bad63b1aad29a7548fce3791aac215042efa39df8d830da3b1fe6fdc0dbf081d92f3e6239d35c2d4346a52beb8f692597d48251b8e4965e9774c6010f9
7
+ data.tar.gz: a05c68c1efc3e2a66689b6fbed37d549015dcbf7adfaea264d1066a74ae28e153690add25921b2e823d135f6bb63e9fa894547aac9ad43bf6df013f3bcfc570a
data/lib/compressor.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
+ require 'fileutils'
2
3
 
3
4
  unless defined?(Motion::Project::Config)
4
5
  raise "This file must be required within a RubyMotion project Rakefile."
@@ -7,19 +8,18 @@ end
7
8
  module Motion::Project
8
9
  class Config
9
10
  def concat_files(opts={})
10
- files_to_concatenate = extract_concatenated_files(Array(opts[:exclude]))
11
- concatenate_files!(files_to_concatenate, opts[:parallel] || 4)
11
+ concatenate_files!(extract_concatenated_files(Array(opts[:exclude])), opts[:parallel] || 4)
12
12
  end
13
13
 
14
14
  private
15
15
 
16
16
  def extract_concatenated_files(excluded=[])
17
17
  @files.flatten!
18
- @concatenated_files = @files.select { |f| excluded.none? { |excluded_match| !!f.match(excluded_match) } }
18
+ concatenated_files = @files.select { |f| excluded.none? { |excluded_match| !!f.match(excluded_match) } }
19
19
  old_dependencies = @dependencies
20
+ @files = @files - concatenated_files
20
21
  @dependencies = Dependency.new(@files - @exclude_from_detect_dependencies, @dependencies).run
21
- @files = @files - @concatenated_files
22
- @concatenated_files = order_concatenated_files(@concatenated_files)
22
+ order_concatenated_files(concatenated_files)
23
23
  end
24
24
 
25
25
  def order_concatenated_files(concatenated_files)
@@ -28,14 +28,18 @@ module Motion::Project
28
28
 
29
29
  def concatenate_files!(concat_files, parallel=4)
30
30
  group_number = 1
31
- concatenated = []
31
+ previous_concat_path = nil
32
+
32
33
  concat_files.in_groups(parallel, false) do |group|
33
34
  concat_path = File.join(File.expand_path(@project_dir), "build", "app-concatenated-#{group_number}.rb")
34
- File.delete(concat_path) if File.exist?(concat_path)
35
- Dir.mkdir(File.dirname(concat_path)) unless File.exist?(File.dirname(concat_path))
35
+ temp_concat_path = File.join(File.expand_path(@project_dir), "build", "app-concatenated-#{group_number}-temp.rb")
36
36
  Motion::Project::App.info "Concat", concat_path
37
37
 
38
- File.open(concat_path, 'a') do |concat|
38
+ # Prep the concat path for writing
39
+ Dir.mkdir(File.dirname(concat_path)) unless File.exist?(File.dirname(concat_path))
40
+
41
+ # Concatenate this group of files
42
+ File.open(temp_concat_path, 'a') do |concat|
39
43
  concat << "# File generated by 'Compressor' by Jamon Holmgren\n\n"
40
44
  concat << "# "
41
45
  group.each do |filename|
@@ -46,11 +50,28 @@ module Motion::Project
46
50
  concat << "\n"
47
51
  end
48
52
  end
49
- concatenated << concat_path
53
+
54
+ if File.exist?(concat_path) && !FileUtils.cmp(temp_concat_path, concat_path)
55
+ # Changed file, replace the original
56
+ File.delete(concat_path)
57
+ FileUtils.mv(temp_concat_path, concat_path)
58
+ else
59
+ # No change, throw it away
60
+ File.delete(temp_concat_path)
61
+ end
62
+
63
+ # Add this concatenated file to the build files
64
+ @files.unshift concat_path
65
+
66
+ # Ensure that each file gets loaded in the right order
67
+ if previous_concat_path
68
+ files_dependencies concat_path => previous_concat_path
69
+ end
70
+ previous_concat_path = concat_path
71
+
72
+ # Next group
50
73
  group_number += 1
51
74
  end
52
- @files.unshift(concatenated)
53
- @files.flatten!
54
75
  end
55
76
  end
56
77
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compressor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jamon Holmgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-18 00:00:00.000000000 Z
11
+ date: 2015-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake