app_stack 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -10,15 +10,17 @@ a stack of modules.
10
10
  Put a configuration file `.app_stack.yml` in your application
11
11
  directory, in format like:
12
12
 
13
- stack: [module-1, module-2]
13
+ stack:
14
+ - module-1
15
+ - module-2: [defaults, tests]
14
16
  stack_dir: '../stack-apps'
15
17
  tpl_ext: '.erb'
16
18
  verbose: 1
17
19
  export:
18
20
  - lib/**/*.rb
19
21
  - app/**/*.rb
20
- include:
21
- - spec/**/*.rb
22
+ - tests:
23
+ - spec/**/*.rb
22
24
  exclude:
23
25
  - lib/extra/*.rb
24
26
  attrs:
@@ -33,6 +35,27 @@ directory, in format like:
33
35
  files:
34
36
  README.md: __self
35
37
 
38
+
39
+ `stack`
40
+ : 设置导入的模块名,元素为字符串(只导入'default'组的文件)或Hash,
41
+ : 为Hash时,key为模块名,值为文件组的数组('all'代表全部)。
42
+
43
+ `stack_dir`(默认为`../stack-apps`)
44
+ : 模块程序所在位置。
45
+
46
+ `export`(默认为空)
47
+ : 可被拷贝至其他模块的文件pattern(为字符串时),或pattern的组
48
+ : (像上述示例中的`tests`一样)。
49
+
50
+ `exclude`(默认为空)
51
+ : 导出到其它模块时,从`export`列表中除外的文件pattern。
52
+ : 注意如果模块中定义了`.gitignore`文件,则其中的内容也会被加载至
53
+ : `exclude`列表。
54
+
55
+ `attrs`
56
+ : 用于assign至`.erb`文件的属性值。在上面的例子中module2会继承
57
+ : module1中设置的值。
58
+
36
59
  `files` field is auto-generated, you should not edit it manually.
37
60
 
38
61
  `export` defines files that should be copied when other modules include
@@ -47,7 +70,7 @@ Variables defined in `attrs` will be assigned into `.erb` files.
47
70
 
48
71
  If you have both a `config.yml` and a `config.yml.erb` file, when export,
49
72
  the `config.yml.erb` will be used instead of `config.yml`, and `attrs` will
50
- be assigned into this file.
73
+ be assigned into this file.
51
74
 
52
75
  Variables in `attrs` will be merged in chain follows the app-stack.
53
76
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  # AppStack module
4
4
  module AppStack
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
data/lib/app_stack.rb CHANGED
@@ -26,8 +26,8 @@ module AppStack
26
26
  render_self!(@self_files)
27
27
 
28
28
  # rewrite configuration back to app-stack file
29
- @config['files'] = @files
30
- File.open(conf_file, 'wb') { |fh| fh.puts YAML.dump(@config) }
29
+ @origin_config['files'] = @files
30
+ File.open(conf_file, 'wb') { |fh| fh.puts YAML.dump(@origin_config) }
31
31
  end
32
32
 
33
33
  # convert directory names, load configuration from yaml file
@@ -35,6 +35,7 @@ module AppStack
35
35
  def load_configuration(conf_file)
36
36
  @conf_file = conf_file || CONF_FILE
37
37
  @config = YAML.load(File.read(@conf_file))
38
+ @origin_config = @config.dup
38
39
 
39
40
  @app_root = @config['app_root'] || File.dirname(@conf_file)
40
41
  @app_root = File.expand_path(@app_root)
@@ -42,17 +43,25 @@ module AppStack
42
43
  @stack_dir = File.expand_path(@app_root + '/' +
43
44
  @stack_dir) if @stack_dir.match(/^\.\.?\//)
44
45
 
46
+ # default values
45
47
  @verbose = @config['verbose'] || 1
46
48
  @verbose = @verbose.to_i
47
49
 
48
50
  @config['tpl_ext'] ||= '.erb'
51
+ raise ArgumentError, 'ERROR: `include` key depriciated, ' +
52
+ 'please update your yml file' if @config['include']
53
+ @config['include'] = []
54
+ @config['exclude'] ||= []
55
+ @config['export'] ||= [] # even export can be blank
56
+ @config['stack'] ||= []
57
+ @config['files'] ||= {}
49
58
 
50
59
  # attrs to assigned into template
51
60
  @attrs = {}
52
61
  # file list under the app_root
53
62
  @self_files = []
54
63
 
55
- @files = @config['files'] || {}
64
+ @files = @config['files']
56
65
  end
57
66
 
58
67
  # for files already in the app root, register to no-copy list
@@ -91,13 +100,20 @@ module AppStack
91
100
  # copy from a stack of applications
92
101
  def merge_stacks!(stack)
93
102
  stack.each do |app|
94
- app_dir = @stack_dir + '/' + app
103
+
104
+ app_dir, groups = '', ['default']
105
+ if app.is_a?(Hash)
106
+ app.each { |k, v| app_dir, groups = k, v }
107
+ else
108
+ app_dir = @stack_dir + '/' + app
109
+ end
110
+
95
111
  raise "no directory found for #{app}" unless File.directory?(app_dir)
96
112
  raise "no configuration found for #{app}" unless
97
113
  File.exists?(app_dir + '/' + File.basename(@conf_file))
98
114
 
99
115
  # loop over remote files
100
- elist = export_list(app_dir)
116
+ elist = export_list(app_dir, groups)
101
117
  elist.each do |file|
102
118
  # skip .erb file as template
103
119
  next if file.match(/#{@config['tpl_ext']}$/) &&
@@ -149,8 +165,8 @@ module AppStack
149
165
  if File.exists?(dir + '/.gitignore')
150
166
  File.read(dir + '/.gitignore').split("\n").each do |line|
151
167
  Dir[dir + '/' + line].each do |f|
152
- f.sub!(/^#{dir}\//, '')
153
- ilist << f unless ilist.include?(f)
168
+ fn = f.sub(/^#{dir}\//, '')
169
+ ilist << fn unless ilist.include?(fn)
154
170
  end
155
171
  end
156
172
  end
@@ -165,32 +181,46 @@ module AppStack
165
181
  end
166
182
 
167
183
  # find a list of file to copy based on export setting
168
- def export_list(dir)
184
+ def export_list(dir, groups = ['default'])
169
185
  dir_conf = YAML.load(File.read(dir + '/' + File.basename(@conf_file)))
170
186
  dir_conf['export'] ||= []
187
+ dir_conf['exclude'] ||= []
171
188
 
172
189
  # update attr list for assign to template files
173
190
  @attrs.deep_merge! dir_conf['attrs'] if dir_conf['attrs'] &&
174
191
  dir_conf['attrs'].is_a?(Hash)
175
192
 
176
- flist = []
193
+ group_patterns, flist = { 'default' => [] }, []
177
194
  # export list defined in stack app's configuration
178
195
  dir_conf['export'].each do |e|
179
- Dir[dir + '/' + e].each { |f| flist << f.sub(/^#{dir}\/?/, '') }
196
+ if e.is_a?(Hash)
197
+ e.each { |k, v| group_patterns[k] = v }
198
+ else
199
+ group_patterns['default'] << e
200
+ end
180
201
  end
181
202
 
182
- # collect include/exclude list from configuration of app-root
183
- inc_list, exc_list = [], []
184
- @config['include'].each do |inc|
185
- Dir[dir + '/' + inc].each { |f| inc_list << f.sub(/^#{dir}\/?/, '') }
203
+ group_patterns.each do |k, v|
204
+ raise "file for group #{k} is not a array." unless v.is_a?(Array)
205
+ next unless groups.include?(k) || groups.include?('all')
206
+ v.each do |e|
207
+ Dir[dir + '/' + e].each do |f|
208
+ fn = f.sub(/^#{dir}\/?/, '')
209
+ flist << fn unless flist.include?(fn)
210
+ end
211
+ end
186
212
  end
187
213
 
188
- @config['exclude'].each do |exc|
189
- Dir[dir + '/' + exc].each { |f| exc_list << f.sub(/^#{dir}\/?/, '') }
214
+ exc_list = []
215
+ dir_conf['exclude'].each do |exc|
216
+ Dir[dir + '/' + exc].each do |f|
217
+ fn = f.sub(/^#{dir}\/?/, '')
218
+ exc_list << fn unless exc_list.include?(fn)
219
+ end
190
220
  end
191
221
 
192
222
  # adjust by include/exclude and
193
- flist + inc_list - gitignore_list(dir) - exc_list
223
+ flist - gitignore_list(dir) - exc_list
194
224
  end
195
225
 
196
226
  # copy file if newer
@@ -218,14 +248,18 @@ module AppStack
218
248
 
219
249
  # render from erb if newer
220
250
  def render_file!(f, target)
221
- # done = 'keep'.white
222
- # if newer?(f, target)
223
- tilt = Tilt::ERBTemplate.new(f)
224
- oh = File.open(target, 'wb')
225
- oh.write tilt.render(OpenStruct.new(@attrs.deep_merge(@config['attrs'])))
226
- oh.close
227
- 'rendered'.bold.green
228
- # end
251
+ done = 'keep'.white
252
+ unless newer?(target, f)
253
+ tilt = Tilt::ERBTemplate.new(f)
254
+ oh = File.open(target, 'wb')
255
+ oh.write tilt.render(OpenStruct.new(@attrs.deep_merge(@config['attrs'])))
256
+ oh.close
257
+
258
+ # update template timestamp
259
+ FileUtils.touch(f)
260
+ done = 'rendered'.bold.green
261
+ end
262
+ done
229
263
  end
230
264
 
231
265
  # use module variables, skip `new`
@@ -35,9 +35,24 @@ describe AppStack do
35
35
  el.include?('lib/extra/excludes.rb').should be_false
36
36
  end
37
37
 
38
- it 'include explicitly included files' do
39
- el.include?('spec/spec_helper.rb').should be_true
40
- el.include?('spec/support/api_test.rb').should be_true
38
+ # depreciated
39
+ # it 'include explicitly included files' do
40
+ # el.include?('spec/spec_helper.rb').should be_true
41
+ # el.include?('spec/support/api_test.rb').should be_true
42
+ # end
43
+
44
+ it 'can include grouped files' do
45
+ el.include?('spec/support/api_test.rb').should be_false
46
+ elist = AppStack.export_list('spec/fixtures/incexc', ['default', 'test'])
47
+ elist.include?('spec/support/api_test.rb').should be_true
48
+ elist.include?('spec/spec_helper.rb').should be_true
49
+ end
50
+
51
+ it 'can set to include all files' do
52
+ elist = AppStack.export_list('spec/fixtures/incexc', ['all'])
53
+ elist.include?('spec/support/api_test.rb').should be_true
54
+ elist.include?('spec/spec_helper.rb').should be_true
55
+ elist.include?('lib/mixin/otherlib.rb').should be_true
41
56
  end
42
57
  end
43
58
 
@@ -6,8 +6,6 @@ export:
6
6
  - lib/**/*.rb
