app_stack 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mjg0MTY2ZmU2NDExMmU3ZjVlYTM5ZDdiODZjYTEyMzg2ZTM4MGM4MA==
5
+ data.tar.gz: !binary |-
6
+ NTllMzU1NmZkZjJlYzM2N2UxYjMzZTQwYWZkZDEzNmNjZGE3NWM1ZQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NWJkOTZlY2ZmNmNjZDc2YWU5MDZmMTljOGM0ZTYzZDUwNTIyMjc2N2NiMmQ3
10
+ ZjIwNTYxZDk5MGRkYWM0YjhkY2FhZGI1NjY3NTFlMmUwZjlmYjBmYzJkMTNi
11
+ MTk2ZDYxZTRhNzE3OTFjMGY5YmE5ZjFiMDBiYTg4MjNlN2I5MmQ=
12
+ data.tar.gz: !binary |-
13
+ NmQ4ZTRjNDI3MzI4NWY4MTlhYzc4MWRmM2U4ZWNjMjhlZDVlODFiNzVhZDYz
14
+ YTUyMWY5ZDZhMzIwYWY3Y2JhNGMzZmE0MDkzYmI0MjhhZTllMmM0ZTA3ODFl
15
+ OGM0ODFhNGQzMTVlMDMyZmUzZWZkMGE3ODQ3MmZiOGViY2I2ZmY=
data/README.md CHANGED
@@ -10,6 +10,11 @@ A configuration file `.app-stack.yml` in you app-root, in format like:
10
10
  app_dir: '../stack-apps'
11
11
  tpl_ext: '.sample.erb'
12
12
  verbose: 1
13
+ file_patterns:
14
+ spec/**/*.rb
15
+ lib/**/*.rb
16
+ **/*.line_addon
17
+ **/*.erb
13
18
  attrs:
14
19
  dababase_name: 'nameofdatabase'
15
20
  files:
@@ -22,7 +27,7 @@ And in `Rakefile` add:
22
27
 
23
28
  namespace :stack do
24
29
  task :update do
25
- AppStack.new('.app-stack.yml').run!
30
+ AppStack.run!('.app-stack.yml')
26
31
  end
27
32
  end
28
33
 
@@ -6,18 +6,18 @@ stack_apps_dir: ../stack-apps
6
6
  tpl_ext: .template.erb
7
7
  addon_ext: .line_addon
8
8
  verbose: 1
9
- ignores:
10
- - .+\.swap
11
- - ~.+
12
- - .+~
13
- - docs/?.*
14
- - .git/?.*
9
+ file_patterns:
10
+ - app/**/*.rb
11
+ - spec/**/*.rb
12
+ - lib/**/*.rb
13
+ - config/**/*.rb
14
+ - config/**/*.conf
15
+ - config/**/*.yaml
15
16
  attrs:
16
17
  application_name: My App
17
18
  from_self: myapp
18
19
  files:
19
- Gemfile: __self
20
- README: __self
21
- config: __self
22
- config/app.config.rb: __self
23
- config/configuration.yml: __self
20
+ config/app.config.rb: base-app
21
+ app/controllers/hello_controller.rb: __self
22
+ app/api_controller.rb: __self
23
+ app/config.rb: __self
@@ -1 +1,2 @@
1
1
  readme in my app
2
+ readme in base_app
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ <%= "Holly OK." %>
@@ -2,5 +2,5 @@
2
2
 
3
3
  # AppStack module
4
4
  module AppStack
5
- VERSION = '0.0.6'
5
+ VERSION = '0.0.7'
6
6
  end
data/lib/app_stack.rb CHANGED
@@ -3,17 +3,19 @@
3
3
  require 'yaml'
4
4
  require 'find'
5
5
  require 'fileutils'
6
+ require 'ostruct'
7
+ require 'tilt/erb'
8
+
6
9
  require 'term/ansicolor'
7
10
  # mixin String class for term-color methods
