bonethug 0.0.7 → 0.0.10

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 CHANGED
@@ -1,10 +1,36 @@
1
+ require 'rbconfig'
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in bonethug.gemspec
4
6
  gemspec
5
7
 
6
8
  # tell bundler to get stuff from git hub
7
- gem 'mina', github: 'nadarei/mina'
8
- gem 'astrails-safe', github: 'astrails/safe'
9
- gem 'whenever', github: 'javan/whenever'
10
- gem 'sprockets', github: 'sstephenson/sprockets'
9
+ gem 'mina', github: 'nadarei/mina'
10
+ gem 'astrails-safe', github: 'astrails/safe'
11
+ gem 'whenever', github: 'javan/whenever'
12
+
13
+ # gem 'sass', github: 'nex3/sass'
14
+ # gem 'coffee-script', github: 'jashkenas/coffee-script'
15
+
16
+ gem 'guard-sprockets', github: 'dormi/guard-sprockets'
17
+ gem 'uglifier'
18
+
19
+ # gem 'less'
20
+ # gem 'sass-rails'
21
+ # gem 'execjs'
22
+
23
+ if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
24
+ gem 'wdm', '>= 0.1.0'
25
+ end
26
+
27
+ # if RUBY_PLATFORM.downcase.include?('linux')
28
+ # gem 'therubyracer'
29
+ # gem 'rb-inotify'
30
+ # end
31
+
32
+ # if RUBY_PLATFORM.downcase.include?('darwin')
33
+ # gem 'rb-fsevent'
34
+ # gem 'terminal-notifier-guard'
35
+ # gem 'growl'
36
+ # end
data/bonethug.gemspec CHANGED
@@ -2,6 +2,8 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'bonethug/version'
5
+ require 'rbconfig'
6
+
5
7
 
6
8
  Gem::Specification.new do |spec|
7
9
 
@@ -25,6 +27,12 @@ Gem::Specification.new do |spec|
25
27
  spec.add_dependency 'mina'
26
28
  spec.add_dependency 'astrails-safe'
27
29
  spec.add_dependency 'whenever'
28
- spec.add_dependency 'sprockets'
30
+ # spec.add_dependency 'sass'
31
+ # spec.add_dependency 'coffee-script'
32
+ spec.add_dependency 'guard-sprockets'
33
+
34
+ if RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i
35
+ spec.add_dependency 'wdm', '>= 0.1.0'
36
+ end
29
37
 
30
38
  end
@@ -2,6 +2,12 @@
2
2
  # bundle exec astrails-safe CONFIG_FILE
3
3
  # more info: https://github.com/astrails/safe
4
4
 
5
+ # require some shit
6
+ # --------------------------------
7
+
8
+ require 'rubygems'
9
+ require 'bonethug/conf'
10
+
5
11
  # Load some data
6
12
  # --------------------------------
7
13
 
@@ -10,8 +16,7 @@ exec_path = File.expand_path(File.dirname(__FILE__))
10
16
  env = ENV['to']
11
17
 
12
18
  # load config
13
- require exec_path + '/lib/conf'
14
- conf = Conf.new.add(exec_path + '/config/cnf.yml').add(exec_path + '/config/database.yml' => { root: 'dbs.default' })
19
+ conf = Bonethug::Conf.new.add(exec_path + '/config/cnf.yml').add(exec_path + '/config/database.yml' => { root: 'dbs.default' })
15
20
 
16
21
  # do a check
17
22
  raise 'could not find deployment environment' unless conf.get('deploy.environments').has_key? env
@@ -119,5 +119,16 @@ chgrp:
119
119
  resources:
120
120
  - public/assets
121
121
  - public/uploads
122
+ watch:
123
+ sass:
124
+ -
125
+ src: public/assets/scss
126
+ dest: public/assets/css
127
+ filter:
128
+ coffee:
129
+ -
130
+ src: public/assets/coffee
131
+ dest: public/assets/js
132
+ filter:
122
133
  log_dirs:
123
134
  - log
@@ -6,8 +6,8 @@
6
6
 
7
7
  # Requires
8
8
  # ---------------------------------------------------------------
9
-
10
- require File.join(File.dirname(__FILE__), '..', 'lib', 'conf')
9
+ require 'rubygems'
10
+ require 'bonethug/conf'
11
11
  require 'mina/bundler'
12
12
  require 'mina/rails'
13
13
  require 'mina/git'
@@ -18,7 +18,7 @@ require 'mina/whenever'
18
18
  # ---------------------------------------------------------------
19
19
 
20
20
  # load the conf
21
- conf = Conf.new
21
+ conf = Bonethug::Conf.new
22
22
  cnf = conf.to_hash
23
23
 
24
24
  # pull config from environment vars