7
7
  - config/**/*
8
8
  - app/**/*.rb
9
- include:
10
- - spec/**/*.rb
11
9
  exclude:
12
10
  - lib/extra/*.rb
13
11
  attrs:
@@ -21,4 +19,3 @@ attrs:
21
19
  development:
22
20
  app_stack: ~> 0.0.8
23
21
  files:
24
- tpl_ext: .erb
@@ -5,8 +5,8 @@ verbose: 1
5
5
  export:
6
6
  - lib/**/*.rb
7
7
  - app/**/*.rb
8
- include:
9
- - spec/**/*.rb
8
+ - test:
9
+ - spec/**/*
10
10
  exclude:
11
11
  - lib/extra/*.rb
12
12
  attrs:
@@ -6,8 +6,6 @@ export:
6
6
  - lib/**/*.rb
7
7
  - Rakefile
8
8
  - Rakefile.erb
9
- include:
10
- - spec/**/*.rb
11
9
  exclude:
12
10
  - lib/extra/*.rb
13
11
  attrs:
@@ -6,8 +6,6 @@ export:
6
6
  - lib/**/*.rb
7
7
  - config/**/*
8
8
  - app/**/*.rb
9
- include:
10
- - spec/**/*.rb
11
9
  exclude:
12
10
  - lib/extra/*.rb
13
11
  attrs:
@@ -31,4 +29,3 @@ files:
31
29
  lib/libonly1.rb: module-1
32
30
  lib/libonly2.rb: module-2
33
31
  Gemfile: module-2
34
- tpl_ext: .erb
@@ -5,8 +5,6 @@ verbose: 1
5
5
  export:
6
6
  - lib/**/*.rb