8
11
  class String; include Term::ANSIColor end
9
- require 'tilt/erb'
10
- require 'ostruct'
11
12
 
12
13
  ## A namespace for app-stack based modules
13
14
  module AppStack
14
15
 
15
16
  CONF_FILE = '.app-stack.yml'
16
17
 
18
+ # public entry ponit, receive a configuration filename
17
19
  def run!(file = '.app-stack.yml')
18
20
  # load configuration
19
21
  @config = YAML.load(File.read(file))
@@ -21,79 +23,40 @@ module AppStack
21
23
  # assign default values:
22
24
  @app_root = File.expand_path(File.dirname(file)) unless @config['app_root']
23
25
  @stack_apps_dir = @config['stack_apps_dir']
26
+ # convert relative path:
24
27
  @stack_apps_dir = @app_root + '/' +
25
28
  @stack_apps_dir if @stack_apps_dir.match(/^\.\.?\//)
26
29
 
27
30
  @files = @config['files'] || {}
28
31
  register_own_files!
29
32
  # loop over each stack application
30
- @config['stack'].each { |stack_app| do_copy(stack_app) }
33
+ @config['stack'].each { |stack_app| do_copy_stack!(stack_app) }
34
+
31
35
  # rewrite configuration back to app-stack file
32
36
  @config['files'] = @files
33
37
  File.open(file, 'wb') { |fh| fh.puts YAML.dump(@config) }
34
38
  end
35
39
 
36
- def newer(f1, f2)
37
- return false unless File.exists?(f1)
38
- return true unless File.exists?(f2)
39
- File.mtime(f1) > File.mtime(f2)
40
- end
41
-
42
- def do_addon!(f, basename)
43
- target = File.expand_path(@app_root + '/' + basename)
44
- # add on always applies
45
- addon_file = f + @config['addon_ext']
46
- if File.exists?(addon_file) # && newer(addon_file, target)
47
- add_lines = File.read(addon_file).split("\n")
48
- add_lines -= File.read(target).split("\n")
49
- afh = File.open(target, 'a')
50
- add_lines.each { |line| afh.puts line }
51
- afh.close
52
- done = 'add lines'.bold.green if add_lines.size > 0
53
- end
54
- end
55
-
56
- # rubocop:disable MethodLength
57
- def copy_file!(f, basename)
58
- done = 'keeped'.green
59
- target = File.expand_path(@app_root + '/' + basename)
60
- # directory?
61
- if File.directory?(f)
62
- if File.directory?(target)
63
- done = 'exists'.green
64
- else
65
- FileUtils.mkdir_p target
66
- done = 'created'.bold.green
40
+ # for files already in the app root, register to no-copy list
41
+ def register_own_files!
42
+ @config['file_patterns'].each do |pt|
43
+ Dir[@app_root + '/' + pt].each do |f|
44
+ next if f == @app_root
45
+ basename = f.sub(/^#{@app_root}\//, '')
46
+ if @files[basename]
47
+ carp "From #{'self'.blue.bold} #{basename.bold} ",
48
+ 'keep'.white if @files[basename] == '__self'
49
+ else
50
+ carp "From #{'self'.blue.bold} #{basename.bold}",
51
+ 'registed'.green.bold
52
+ @files[basename] = '__self'
53
+ end
67
54
  end
68
- else
69
- tpl_file = f + @config['tpl_ext']
70
- if File.exists?(tpl_file) && newer(tpl_file, target)
71
- @tilt = Tilt::ERBTemplate.new(tpl_file)
72
- oh = File.open(target, 'wb')
73
- oh.write @tilt.render(OpenStruct.new(@attr.merge(@config['attrs'])))
74
- oh.close
75
- done = 'rendered'.bold.green
76
- elsif newer(f, target)
77
- FileUtils.copy f, target
78
- done = 'copied'.bold.green
79
- end
80
55
  end
81
- done
82
- end
83
- # rubocop:able MethodLength
84
-
85
- def ignores(f)
86
- @config['ignores'] = [] unless @config['ignores']
87
- return true if f == CONF_FILE
88
- return true if /#{@config['tpl_ext']}$/.match(f)
89
- return true if /#{@config['addon_ext']}$/.match(f)
90
- @config['ignores'].each do |ptn|
91
- return true if /^#{ptn}$/.match(f)
92
- end
93
- false
94
56
  end
95
57
 
96
- def do_copy(stack_app)
58
+ # copy files for each included file
59
+ def do_copy_stack!(stack_app)
97
60
  raise 'invalid app name "__self"' if stack_app == '__self'
98
61
  stack_app_dir = File.expand_path(@stack_apps_dir + '/' + stack_app)
99
62
 
@@ -104,39 +67,84 @@ module AppStack
104
67
  stack_conf['attrs'].is_a?(Hash)
105
68
  end
106
69
 
70
+ # for each included files
71
+ @config['file_patterns'].each do |pt|
72
+ Dir[stack_app_dir + '/' + pt].each do |f|
73
+ basename = f.sub(/^#{stack_app_dir}\//, '')
74
+ # trivial ignore the stack directory itself:
75
+ next if f == stack_app_dir
76
+ if (@files[basename].nil? or @files[basename] == stack_app)
77
+ @files[basename] = stack_app unless @files[basename] # register
78
+ done = copy_file!(f, File.expand_path(@app_root + '/' + basename))
79
+ carp "From #{stack_app.blue.bold} #{basename.bold}", done
80
+ else
81
+ carp "From #{stack_app.blue.bold} #{basename.bold}",
82
+ 'skip, use '.white + @files[basename]
83
+ end
84
+ end
85
+ end
86
+
87
+ # for templates and addons
107
88
  Find.find(stack_app_dir).each do |f|
108
89
  basename = f.sub(/^#{stack_app_dir}\//, '')
109
- next if f == stack_app_dir
110
- next if ignores(basename)
111
- do_copy_it = @files[basename] ? false : true
112
- do_copy_it = true if @files[basename] == stack_app
113
- if do_copy_it
114
- @files[basename] = stack_app unless @files[basename]
115
- done = copy_file!(f, basename)
116
- carp "From #{stack_app.blue.bold} #{basename.bold}", done
117
- else
118
- carp "From #{stack_app.blue.bold} #{basename.bold}",
119
- 'skip, use '.white + @files[basename]
90
+
91
+ if basename.gsub!(/#{@config['tpl_ext']}$/, '')
92
+ target = File.expand_path(@app_root + '/' + basename)
93
+ # next unless File.exists?(target)
94
+ done = 'keep'.white
95
+ if newer?(f, target)
96
+ tilt = Tilt::ERBTemplate.new(f)
97
+ oh = File.open(target, 'wb')
98
+ oh.write tilt.render(OpenStruct.new(@attr.merge(@config['attrs'])))
99
+ oh.close
100
+ done = 'rendered'.bold.green
101
+ end
102
+ carp "From #{stack_app.blue.bold} render #{basename.bold}", done
103
+ elsif basename.gsub!(/#{@config['addon_ext']}$/, '')
104
+ target = File.expand_path(@app_root + '/' + basename)
105
+ if File.exists?(target)
106
+ done = do_addon!(f, target)
107
+ end
108
+ done ||= 'keep'.white
109
+ carp "From #{stack_app.blue.bold} addon #{basename.bold}", done
120
110
  end
121
- done = do_addon!(f, basename)
122
- carp "From #{stack_app.blue.bold} addon #{basename.bold}", done if done
123
111
  end
124
112
  end
125
113
 
126
- # for files already in the app root, register to no-copy list
127
- def register_own_files!
128
- Find.find(@app_root).each do |f|
129
- next if f == @app_root
130
- basename = f.sub(/^#{@app_root}\//, '')
131
- next if ignores(basename)
132
- if @files[basename]
133
- carp "From #{'self'.blue.bold} #{basename.bold} ",
134
- 'keep'.green if @files[basename] == '__self'
114
+ def newer?(f1, f2)
115
+ return false unless File.exists?(f1)
116
+ return true unless File.exists?(f2)
117
+ File.mtime(f1) > File.mtime(f2)
118
+ end
119
+
120
+ def do_addon!(addon_file, target)
121
+ add_lines = File.read(addon_file).split("\n")
122
+ add_lines -= File.read(target).split("\n")
123
+ afh = File.open(target, 'a')
124
+ add_lines.each { |line| afh.puts line }
125
+ afh.close
126
+ lines = add_lines.size
127
+ done = "add #{lines} lines".bold.green if lines > 0
128
+ end
129
+
130
+ def copy_file!(f, target)
131
+ # directory?
132
+ if File.directory?(f)
133
+ if File.directory?(target)
134
+ done = 'exists'.green
135
135
  else
136
- @files[basename] = '__self'
137
- carp "From #{'self'.blue.bold} #{basename.bold}", 'registed'.green.bold
136
+ FileUtils.mkdir_p target
137
+ done = 'created'.bold.green
138
+ end
139
+ else
140
+ if newer?(f, target)
141
+ FileUtils.copy f, target
142
+ done = 'copied'.bold.green
143
+ else
144
+ done = 'keep'.white
138
145
  end
139
146
  end
147
+ done
140
148
  end
141
149
 
142
150
  def carp(job, state = 'done'.green)
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Huang Wei
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-27 00:00:00.000000000 Z
11
+ date: 2013-09-03 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: tilt
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: term-ansicolor
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: simplecov
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -86,11 +77,16 @@ files:
86
77
  - examples/my_app/.app-stack.yml
87
78
  - examples/my_app/Gemfile
88
79
  - examples/my_app/README
80
+ - examples/my_app/app/api_controller.rb
81
+ - examples/my_app/app/config.rb
82
+ - examples/my_app/app/controllers/hello_controller.rb
89
83
  - examples/my_app/config/app.config.rb
90
84
  - examples/my_app/config/configuration.yml
85
+ - examples/my_app/fileabc.rb
91
86
  - examples/stack-apps/auth-app/Gemfile
92
87
  - examples/stack-apps/auth-app/Gemfile.line_addon
93
88
  - examples/stack-apps/auth-app/README
89
+ - examples/stack-apps/auth-app/app/config.rb.erb
94
90
  - examples/stack-apps/auth-app/config/app.config.rb
95
91
  - examples/stack-apps/auth-app/config/configuration.yml
96
92
  - examples/stack-apps/auth-app/config/configuration.yml.template.erb
@@ -102,27 +98,26 @@ files:
102
98
  homepage: https://github.com/7lime/app-stack-gem
103
99
  licenses:
104
100
  - MIT
101
+ metadata: {}
105
102
  post_install_message:
106
103
  rdoc_options: []
107
104
  require_paths:
108
105
  - lib
109
106
  required_ruby_version: !ruby/object:Gem::Requirement
110
- none: false
111
107
  requirements:
112
108
  - - ! '>='
113
109
  - !ruby/object:Gem::Version
114
110
  version: '0'
115
111
  required_rubygems_version: !ruby/object:Gem::Requirement
116
- none: false
117
112
  requirements:
118
113
  - - ! '>='
119
114
  - !ruby/object:Gem::Version
120
115
  version: '0'
121
116
  requirements: []
122
117
  rubyforge_project:
123
- rubygems_version: 1.8.23
118
+ rubygems_version: 2.0.6
124
119
  signing_key:
125
- specification_version: 3
120
+ specification_version: 4
126
121
  summary: Use as a rake task, define a stack of modules and app-stack will merge files
127
122
  from those stack-apps to the local application directory.
128
123
  test_files: []