app_stack 1.3.0 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/app_stack.gemspec CHANGED
@@ -15,6 +15,7 @@ Gem::Specification.new 'app_stack', AppStack::VERSION do |s|
15
15
  s.add_dependency 'tilt', '>= 1.4.1'
16
16
  s.add_dependency 'term-ansicolor', '>= 1.2.2'
17
17
  s.add_dependency 'activesupport', '>= 3.2.14'
18
+ s.add_dependency 'diffy'
18
19
  s.add_development_dependency 'rspec', '>= 2.14.1'
19
20
  s.add_development_dependency 'simplecov', '>= 0.7.1'
20
21
  end
@@ -124,7 +124,7 @@ module AppStack
124
124
  target_dir = File.dirname(to)
125
125
  FileUtils.mkdir_p target_dir unless File.directory?(target_dir)
126
126
  puts "copied #{fr.blue} \n to: " + to.green.bold
127
- FileUtils.copy fr, to
127
+ FileUtils.cp_r fr, to
128
128
  end
129
129
 
130
130
  def render_file!(fr, to)
@@ -87,9 +87,14 @@ module AppStack
87
87
 
88
88
  # add local template files the copy list
89
89
  Dir[directory + "/**/*{#{@config[:tpl_ext].join(',')}}"].each do |f|
