jbundle 0.0.5 → 0.0.6

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jbundle (0.0.4)
4
+ jbundle (0.0.5)
5
5
  closure-compiler
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -91,7 +91,7 @@ You can add configuration in a Jfile in the root of your project.
91
91
  file 'page.html'
92
92
 
93
93
  filter do |src, config|
94
- src.gsub! /<VERSION>/, config.version
94
+ src.gsub! /<VERSION>/, config.version.to_s
95
95
  end
96
96
 
97
97
  target_dir 'dist'
@@ -100,6 +100,21 @@ Then you can bundle everything up with the command line tool
100
100
 
101
101
  $ jbundle
102
102
 
103
+ You can run arbitrary code after writing all versioned files by registering an after_write block in your JFile. The following example copies a .swf file from the src dir to all versioned directories
104
+
105
+ after_write do |config|
106
+
107
+ config.version.releaseable.each do |version|
108
+ from = "#{config.src_dir}/foo.swf"
109
+ to = "#{config.target_dir}/#{version}/foo.swf"
110
+ puts "copying #{to}"
111
+ FileUtils.cp(from, to)
112
+ end
113
+
114
+ end
115
+
116
+ config.version.releaseble returns an array with with all created versions (ie. ['1.6.1', '1.6'] or just ['1.6.1-pre'] for prereleases).
117
+
103
118
  ## Pre-releases
104
119
 
105
120
  If you want a prerelease not to overwrite the previous point release, suffix it with "-pre", as in:
@@ -2,16 +2,17 @@ module JBundle
2
2
 
3
3
  class Config
4
4
 
5
- attr_reader :bundles, :files, :src_dir, :filters
5
+ attr_reader :bundles, :files, :filters, :after_write_blocks
6
6
 
7
7
  def initialize
8
8
  @bundles = []
9
9
  @files = []
10
10
  @filters = []
11
+ @after_write_blocks = []
11
12
  end
12
13
 
13
14
  def version(v = nil)
14
- @version = v if v
15
+ @version = JBundle::Version.new(v) if v
15
16
  @version
16
17
  end
17
18
 
@@ -43,6 +44,10 @@ module JBundle
43
44
  filters << block
44
45
  end
45
46
 
47
+ def after_write(&block)
48
+ after_write_blocks << block
49
+ end
50
+
46
51
  def bundles_and_files
47
52
  @bundles + @files
48
53
  end
@@ -1,3 +1,3 @@
1
1
  module JBundle
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -22,6 +22,10 @@ module JBundle
22
22
  def to_s
23
23
  full
24
24
  end
25
+
26
+ def inspect
27
+ "[JBundle::Version] #{full}"
28
+ end
25
29
 
26
30
  protected
27
31
 
@@ -34,7 +38,7 @@ module JBundle
34
38
  class Writer
35
39
 
36
40
  def initialize(compiler, version, target_dir)
37
- @compiler, @version, @target_dir = compiler, Version.new(version), target_dir
41
+ @compiler, @version, @target_dir = compiler, version, target_dir
38
42
  @out = []
39
43
  end
40
44
 
data/lib/jbundle.rb CHANGED
@@ -34,9 +34,11 @@ module JBundle
34
34
  end
35
35
 
36
36
  def write!
37
- output.map do |compiler|
37
+ out = output.map do |compiler|
38
38
  Writer.new(compiler, config.version, config.target_dir || './dist').write
39
39
  end.flatten
40
+ run_after_write unless config.after_write_blocks.empty?
41
+ out
40
42
  end
41
43
 
42
44
  def build(name)
@@ -51,6 +53,10 @@ module JBundle
51
53
  config.instance_eval( ::File.read(file), file )
52
54
  end
53
55
 
56
+ def run_after_write
57
+ config.after_write_blocks.each {|block| block.call(config)}
58
+ end
59
+
54
60
  end
55
61
 
56
62
  self.logger = lambda {|msg| puts "#{msg}\n"}
data/spec/JFile CHANGED
@@ -19,5 +19,16 @@ file 'file4.js'
19
19
  file 'text.txt'
20
20
 
21
21
  filter do |src, config|
22
- src.gsub!(/<VERSION>/, config.version)
22
+ src.gsub!(/<VERSION>/, config.version.full)
23
+ end
24
+
25
+ after_write do |config|
26
+
27
+ config.version.releaseable.each do |v|
28
+ from = "#{config.src_dir}/foo.txt"
29
+ to = "#{config.target_dir}/#{v}/foo.txt"
30
+ puts "copying #{to}"
31
+ FileUtils.cp(from, to)
32
+ end
33
+
23
34
  end
data/spec/jbundle_spec.rb CHANGED
@@ -66,6 +66,11 @@ describe "JBundle" do
66
66
  File.exist?(DIST + '/1.6/text.min.txt').should be_false
67
67
  end
68
68
 
69
+ it 'should have run after_write block' do
70
+ File.exist?(DIST + '/1.6.1/foo.txt').should be_true
71
+ File.exist?(DIST + '/1.6/foo.txt').should be_true
72
+ end
73
+
69
74
  it 'should return a list of files written' do
70
75
  @written_files.should == [
71
76
  DIST + '/1.6.1/foo.js',
@@ -0,0 +1 @@
1
+ # This file should just be copied, not processed nor minified
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbundle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ismael Celis
@@ -96,6 +96,7 @@ files:
96
96
  - spec/test_src/file2.js
97
97
  - spec/test_src/file3.js
98
98
  - spec/test_src/file4.js
99
+ - spec/test_src/foo.txt
99
100
  - spec/test_src/license.txt
100
101
  - spec/test_src/text.txt
101
102
  has_rdoc: true