@@ -111,6 +111,11 @@ task :init_db => :environment do
111
111
  queue! %[cd #{deploy_to}/current && bundle exec rake db:reset RAILS_ENV="#{env}"] if deploy.get('project_type') == 'rails'
112
112
  end
113
113
 
114
+ desc "Restores application state to the most recent backup"
115
+ task :backup => :environment do
116
+ queue! %[cd #{deploy_to}/current && export to=#{env} && bundle exec astrails-safe .bonethug/backup.rb] if deploy.get('project_type') == 'rails'
117
+ end
118
+
114
119
  desc "Restores application state to the most recent backup"
115
120
  task :restore_backup => :environment do
116
121
  # to be implemented
@@ -194,6 +199,14 @@ task :deploy => :environment do
194
199
 
195
200
  to :launch do
196
201
 
202
+ if ['rails3'].include? deploy.get('project_type')
203
+
204
+ # make sure passenger runs the app as apache
205
+ queue! %[cd #{deploy_to}/current/config && chown -R www-data:www-data environment.rb]
206
+ queue! %[cd #{deploy_to}/current && chown -R www-data:www-data config.ru]
207
+
208
+ end
209
+
197
210
  # ensure that the correct directory permissions are set
198
211
  queue! %[cd #{deploy_to}/current/public && chown -R www-data:www-data . && chmod -R 775 .]
199
212
  queue! %[cd #{deploy_to}/shared/tmp && chown -R www-data:www-data . && chmod -R 775 .]
@@ -30,5 +30,5 @@ set :output, {:error => base_path+'/log/cron_error.log', :standard => base_path+
30
30
 
31
31
  # actual jobs
32
32
  every 1.day, :at => '11 pm' do
33
- command "cd #{base_path} && export to=#{@environment} && bundle exec astrails-safe config/backup.rb"
33
+ command "cd #{base_path} && export to=#{@environment} && bundle exec astrails-safe .bonethug/backup.rb"
34
34
  end
data/lib/bonethug/cli.rb CHANGED
@@ -17,10 +17,60 @@ module Bonethug
17
17
  # handle args
18
18
  type = ARGV[1]
19
19
  location = ARGV[2] || '.'
20
- puts 'Usage: bonethug install [location]' if type.empty?
20
+
21
+ # validate
22
+ if type.empty?
23
+ puts 'Usage: bonethug install [type] [location]'
24
+ return
25
+ end
26
+
27
+ # run the installer
28
+ Installer.install type, location
29
+
30
+ when 'init', 'update'
31
+
32
+ # handle args
33
+ location = ARGV[1] || '.'
34
+
35
+ # validate
36
+ if location.empty?
37
+ puts 'Usage: bonethug #{task} [location]'
38
+ return
39
+ end
40
+
41
+ # run the initaliser
42
+ Installer.bonethugise(location, task.to_sym)
43
+
44
+ when 'deploy', 'setup', 'remote-backup', 'local-backup'
45
+
46
+ # handle args
47
+ environment = ARGV[1]
48
+
49
+ # validate
50
+ if environment.empty?
51
+ puts 'Usage: bonethug #{task} [environment]'
52
+ return
53
+ end
54
+
55
+ case task
56
+ when 'deploy'
57
+ exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb deploy --verbose"
58
+ when 'setup'
59
+ exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb setup --verbose"
60
+ when 'remote-backup'
61
+ exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb backup --verbose"
62
+ when 'local-backup'
63
+ exec "export to=#{environment} && bundle exec astrails-safe .bonethug/backup.rb"
64
+ end
65
+
66
+ when 'watch'
67
+
68
+ # handle args
69
+ type = ARGV[1] || 'all'
70
+ location = ARGV[2] || '.'
21
71
 
22
72
  # run the installer
23
- Installer.install type, location
73
+ Watcher.watch type, location
24
74
 
25
75
  when 'clean'
26
76
 
@@ -0,0 +1,280 @@
1
+ require 'yaml'
2
+
3
+ module Bonethug
4
+
5
+ class Conf
6
+
7
+ @@default_paths = {
8
+ File.expand_path('./config/cnf.yml') => nil,
9
+ File.expand_path('./config/database.yml') => {root: 'dbs.default'}
10
+ }
11
+ @@fallbacks = {
12
+ 'name' => 'database',
13
+ 'user' => 'username',
14
+ 'pass' => 'password'
15
+ }
16
+
17
+ def initialize(new_hash = nil, options = {})
18
+ raise "New hash must be of type Hash" if new_hash && new_hash.class.name != 'Hash'
19
+ @options = {use_fallbacks: true}.merge options
20
+ @loaded_paths = []
21
+ @paths = {}
22
+ @config_hashes = {}
23
+ @compiled_hash = new_hash ? new_hash : {}
24
+ end
25
+
26
+ def add_path(new_path)
27
+ if new_path.class.name == 'Hash'
28
+ path_hash = new_path
29
+ elsif new_path.class.name == 'String'
30
+ path_hash = {new_path => nil}
31
+ else
32
+ raise "add_path only accepts stings or hashes"
33
+ end
34
+ @paths = @paths.merge path_hash
35
+ self
36
+ end
37
+
38
+ def remove_path(path_to_remove)
39
+ # deletes an element from a hash if its key can be found
40
+ @paths.delete path_to_remove
41
+ self
42
+ end
43
+
44
+ def compile_configuration
45
+
46
+ # load the defaults if we haven't loaded anything
47
+ use_defaults if @paths.empty?
48
+
49
+ # generate output
50
+ out = {}
51
+ @paths.each do |path,options|
52
+
53
+ # load the file if we haven't already
54
+ load_path path unless @loaded_paths.include? path
55
+
56
+ # create a base fragment
57
+ fragment_base = {}
58
+
59
+ # create the other nodes
60
+ if options and options.has_key? :root
61
+ fragment = fragment_base
62
+ nodes = options[:root].split '.'
63
+ nodes.each_with_index do |node,i|
64
+ fragment[node] = i == nodes.length-1 ? @config_hashes[path] : {}
65
+ fragment = fragment[node]
66
+ end
67
+ else
68
+ fragment_base = @config_hashes[path]
69
+ end
70
+
71
+ # output
72
+ out = out.merge fragment_base
73
+
74
+ end
75
+ @compiled_hash = out
76
+ self
77
+
78
+ end
79
+
80
+ def all_paths_loaded?
81
+ @paths.each do |path,options|
82
+ return false unless @loaded_paths.include? path
83
+ end
84
+ true
85
+ end
86
+
87
+ def path_ok?(path)
88
+ path && path.class.name == 'String' and File.exist?(path) and File.file?(path)
89
+ end
90
+
91
+ def check_path!(path)
92
+ raise 'config file "' + path.to_s + '" does not exist' unless path_ok? path
93
+ end
94
+
95
+ def check_paths!
96
+ raise 'No config files have not been set' if @paths.empty?
97
+ @paths.each do |path,options|
98
+ check_path! path
99
+ end
100
+ self
101
+ end
102
+
103
+ def check_paths
104
+ @paths.each do |path,options|
105
+ @paths.delete path unless path_ok? path
106
+ end
107
+ self
108
+ end
109
+
110
+ def load_paths
111
+ @paths.each do |path,options|
112
+ load_path path
113
+ end
114
+ self
115
+ end
116
+
117
+ def load_path(path)
118
+ load_path? path
119
+ self
120
+ end
121
+
122
+ def load_path?(path)
123
+ return false unless path_ok? path
124
+ @loaded_paths.push path
125
+ @config_hashes[path] = YAML.load_file path
126
+ self
127
+ end
128
+
129
+ def use_defaults
130
+ @paths = @@default_paths if @paths.empty?
131
+ load_paths
132
+ self
133
+ end
134
+
135
+ def get(node = nil, force_type = nil)
136
+ node_val = node ? get_compiled_hash_node_handle(node) : self
137
+ case force_type
138
+ when 'Array'
139
+ return [] unless node_val
140
+ return [node_val] if node_val.class.name == 'String'
141
+ return node_val.class.name == 'Array' ? node_val.clone : node_val.to_a
142
+ when 'Hash'
143
+ return {} unless node_val
144
+ if node_val.class.name == 'Array'
145
+ return array2hash node_val
146
+ elsif node_val.class.name == 'Hash'
147
+ return node_val.clone
148
+ else
149
+ return node_val.to_hash
150
+ end
151
+ else
152
+ return handle_node_value node_val
153
+ end
154
+ end
155
+
156
+ def has_key?(key)
157
+ compiled_hash.has_key? key
158
+ end
159
+
160
+ def get_compiled_hash_node_handle(node = nil)
161
+ if node
162
+ nodes = node.split('.')
163
+ current = compiled_hash
164
+ nodes.each do |node|
165
+ node = @@fallbacks[node] if @options[:use_fallbacks] and !current[node] and @@fallbacks[node]
166
+ current = (current.class.name == 'Hash' or current.class.name == 'Array') ? current[node] : nil
167
+ end
168
+ return current
169
+ else
170
+ return self.compiled_hash
171
+ end
172
+ end
173
+
174
+ def handle_node_value(node)
175
+ return node if node.class.name == 'Conf'
176
+ node = array2hash node if node.class.name == 'Array'
177
+ return node.class.name == 'Hash' ? self.clone.set_compiled_hash(node) : node
178
+ end
179
+
180
+ def array2hash(arr)
181
+ return arr if arr.class.name == 'Hash'
182
+ hsh = {}
183
+ arr.each_with_index do |item,i|
184
+ hsh[i] = item
185
+ end
186
+ hsh
187
+ end
188
+
189
+ def get_hash(node = nil)
190
+ get(node).compiled_hash
191
+ end
192
+
193
+ def to_hash
194
+ compiled_hash.clone
195
+ end
196
+
197
+ def to_a
198
+ to_hash.to_a
199
+ end
200
+
201
+ def node_merge!(node1,node2)
202
+ cnf1 = get_compiled_hash_node_handle node1
203
+ cnf2 = get_compiled_hash_node_handle node2
204
+ cnf1.merge!(cnf2) if cnf1 && cnf2
205
+ return self
206
+ end
207
+
208
+ def node_merge(node1,node2)
209
+ cnf1 = get_compiled_hash_node_handle node1
210
+ cnf2 = get_compiled_hash_node_handle node2
211
+ return handle_node_value cnf1 if cnf1 && !cnf2
212
+ return handle_node_value cnf1 if cnf2 && !cnf1
213
+ return handle_node_value cnf1.merge(cnf2) if cnf1 && cnf2
214
+ end
215
+
216
+ def merge(node)
217
+ return self unless node
218
+ return handle_node_value compiled_hash.merge(node.to_hash)
219
+ end
220
+
221
+ def each
222
+ compiled_hash.each do |k,v|
223
+ yield k,handle_node_value(v)
224
+ end
225
+ end
226
+
227
+ # Getters and Setters
228
+ # -------------------
229
+
230
+ def paths=(new_paths)
231
+ raise "paths must be a hash" unless new_hash.class.name == 'Hash'
232
+ @paths = new_paths
233
+ end
234
+
235
+ def paths
236
+ @paths
237
+ end
238
+
239
+ def config_hashes
240
+ @config_hashes
241
+ end
242
+
243
+ def compiled_hash
244
+ compile_configuration if @compiled_hash.empty?
245
+ @compiled_hash
246
+ end
247
+
248
+ def compiled_hash=(new_hash)
249
+ raise "compiled hash must be a hash" unless new_hash.class.name == 'Hash'
250
+ @compiled_hash = new_hash
251
+ end
252
+
253
+ def set_compiled_hash(new_hash)
254
+ raise "compiled hash must be a hash" unless new_hash.class.name == 'Hash'
255
+ @compiled_hash = new_hash
256
+ self
257
+ end
258
+
259
+ # Method Aliases
260
+ # --------------
261
+
262
+ def a2h(arr)
263
+ array2hash arr
264
+ end
265
+
266
+ def to_hash
267
+ compiled_hash
268
+ end
269
+
270
+ def add(new_path)
271
+ add_path new_path
272
+ end
273
+
274
+ def remove(path_to_remove)
275
+ remove_path path_to_remove
276
+ end
277
+
278
+ end
279
+
280
+ end
@@ -2,9 +2,11 @@
2
2
  # ----------------
3
3
  # - Have some sort of safe vs forced install - tie in with exlcuded paths
4
4
  # - Check that excluded paths is working in manifest
5
+ # - Gemfile, .gitignore, composer.json need to be no go zones
5
6
  # ----------------
6
7
 
7
- require File.expand_path(File.dirname(__FILE__)) + '/../../skel/base/lib/conf'
8
+ require 'rubygems'
9
+ require 'bonethug/conf'
8
10
  require 'fileutils'
9
11
  require 'find'
10
12
  require 'digest/md5'
@@ -17,9 +19,10 @@ module Bonethug
17
19
  include FileUtils
18
20
  include Digest
19
21
 
20
- @@skel_dir = File.expand_path(File.dirname(__FILE__)) + '/../../skel'
22
+ @@bonthug_gem_dir = File.expand_path(File.dirname(__FILE__)) + '/../..'
23
+ @@skel_dir = @@bonthug_gem_dir + '/skel'
21
24
  @@conf = Conf.new.add(@@skel_dir + '/skel.yml')
22
- @@project_config_files = ['backup.rb','cnf.yml','deploy.rb','schedule.rb']
25
+ @@project_config_files = {editable: ['cnf.yml','schedule.rb'], generated: ['backup.rb','deploy.rb']}
23
26
 
24
27
  def self.install(type, target = '.')
25
28
 
@@ -72,20 +75,20 @@ module Bonethug
72
75
  puts 'Installing build to ' + target + '...'
73
76
  FileUtils.cp_r tmp_dir + '/.', target
74
77
 
75
- # try to update the configuration files
76
- puts 'Updating configs...'
77
- self.update_configuration_files(target)
78
-
79
78
  # try to update the configuration files
80
79
  puts 'Updating build informtation...'
81
80
  self.save_project_meta_data(target)
82
81
 
83
82
  # clean up any exisitng install tmp files
84
83
  puts 'Cleaning up temporary files...'
85
- FileUtils.rm_rf tmp_dir
84
+ FileUtils.rm_rf tmp_dir
86
85
 
87
86
  puts "Installation Complete"
88
87
 
88
+ # try to update the configuration files
89
+ puts 'Updating configs...'
90
+ self.bonethugise(target, :init)
91
+
89
92
  end
90
93
 
91
94
  def self.clean(target)
@@ -136,48 +139,11 @@ module Bonethug
136
139
 
137
140
  def self.build_manifest(dir)
138
141
  dir_contents = Find.find(dir).map { |p| File.expand_path(p) }
139
- manifest = dir_contents - ((@@conf.get('exlcuded_paths') || []).map { |p| File.expand_path(p) })
142
+ manifest = dir_contents - ((@@conf.get('exlcuded_paths','Array') || []).map { |p| File.expand_path(p) })
140
143
  File.open(dir + '/.bonethug/manifest','w') { |file| file.puts manifest.join("\n") }
141
144
  self
142
145
  end
143
146
 
144
- def self.update_configuration_files(target)
145
-
146
- # load the existing project's datafile if present
147
- meta_data = self.get_project_meta_data target
148
-
149
- @@project_config_files.each do |config|
150
-
151
- do_copy = true
152
- example_file = target + '/config/example/' + config
153
- target_file = target + '/config/' + config
154
-
155
- # analyse the config file + build data file
156
- file_exists = File.exist?(target_file)
157
- contents_not_modified = false
158
- contents_not_modified = true if file_exists and meta_data and meta_data['config_digests'] and meta_data['config_digests']['example/' + config] == self.contents_md5(target_file)
159
-
160
- # meta_data_is_hash = meta_data_exists and meta_data.class.name == 'Hash' and meta_data['config_digests'].class.name == 'Hash'
161
- # config_digests_found = meta_data_is_hash and meta_data['config_digests'].methods.include?('has_key?') and meta_data['config_digests'].has_key?('example/' + config)
162
- # contents_not_modified = config_digests_found and meta_data['config_digests']['example/' + config] == self.contents_md5(target_file)
163
-
164
- # don't copy if the file exists...
165
- do_copy = false if file_exists
166
-
167
- # unless it hasn't been modified, i.e. probably not conf.yml, but possibly some of the other ones
168
-
169
- do_copy = true if contents_not_modified
170
-
171
- # Copy if that's ok
172
- FileUtils.cp example_file, target_file if do_copy
173
-
174
- end
175
-
176
- # return self for chaining
177
- self
178
-
179
- end
180
-
181
147
  def self.contents_md5(file)
182
148
  return false unless File.exist?(file)
183
149
  MD5.digest File.read(file)
@@ -186,7 +152,7 @@ module Bonethug
186
152
  def self.save_project_meta_data(base_dir)
187
153
 
188
154
  meta_data = {'config_digests' => {}}
189
- @@project_config_files.each do |file|
155
+ @@project_config_files[:editable].each do |file|
190
156
  meta_data['config_digests']['example/' + file] = self.contents_md5(base_dir + '/config/example/' + file)
191
157
  end
192
158
  File.open(base_dir + '/.bonethug/data','w') { |file| file.puts meta_data.to_yaml }
@@ -202,7 +168,78 @@ module Bonethug
202
168
  return YAML.load_file data_file if File.exists? data_file
203
169
  return false
204
170
 
205
- end
171
+ end
172
+
173
+ # mode == :init
174
+ # copy cnf.yml + schedule.rb to config if possible
175
+ # copy cnf.yml + schedule.rb to config/example if possible
176
+ # copy backup.rb and deploy.rb to .bonethug if possible
177
+ # add bonethug to gemfile if required
178
+ # run bundle install
179
+
180
+ # mode == :update
181
+ # copy cnf.yml + schedule.rb to config if possible
182
+ # force copy cnf.yml + schedule.rb to config/example
183
+ # force copy backup.rb and deploy.rb to .bonethug
184
+ # add bonethug to gemfile if required
185
+ # run bundle install
186
+
187
+ def self.bonethugise(dir='.', mode=:init)
188
+
189
+ target = File.expand_path(dir)
190
+
191
+ # check for the existence of required dirs and create if required
192
+ [target + '/.bonethug', target + '/config', target + '/config/example'].each do |path|
193
+ FileUtils.mkdir path unless File.directory? path
194
+ end
195
+
196
+ # Handle config files
197
+ @@project_config_files.each do |type, dirs|
198
+ dirs.each do |config|
199
+
200
+ src_file = @@bonthug_gem_dir + '/config/' + config
201
+ example_file = target + '/config/example/' + config if type == :editable
202
+ target_file = type == :editable ? target + '/config/' + config : target + '/.bonethug/' + config
203
+
204
+ if mode == :init
205
+ FileUtils.cp src_file, example_file if type == :editable and !File.exist?(example_file)
206
+ FileUtils.cp src_file, target_file unless File.exist?(target_file)
207
+ elsif mode == :update
208
+ FileUtils.cp src_file, example_file if type == :editable
209
+ FileUtils.cp src_file, target_file if type == :generated or !File.exist?(target_file)
210
+ else
211
+ raise "invalid bonethugise mode"
212
+ end
213
+
214
+ end
215
+ end
216
+
217
+ # handle gemfile
218
+ gemfile_path = target + '/Gemfile'
219
+ if File.exist? gemfile_path
220
+ gemfile_contents = File.read(gemfile_path)
221
+ unless /gem ["']bonethug["']/ =~ File.read(gemfile_path)
222
+ File.open(gemfile_path,'w') { |file| gemfile_contents + "\n" + 'gem "bonethug"' }
223
+ end
224
+ else
225
+ FileUtils.cp @@skel_dir + '/base/Gemfile', gemfile_path
226
+ end
227
+
228
+ # run bundler
229
+ exec 'bundle install --path vendor --binstubs'
230
+
231
+ # self
232
+
233
+ end
234
+
235
+ def self.update(dir = '.')
236
+ self.bonethugise(dir,:update)
237
+ end
238
+
239
+ def self.init(dir = '.')
240
+ self.bonethugise(dir,:init)
241
+ end
242
+
206
243
  end
207
244
 
208
245
  end
@@ -1,3 +1,3 @@
1
1
  module Bonethug
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1,121 @@
1
+ # Todo
2
+ # ----------------
3
+ # - Have some sort of safe vs forced install - tie in with exlcuded paths
4
+ # - Check that excluded paths is working in manifest
5
+ # ----------------
6
+
7
+ require 'bonethug/conf'
8
+ require 'fileutils'
9
+ require 'find'
10
+ require 'digest/md5'
11
+ require 'yaml'
12
+
13
+ module Bonethug
14
+
15
+ class Watcher
16
+
17
+ include FileUtils
18
+ include Digest
19
+
20
+ def self.watch(type = 'all', target = '.')
21
+
22
+ # create full path
23
+ target = File.expand_path target
24
+
25
+ # load config
26
+ puts "Parsing Config..."
27
+ unless conf = Conf.new.add(target + '/config/cnf.yml')
28
+ puts "Couldn't find project configuration"
29
+ return
30
+ end
31
+
32
+ # project type
33
+ project_type = conf.get('deploy.project_type')
34
+
35
+ # end now if its a rails project
36
+ if ['rails','rails3'].include? project_type
37
+ puts "Rails doesn't require watching"
38
+ return
39
+ end
40
+
41
+ sass = []
42
+ if sasses = conf.get('watch.sass')
43
+ sasses.each do |index, watch|
44
+ sass.push(src: watch.get('src','Array'), dest: watch.get('dest'))
45
+ end
46
+ end
47
+
48
+ coffee = []
49
+ if coffees = conf.get('watch.coffee')
50
+ coffees.each do |index, watch|
51
+ coffee.push(src: watch.get('src','Array'), dest: watch.get('dest'))
52
+ end
53
+ end
54
+
55
+ # Generate Guardfile
56
+ puts 'Generating Guardfile...'
57
+ guardfile_content = ''
58
+
59
+ # puts 'Starting Watch Daemons...'
60
+ # puts 'This may start more than one watch process and you may have to ctrl + c more than once to quit.'
61
+
62
+ # sass compiler
63
+ sass_watch_str = ''
64
+ sass.each do |watch|
65
+ filter = watch[:filter] ? "watch '#{watch[:filter]}'" : ""
66
+ guardfile_content += "
67
+ guard 'sprockets', :minify => true, :destination => '#{watch[:dest]}', :asset_paths => #{watch[:src].to_s} do
68
+ #{filter}
69
+ end
70
+ "
71
+ end
72
+
73
+ # # Coffescript compiler
74
+ coffee_watch_str = ''
75
+ coffee.each do |watch|
76
+ filter = watch[:filter] ? "watch '#{watch[:filter]}'" : ""
77
+ guardfile_content += "
78
+ guard 'sprockets', :minify => true, :destination => '#{watch[:dest]}', :asset_paths => #{watch[:src].to_s} do
79
+ #{filter}
80
+ end
81
+ "
82
+ end
83
+
84
+ # save the guardfile
85
+ File.open(target + '/.bonethug/Guardfile','w') do |file|
86
+ file.puts guardfile_content
87
+ end
88
+
89
+ puts 'Starting Watch Daemon...'
90
+ cmd = 'bundle exec guard --guardfile ' + target + '/.bonethug/Guardfile'
91
+ puts "calling: " + cmd
92
+ exec cmd
93
+
94
+ # puts 'Starting Watch Daemons...'
95
+ # puts 'This may start more than one watch process and you may have to ctrl + c more than once to quit.'
96
+
97
+ # # sass compiler
98
+ # sass_watch_str = ''
99
+ # sass.each do |watch|
100
+ # sass_watch_str += ' '+watch[:src]+':'+watch[:dest]
101
+ # end
102
+ # sass_cmd = "sass --watch #{sass_watch_str} --style compressed"
103
+
104
+ # # Coffescript compiler
105
+ # coffee_watch_str = ''
106
+ # coffee.each do |watch|
107
+ # coffee_watch_str += ' && coffee -o '+watch[:dest]+'/ -cw '+watch[:src]+'/'
108
+ # end
109
+ # coffee_cmd = coffee_watch_str
110
+
111
+ # # call it
112
+ # cmd = "#{sass_cmd} #{coffee_cmd}"
113
+ # puts "Running: " + cmd
114
+
115
+ # log = `#{cmd}`
116
+
117
+ end
118
+
119
+ end
120
+
121
+ end
data/lib/bonethug.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "bonethug/version"
2
2
  require "bonethug/installer"
3
+ require "bonethug/watcher"
3
4
  require "bonethug/cli"
4
5
 
5
6
  module Bonethug
File without changes
File without changes
@@ -8,8 +8,7 @@
8
8
  "silverstripe/installer" : "3.1.*@dev",
9
9
  "silverstripe/bootstrap-forms" : "dev-master",
10
10
  "silverstripe/html5" : "dev-master",
11
- "silverstripe/widgets" : "dev-master",
12
- "silverstripe/compass" : "dev-master"
11
+ "silverstripe/widgets" : "dev-master"
13
12
  },
14
13
  "extra": {
15
14
  "installer-paths": {
@@ -17,14 +16,16 @@
17
16
  ],
18
17
  "public/themes/{$name}": [
19
18
  "silverstripe-themes/simple"
20
- ],
19
+ ],
20
+ "public": [
21
+ "silverstripe/installer"
22
+ ],
21
23
  "public/{$name}": [
22
24
  "silverstripe/framework",
23
25
  "silverstripe/cms",
24
26
  "silverstripe/bootstrap-forms",
25
27
  "silverstripe/html5",
26
28
  "silverstripe/widgets",
27
- "silverstripe/compass"
28
29
  ]
29
30
  }
30
31
  }
@@ -33,26 +33,26 @@ every 1.day, :at => '11 pm' do
33
33
  command "cd #{base_path} && export to=#{@environment} && bundle exec astrails-safe config/backup.rb"
34
34
  end
35
35
 
36
- every 15.minutes do
37
- command "php #{base_path}/public/framework/cli-script.php /QuarterlyHourlyTask"
38
- end
36
+ # every 15.minutes do
37
+ # command "php #{base_path}/public/framework/cli-script.php /QuarterlyHourlyTask"
38
+ # end
39
39
 
40
- every 1.hour do
41
- command "php #{base_path}/public/framework/cli-script.php /HourlyTask"
42
- end
40
+ # every 1.hour do
41
+ # command "php #{base_path}/public/framework/cli-script.php /HourlyTask"
42
+ # end
43
43
 
44
- every 1.day :at => '2am'.minutes do
45
- command "php #{base_path}/public/framework/cli-script.php /DailyTask"
46
- end
44
+ # every 1.day :at => '2am'.minutes do
45
+ # command "php #{base_path}/public/framework/cli-script.php /DailyTask"
46
+ # end
47
47
 
48
- every 1.week do
49
- command "php #{base_path}/public/framework/cli-script.php /WeeklyTask"
50
- end
48
+ # every 1.week do
49
+ # command "php #{base_path}/public/framework/cli-script.php /WeeklyTask"
50
+ # end
51
51
 
52
- every 1.month do
53
- command "php #{base_path}/public/framework/cli-script.php /MonthlyTask"
54
- end
52
+ # every 1.month do
53
+ # command "php #{base_path}/public/framework/cli-script.php /MonthlyTask"
54
+ # end
55
55
 
56
- every 1.year do
57
- command "php #{base_path}/public/framework/cli-script.php YearlyTask"
58
- end
56
+ # every 1.year do
57
+ # command "php #{base_path}/public/framework/cli-script.php YearlyTask"
58
+ # end
@@ -36,7 +36,7 @@ $mail = (object) $cnf['mail']['smtp'][APPLICATION_ENV];
36
36
 
37
37
  // file to url
38
38
  $base_dir = __DIR__ . '/..';
39
- $url = $cnf['apache'][APPLICATION_ENV]['server_name'];
39
+ $url = 'http://'.$cnf['apache'][APPLICATION_ENV]['server_name'];
40
40
  $_FILE_TO_URL_MAPPING[$base_dir] = $url;
41
41
 
42
42
  // Env specific settings
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bonethug
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: sprockets
95
+ name: guard-sprockets
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -107,6 +107,22 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: wdm
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: 0.1.0
110
126
  description: Project Skeleton Manager
111
127
  email:
112
128
  - breaks.nz@gmail.com
@@ -123,20 +139,23 @@ files:
123
139
  - Rakefile
124
140
  - bin/bonethug
125
141
  - bonethug.gemspec
142
+ - config/backup.rb
143
+ - config/cnf.yml
144
+ - config/deploy.rb
145
+ - config/schedule.rb
126
146
  - lib/bonethug.rb
127
147
  - lib/bonethug/cli.rb
148
+ - lib/bonethug/conf.rb
128
149
  - lib/bonethug/installer.rb
129
150
  - lib/bonethug/utils.rb
130
151
  - lib/bonethug/version.rb
152
+ - lib/bonethug/watcher.rb
131
153
  - lib/tasks/setup.rake
132
154
  - skel/base/.gitignore
133
155
  - skel/base/Gemfile
134
156
  - skel/base/README.md
135
- - skel/base/config/example/backup.rb
136
- - skel/base/config/example/cnf.yml
137
- - skel/base/config/example/deploy.rb
138
- - skel/base/config/example/schedule.rb
139
- - skel/base/lib/conf.rb
157
+ - skel/base/config/example/.gitkeep
158
+ - skel/base/lib/.gitkeep
140
159
  - skel/base/log/.gitkeep
141
160
  - skel/base/public/apple-touch-icon-114x114-precomposed.png
142
161
  - skel/base/public/apple-touch-icon-72x72-precomposed.png
@@ -154,7 +173,6 @@ files:
154
173
  - skel/project_types/php/composer.json
155
174
  - skel/project_types/silverstripe3/.gitignore
156
175
  - skel/project_types/silverstripe3/composer.json
157
- - skel/project_types/silverstripe3/config.ru
158
176
  - skel/project_types/silverstripe3/config/example/schedule.rb
159
177
  - skel/project_types/silverstripe3/public/.htaccess
160
178
  - skel/project_types/silverstripe3/public/abc/_config.php
@@ -1,275 +0,0 @@
1
- require 'yaml'
2
-
3
- class Conf
4
-
5
- @@default_paths = {
6
- File.expand_path(File.dirname(__FILE__)) + '/../config/cnf.yml' => nil,
7
- File.expand_path(File.dirname(__FILE__)) + '/../config/database.yml' => {root: 'dbs.default'}
8
- }
9
- @@fallbacks = {
10
- 'name' => 'database',
11
- 'user' => 'username',
12
- 'pass' => 'password'
13
- }
14
-
15
- def initialize(new_hash = nil, options = {})
16
- raise "New hash must be of type Hash" if new_hash && new_hash.class.name != 'Hash'
17
- @options = {use_fallbacks: true}.merge options
18
- @loaded_paths = []
19
- @paths = {}
20
- @config_hashes = {}
21
- @compiled_hash = new_hash ? new_hash : {}
22
- end
23
-
24
- def add_path(new_path)
25
- if new_path.class.name == 'Hash'
26
- path_hash = new_path
27
- elsif new_path.class.name == 'String'
28
- path_hash = {new_path => nil}
29
- else
30
- raise "add_path only accepts stings or hashes"
31
- end
32
- @paths = @paths.merge path_hash
33
- self
34
- end
35
-
36
- def remove_path(path_to_remove)
37
- # deletes an element from a hash if its key can be found
38
- @paths.delete path_to_remove
39
- self
40
- end
41
-
42
- def compile_configuration
43
-
44
- # load the defaults if we haven't loaded anything
45
- use_defaults if @paths.empty?
46
-
47
- # generate output
48
- out = {}
49
- @paths.each do |path,options|
50
-
51
- # load the file if we haven't already
52
- load_path path unless @loaded_paths.include? path
53
-
54
- # create a base fragment
55
- fragment_base = {}
56
-
57
- # create the other nodes
58
- if options and options.has_key? :root
59
- fragment = fragment_base
60
- nodes = options[:root].split '.'
61
- nodes.each_with_index do |node,i|
62
- fragment[node] = i == nodes.length-1 ? @config_hashes[path] : {}
63
- fragment = fragment[node]
64
- end
65
- else
66
- fragment_base = @config_hashes[path]
67
- end
68
-
69
- # output
70
- out = out.merge fragment_base
71
-
72
- end
73
- @compiled_hash = out
74
- self
75
-
76
- end
77
-
78
- def all_paths_loaded?
79
- @paths.each do |path,options|
80
- return false unless @loaded_paths.include? path
81
- end
82
- true
83
- end
84
-
85
- def path_ok?(path)
86
- path && path.class.name == 'String' and File.exist?(path) and File.file?(path)
87
- end
88
-
89
- def check_path!(path)
90
- raise 'config file "' + path.to_s + '" does not exist' unless path_ok? path
91
- end
92
-
93
- def check_paths!
94
- raise 'No config files have not been set' if @paths.empty?
95
- @paths.each do |path,options|
96
- check_path! path
97
- end
98
- self
99
- end
100
-
101
- def check_paths
102
- @paths.each do |path,options|
103
- @paths.delete path unless path_ok? path
104
- end
105
- self
106
- end
107
-
108
- def load_paths
109
- @paths.each do |path,options|
110
- load_path path
111
- end
112
- self
113
- end
114
-
115
- def load_path(path)
116
- load_path? path
117
- self
118
- end
119
-
120
- def load_path?(path)
121
- return false unless path_ok? path
122
- @loaded_paths.push path
123
- @config_hashes[path] = YAML.load_file path
124
- self
125
- end
126
-
127
- def use_defaults
128
- @paths = @@default_paths if @paths.empty?
129
- load_paths
130
- self
131
- end
132
-
133
- def get(node = nil, force_type = nil)
134
- node_val = node ? get_compiled_hash_node_handle(node) : self
135
- case force_type
136
- when 'Array'
137
- return [] unless node_val
138
- return node_val.class.name == 'Array' ? node_val.clone : node_val.to_a
139
- when 'Hash'
140
- return {} unless node_val
141
- if node_val.class.name == 'Array'
142
- return array2hash node_val
143
- elsif node_val.class.name == 'Hash'
144
- return node_val.clone
145
- else
146
- return node_val.to_hash
147
- end
148
- else
149
- return handle_node_value node_val
150
- end
151
- end
152
-
153
- def has_key?(key)
154
- compiled_hash.has_key? key
155
- end
156
-
157
- def get_compiled_hash_node_handle(node = nil)
158
- if node
159
- nodes = node.split('.')
160
- current = compiled_hash
161
- nodes.each do |node|
162
- node = @@fallbacks[node] if @options[:use_fallbacks] and !current[node] and @@fallbacks[node]
163
- current = (current.class.name == 'Hash' or current.class.name == 'Array') ? current[node] : nil
164
- end
165
- return current
166
- else
167
- return self.compiled_hash
168
- end
169
- end
170
-
171
- def handle_node_value(node)
172
- return node if node.class.name == 'Conf'
173
- node = array2hash node if node.class.name == 'Array'
174
- return node.class.name == 'Hash' ? self.clone.set_compiled_hash(node) : node
175
- end
176
-
177
- def array2hash(arr)
178
- return arr if arr.class.name == 'Hash'
179
- hsh = {}
180
- arr.each_with_index do |item,i|
181
- hsh[i] = item
182
- end
183
- hsh
184
- end
185
-
186
- def get_hash(node = nil)
187
- get(node).compiled_hash
188
- end
189
-
190
- def to_hash
191
- compiled_hash.clone
192
- end
193
-
194
- def to_a
195
- to_hash.to_a
196
- end
197
-
198
- def node_merge!(node1,node2)
199
- cnf1 = get_compiled_hash_node_handle node1
200
- cnf2 = get_compiled_hash_node_handle node2
201
- cnf1.merge!(cnf2) if cnf1 && cnf2
202
- return self
203
- end
204
-
205
- def node_merge(node1,node2)
206
- cnf1 = get_compiled_hash_node_handle node1
207
- cnf2 = get_compiled_hash_node_handle node2
208
- return handle_node_value cnf1 if cnf1 && !cnf2
209
- return handle_node_value cnf1 if cnf2 && !cnf1
210
- return handle_node_value cnf1.merge(cnf2) if cnf1 && cnf2
211
- end
212
-
213
- def merge(node)
214
- return self unless node
215
- return handle_node_value compiled_hash.merge(node.to_hash)
216
- end
217
-
218
- def each
219
- compiled_hash.each do |k,v|
220
- yield k,handle_node_value(v)
221
- end
222
- end
223
-
224
- # Getters and Setters
225
- # -------------------
226
-
227
- def paths=(new_paths)
228
- raise "paths must be a hash" unless new_hash.class.name == 'Hash'
229
- @paths = new_paths
230
- end
231
-
232
- def paths
233
- @paths
234
- end
235
-
236
- def config_hashes
237
- @config_hashes
238
- end
239
-
240
- def compiled_hash
241
- compile_configuration if @compiled_hash.empty?
242
- @compiled_hash
243
- end
244
-
245
- def compiled_hash=(new_hash)
246
- raise "compiled hash must be a hash" unless new_hash.class.name == 'Hash'
247
- @compiled_hash = new_hash
248
- end
249
-
250
- def set_compiled_hash(new_hash)
251
- raise "compiled hash must be a hash" unless new_hash.class.name == 'Hash'
252
- @compiled_hash = new_hash
253
- self
254
- end
255
-
256
- # Method Aliases
257
- # --------------
258
-
259
- def a2h(arr)
260
- array2hash arr
261
- end
262
-
263
- def to_hash
264
- compiled_hash
265
- end
266
-
267
- def add(new_path)
268
- add_path new_path
269
- end
270
-
271
- def remove(path_to_remove)
272
- remove_path path_to_remove
273
- end
274
-
275
- end
@@ -1,3 +0,0 @@
1
- environment = Sprockets::Environment.new
2
- environment.append_path 'public/themes/css'
3
- environment.append_path 'public/javascript'