90
- @copy_list['r:' + f] = f.gsub(/#{@config[:tpl_ext].join('|')}$/, '')
91
- echo 'found local template file: ',
92
- short_path(f) + ' -> ' + short_path(@copy_list['r:' + f])
90
+ of = f.gsub(/#{@config[:tpl_ext].join('|')}$/, '')
91
+ if File.exists?(of)
92
+ @copy_list['r:' + f] = of
93
+ echo 'found local template file: ',
94
+ short_path(f) + ' -> ' + short_path(of)
95
+ else
96
+ echo 'skip template file: ', f
97
+ end
93
98
  end
94
99
 
95
100
  merge!
@@ -2,5 +2,5 @@
2
2
 
3
3
  # AppStack module
4
4
  module AppStack
5
- VERSION = '1.3.0'
5
+ VERSION = '1.3.3'
6
6
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Huang Wei
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-14 00:00:00.000000000 Z
12
+ date: 2013-10-15 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: tilt
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: term-ansicolor
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: activesupport
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,13 +54,31 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 3.2.14
62
+ - !ruby/object:Gem::Dependency
63
+ name: diffy
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
55
78
  - !ruby/object:Gem::Dependency
56
79
  name: rspec
57
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
58
82
  requirements:
59
83
  - - ! '>='
60
84
  - !ruby/object:Gem::Version
@@ -62,6 +86,7 @@ dependencies:
62
86
  type: :development
63
87
  prerelease: false
64
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
65
90
  requirements:
66
91
  - - ! '>='
67
92
  - !ruby/object:Gem::Version
@@ -69,6 +94,7 @@ dependencies:
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: simplecov
71
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
72
98
  requirements:
73
99
  - - ! '>='
74
100
  - !ruby/object:Gem::Version
@@ -76,6 +102,7 @@ dependencies:
76
102
  type: :development
77
103
  prerelease: false
78
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
79
106
  requirements:
80
107
  - - ! '>='
81
108
  - !ruby/object:Gem::Version
@@ -99,7 +126,6 @@ files:
99
126
  - lib/app_stack/cli_options.rb
100
127
  - lib/app_stack/copy_list_builder.rb
101
128
  - lib/app_stack/local_files_parser.rb
102
- - lib/app_stack/merger.rb
103
129
  - lib/app_stack/stack_app.rb
104
130
  - lib/app_stack/version.rb
105
131
  - spec/config_spec.rb
@@ -146,26 +172,27 @@ files:
146
172
  homepage: https://github.com/7lime/app_stack-gem
147
173
  licenses:
148
174
  - MIT
149
- metadata: {}
150
175
  post_install_message:
151
176
  rdoc_options: []
152
177
  require_paths:
153
178
  - lib
154
179
  required_ruby_version: !ruby/object:Gem::Requirement
180
+ none: false
155
181
  requirements:
156
182
  - - ! '>='
157
183
  - !ruby/object:Gem::Version
158
184
  version: '0'
159
185
  required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
160
187
  requirements:
161
188
  - - ! '>='
162
189
  - !ruby/object:Gem::Version
163
190
  version: '0'
164
191
  requirements: []
165
192
  rubyforge_project:
166
- rubygems_version: 2.0.6
193
+ rubygems_version: 1.8.23
167
194
  signing_key:
168
- specification_version: 4
195
+ specification_version: 3
169
196
  summary: Use as a rake task, define a stack of modules and app-stack will merge files
170
197
  from those stack-apps to the local application directory.
171
198
  test_files:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTJmNjU5OThhNjgwMjg5MzJjZGVmNjQ2MGU2ZTkzMDNkZGY0NGM5NQ==
5
- data.tar.gz: !binary |-
6
- ZTA1ODI2N2RlM2U3MTNiZmFkM2NjMmI5ZTdhNWU5NzRiNTE1NDhlMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzAzMmQ5YzEwNWIzZTI3MDk1MmE1MzMzOWZhOGQ5YWFkMWNkZTJhY2E5OGJl
10
- ZjgwOTNiZGRhYjY2MWM3MDdmMGRjOWNmYTVhYjg5ZDE4NGIzMmI0NTNmMTA1
11
- ZTUwMWFhZDNkMTg5MzAyYjdmYmMzOTI4ZGUyM2QxYWIyMDk1NTI=
12
- data.tar.gz: !binary |-
13
- MjVjNDgwNmE1OWQ2YTlhODZhZDgxNDYzZGM4ZGY3YzQ4MjdjMDE5NmNkNTdh
14
- NWY2ZWNiYzViYmRmNDkzNTA4MGM2NmU1ZDM2N2RlMDk4OTM5ZWY2MTFkZTI4
15
- OWNmNWJjNjk3NDYwYjYxYWUxZGNlNzk0ZDdjZjc0NmRmZTEwN2E=
@@ -1,136 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module AppStack
4
- # runner for merge files from stack of apps
5
- class Merger
6
- attr_reader :stacks, :copy_list, :render_list
7
-
8
- def initialize(conf_file, verbose = false)
9
- # load configuration
10
- @conf_file = conf_file
11
- @config = Config.new(@conf_file)
12
- @verbose = verbose
13
-
14
- @stacks = []
15
- @attr_vars = {}
16
- @attr_last_mod = File.mtime(@conf_file)
17
- parse_stacks
18
-
19
- @copy_list = {}
20
- @render_list = {}
21
- @prepared = false
22
- end
23
-
24
- def prepare(verbose = false)
25
- local_dir = Pathname.new(@config.directory)
26
- @stacks.each do |stack|
27
- stack.copy_list.each do |fr, to| # copy from, copy to
28
- to = local_dir + to.gsub(/^\//, '')
29
- if @config.exclude_files[to.to_s]
30
- puts 'keep '.green.bold + to.to_s.gsub(@config.stack_dir, '') if verbose
31
- elsif newer?(to, fr)
32
- puts 'skip '.white.bold + to.to_s.gsub(@config.stack_dir, '') if verbose
33
- else
34
- # render list
35
- tpl_file = nil
36
- @config.tpl_ext.each { |ext| tpl_file = fr + ext if File.exists?(fr + ext) }
37
-
38
- if tpl_file
39
- @render_list[to.to_s] = tpl_file if newer?(tpl_file, to) || attr_mod?(to)
40
- else
41
- @copy_list[to.to_s] = fr if newer?(fr, to)
42
- end
43
- end
44
- end
45
- end
46
-
47
- # render local templates
48
- Find.find(@config.directory) do |fr|
49
- next if File.directory? fr
50
- tpl_file = nil
51
- @config.tpl_ext.each { |ext| tpl_file = fr + ext if File.exists?(fr + ext) }
52
- if tpl_file
53
- @render_list[fr] = tpl_file if newer?(tpl_file, fr) || attr_mod?(fr)
54
- end
55
- end
56
-
57
- if verbose
58
- @copy_list.each do |to, fr|
59
- puts 'copy '.bold + fr.gsub(@config.stack_dir, '')
60
- puts ' to '.bold + to.to_s.gsub(@config.stack_dir, '')
61
- end
62
-
63
- @render_list.each do |to, fr|
64
- puts 'render '.bold + fr.gsub(@config.stack_dir, '')
65
- puts ' to '.bold + to.to_s.gsub(@config.stack_dir, '')
66
- end
67
- end
68
-
69
- @prepared = true
70
- end
71
-
72
- def merge!
73
- @prepared || prepare(@verbose)
74
- @copy_list.each { |to, fr| copy_file!(fr, to) }
75
- @render_list.each { |to, fr| render_file!(fr, to) }
76
- end
77
-
78
- private
79
-
80
- def copy_file!(fr, to)
81
- target_dir = File.dirname(to)
82
- FileUtils.mkdir_p target_dir unless File.directory?(target_dir)
83
- FileUtils.copy fr, to
84
- end
85
-
86
- def render_file!(fr, to)
87
- var = @attr_vars.deep_merge(@config.attr_vars)
88
- oh = File.open(to, 'wb')
89
- if fr.match(/\.liquid$/)
90
- require 'liquid'
91
- oh.write Liquid::Template.parse(File.open(fr, 'r:utf-8').read).render(var)
92
- else
93
- tilt = Tilt.new(fr)
94
- oh.write tilt.render(OpenStruct.new(var))
95
- end
96
- oh.close
97
- end
98
-
99
- # get a list of stacked app object
100
- def parse_stacks
101
- @config.stack.each do |stk|
102
- case
103
- when stk.is_a?(String) then @stacks << load_stack(stk, ['default'])
104
- when stk.is_a?(Hash)
105
- stk.each { |key, groups| @stacks << load_stack(key, groups) }
106
- else
107
- raise 'stack must be a string or a hash, in ' + @conf_file
108
- end
109
- end
110
- end
111
-
112
- # read stack from list, set copy_list
113
- def load_stack(stack_name, groups)
114
- conf_base_name = File.basename(@conf_file)
115
- stack_dir = Pathname.new(@config.stack_dir) + stack_name
116
- stack = Config.new(stack_dir + conf_base_name)
117
- fmodtime = File.mtime(stack_dir + conf_base_name)
118
- @attr_last_mod = fmodtime if fmodtime > @attr_last_mod # update file mod time
119
- @attr_vars = @attr_vars.deep_merge stack.attr_vars
120
- groups.each { |grp| stack.add_copy_list(grp) }
121
- stack
122
- end
123
-
124
- # if f1 newer than f2, or f2 not exits but f1 does.
125
- def newer?(f1, f2)
126
- return false unless File.exists?(f1)
127
- return true unless File.exists?(f2)
128
- File.mtime(f1) > File.mtime(f2)
129
- end
130
-
131
- def attr_mod?(to)
132
- return true unless File.exists?(to)
133
- @attr_last_mod > File.mtime(to)
134
- end
135
- end
136
- end