7
7
  - app/**/*.rb
8
- include:
9
- - spec/**/*.rb
10
8
  exclude:
11
9
  - lib/extra/*.rb
12
10
  attrs:
@@ -4,8 +4,6 @@ export:
4
4
  - config/**/*
5
5
  - app/**/*.rb
6
6
  - Gemfile
7
- include:
8
- - spec/**/*.rb
9
7
  exclude:
10
8
  - lib/extra/*.rb
11
9
  attrs:
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.0.0
4
+ version: 1.1.0
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-09-10 00:00:00.000000000 Z
12
+ date: 2013-09-11 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,6 +54,7 @@ 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
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rspec
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: simplecov
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ~>
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ~>
81
92
  - !ruby/object:Gem::Version
@@ -92,6 +103,7 @@ files:
92
103
  - app_stack.gemspec
93
104
  - lib/app_stack.rb
94
105
  - lib/app_stack/version.rb
106
+ - spec/export_list_spec.rb
95
107
  - spec/fixtures/.app_stack.yml
96
108
  - spec/fixtures/incexc-config.yml
97
109
  - spec/fixtures/incexc/.gitignore
@@ -119,36 +131,37 @@ files:
119
131
  - spec/fixtures/stack_apps/module-2/lib/libonly2.rb
120
132
  - spec/gitignore_list_spec.rb
121
133
  - spec/load_configuration_spec.rb
122
- - spec/merge_stack_spec.rb
123
134
  - spec/register_self_spec.rb
124
135
  - spec/spec_helper.rb
125
136
  - spec/stackup_spec.rb
126
137
  homepage: https://github.com/7lime/app_stack-gem
127
138
  licenses:
128
139
  - MIT
129
- metadata: {}
130
140
  post_install_message:
131
141
  rdoc_options: []
132
142
  require_paths:
133
143
  - lib
134
144
  required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
135
146
  requirements:
136
147
  - - ! '>='
137
148
  - !ruby/object:Gem::Version
138
149
  version: '0'
139
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
+ none: false
140
152
  requirements:
141
153
  - - ! '>='
142
154
  - !ruby/object:Gem::Version
143
155
  version: '0'
144
156
  requirements: []
145
157
  rubyforge_project:
146
- rubygems_version: 2.0.6
158
+ rubygems_version: 1.8.23
147
159
  signing_key:
148
- specification_version: 4
160
+ specification_version: 3
149
161
  summary: Use as a rake task, define a stack of modules and app-stack will merge files
150
162
  from those stack-apps to the local application directory.
151
163
  test_files:
164
+ - spec/export_list_spec.rb
152
165
  - spec/fixtures/incexc/lib/anyway.rb
153
166
  - spec/fixtures/incexc/lib/extra/excludes.rb
154
167
  - spec/fixtures/incexc/lib/mixin/otherlib.rb
@@ -160,7 +173,6 @@ test_files:
160
173
  - spec/fixtures/stack_apps/module-2/lib/libonly2.rb
161
174
  - spec/gitignore_list_spec.rb
162
175
  - spec/load_configuration_spec.rb
163
- - spec/merge_stack_spec.rb
164
176
  - spec/register_self_spec.rb
165
177
  - spec/spec_helper.rb
166
178
  - spec/stackup_spec.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MmFmMzhjYjBiYmRmNjZkZjFjNGIxZWU5OThjZjJhOTRhNGJlZWUwNg==
5
- data.tar.gz: !binary |-
6
- MGRmMTNmYWY5NWI1ODY0ZWVmNDdmZDcxYmFmNTQyNzhkMzBlN2YwMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YmRjYmU4N2MwZDIxYmUyMDRjM2FlMDRjNGIwN2RmZTA0YjhjZDU5MDgzYmFh
10
- OTI3Yjk3NTFiM2FjNzRmMDI1YjM4YWU4ZWQ3OWM0NGZmNTMyMTg1OTMzYjk3
11
- NWM4YTUwZGVhZDcyOTRlMTZmYWI3MTNjOGE5Mzk2MzEyYjQxN2Y=
12
- data.tar.gz: !binary |-
13
- ZjFkODQzOTVjZTA1ZDNjZWFjYjRjZWNjMjNkNTRmYmE0ZTVjNTQyZWQ5MDNi
14
- YmQwODA1MTQwZGZkZGUxMGVmNWIzY2UyZDMyNWEwM2Y3YWNhZDE5ZDJjOTUy
15
- NTY3ZTlhZDEyYzU4MDliN2U3NmUxYzNlZGRhYmFjMTM4YzVjMjU=