daiku 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -0
  3. data/README.md +31 -6
  4. data/lib/daiku.rb +35 -2
  5. data/lib/daiku/_app/.env.tt +0 -11
  6. data/lib/daiku/_app/.node-version +1 -0
  7. data/lib/daiku/_app/.ruby-version.tt +1 -1
  8. data/lib/daiku/_app/.travis.yml.tt +1 -8
  9. data/lib/daiku/_app/Gemfile.tt +1 -32
  10. data/lib/daiku/_app/Procfile.tt +1 -4
  11. data/lib/daiku/_app/Rakefile.tt +3 -1
  12. data/lib/daiku/_app/config.ru.tt +1 -11
  13. data/lib/daiku/{_templates → _app/config}/pony.rb.tt +0 -0
  14. data/lib/daiku/_app/config/puma.rb +0 -3
  15. data/lib/daiku/_app/lib/boot.rb.tt +1 -7
  16. data/lib/daiku/cli.rb +48 -49
  17. data/lib/daiku/core_ext.rb +36 -0
  18. data/lib/daiku/plugin.rb +26 -0
  19. data/lib/daiku/plugins.rb +38 -0
  20. data/lib/daiku/plugins/database-sql.rb +10 -0
  21. data/lib/daiku/{_templates/db_helper.rb → plugins/database-sql/_templates/db_helper.rb.tt} +0 -0
  22. data/lib/daiku/plugins/database-sql/cli.rb +41 -0
  23. data/lib/daiku/plugins/datamapper.rb +10 -0
  24. data/lib/daiku/{_templates → plugins/datamapper/_templates}/datamapper.rb.tt +0 -0
  25. data/lib/daiku/plugins/datamapper/cli.rb +50 -0
  26. data/lib/daiku/plugins/grunt.rb +10 -0
  27. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/aliases.yaml +0 -0
  28. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/coffee.coffee +0 -0
  29. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/imagemin.coffee +0 -0
  30. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/robotstxt.coffee +0 -0
  31. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/sass.coffee +0 -0
  32. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/slim.coffee +0 -0
  33. data/lib/daiku/{_grunt/.grunt → plugins/grunt/_config}/uglify.coffee +0 -0
  34. data/lib/daiku/{_grunt → plugins/grunt/_templates}/.bowerrc +0 -0
  35. data/lib/daiku/plugins/grunt/_templates/.bowerrc.tt +4 -0
  36. data/lib/daiku/{_grunt → plugins/grunt/_templates}/Gruntfile.coffee +0 -0
  37. data/lib/daiku/{_grunt → plugins/grunt/_templates}/bower.json.tt +0 -0
  38. data/lib/daiku/{_grunt → plugins/grunt/_templates}/package.json.tt +0 -0
  39. data/lib/daiku/plugins/grunt/cli.rb +26 -0
  40. data/lib/daiku/plugins/honeybadger.rb +10 -0
  41. data/lib/daiku/{_app/config/honeybadger.rb → plugins/honeybadger/_templates/honeybadger.rb.tt} +0 -0
  42. data/lib/daiku/plugins/honeybadger/cli.rb +43 -0
  43. data/lib/daiku/plugins/newrelic.rb +10 -0
  44. data/lib/daiku/plugins/newrelic/cli.rb +22 -0
  45. data/lib/daiku/plugins/sidekiq.rb +10 -0
  46. data/lib/daiku/{_templates → plugins/sidekiq/_templates}/sidekiq.rb.tt +0 -0
  47. data/lib/daiku/plugins/sidekiq/cli.rb +53 -0
  48. data/lib/daiku/plugins/vcr.rb +10 -0
  49. data/lib/daiku/{_templates/vcr_helper.rb → plugins/vcr/_templates/vcr_helper.rb.tt} +0 -0
  50. data/lib/daiku/plugins/vcr/cli.rb +31 -0
  51. data/lib/daiku/version.rb +1 -1
  52. data/spec/daiku/plugins_spec.rb +60 -0
  53. data/spec/spec_helper.rb +16 -0
  54. metadata +43 -21
  55. data/lib/daiku/_templates/bower.json.tt +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e26ebe168ec7594ccbb883882da0efb623e9930
4
- data.tar.gz: 6164405c5eff7d1592e8575ced8988c10823d791
3
+ metadata.gz: 3e8b05bc97a7765ef02bad3f80967d180967e14d
4
+ data.tar.gz: 286c391924557281a930f595163eb5d9239f8e39
5
5
  SHA512:
6
- metadata.gz: bdb012bb7fcc62738027e84b8ee2c94990649deb47e9bb1f31037892b03fe19f8b5ebd11f68bb45025e0685ff80ebfa578ece5e5918feeb669e5a5ef7909655a
7
- data.tar.gz: 16ffbdc2492ac696d5cc48df8f5ede19dee95e907a099e4eca9e6e07feb25373d7d4119ae7aa104db9b817315cf551a600da1dd016e3d25d89b09a85e8a40929
6
+ metadata.gz: eb28349484e0b914c839bef30de734bd368f0b63696f26d0cb616e90d0a3e4872f13d727bd215c47fafd527c9397fd3406af74131ca8a9d0cb7b7e4efb8ef90e
7
+ data.tar.gz: cc7715bd90bceb56eba923207c281b54b7069b68a8bfe9b5442bd0de362b3d28001a9f91639e661ea5ad87ee699f30a1c406813acac87923700cd05beaf6fba9
data/Gemfile CHANGED
@@ -1,2 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
4
+ group :test do
5
+ gem 'minitest', require: false
6
+ gem 'minitest-spec-context', require: false
7
+ gem 'minitest-reporters', require: false
8
+ gem 'mocha', require: false
9
+ end
data/README.md CHANGED
@@ -60,6 +60,21 @@ This will generate the following app:
60
60
 
61
61
  ````
62
62
  myapp
63
+ ├── .bowerrc
64
+ ├── .env
65
+ ├── .gitignore
66
+ ├── .grunt
67
+ │   ├── aliases.yaml
68
+ │   ├── coffee.coffee
69
+ │   ├── imagemin.coffee
70
+ │   ├── robotstxt.coffee
71
+ │   ├── sass.coffee
72
+ │   ├── slim.coffee
73
+ │   └── uglify.coffee
74
+ ├── .node-version
75
+ ├── .ruby-version
76
+ ├── .slugignore
77
+ ├── .travis.yml
63
78
  ├── Gemfile
64
79
  ├── Gruntfile.coffee
65
80
  ├── Procfile
@@ -67,11 +82,13 @@ myapp
67
82
  ├── app.rb
68
83
  ├── assets
69
84
  │   ├── images
85
+ │   │   └── .gitkeep
70
86
  │   ├── javascripts
71
- │   │   ├── app.coffee
72
- │   │   ├── config.coffee
73
- │   │   └── main.coffee
87
+ │   │   └── app.coffee
88
+ │   ├── pages
89
+ │   │   └── .gitkeep
74
90
  │   └── stylesheets
91
+ │   ├── .gitkeep
75
92
  │   └── app.scss
76
93
  ├── bin
77
94
  │   └── console
@@ -87,25 +104,33 @@ myapp
87
104
  │   ├── core_ext
88
105
  │   │   └── frame_options.rb
89
106
  │   ├── errors
107
+ │   │   ├── .gitkeep
90
108
  │   │   └── app.rb
91
109
  │   ├── jobs
110
+ │   │   └── .gitkeep
92
111
  │   ├── models
112
+ │   │   └── .gitkeep
93
113
  │   ├── services
114
+ │   │   └── .gitkeep
94
115
  │   ├── tasks
116
+ │   │   └── .gitkeep
95
117
  │   └── values
118
+ │   └── .gitkeep
96
119
  ├── package.json
97
120
  ├── public
98
121
  │   ├── assets
99
- │   │   ├── development
100
- │   │   ├── production
101
- │   │   └── staging
122
+ │   │   └── .gitkeep
102
123
  │   └── fonts
124
+ │   └── .gitkeep
103
125
  ├── spec
104
126
  │   ├── _cassettes
127
+ │   │   └── .gitkeep
105
128
  │   ├── app_spec.rb
106
129
  │   ├── db_helper.rb
107
130
  │   ├── models
131
+ │   │   └── .gitkeep
108
132
  │   ├── services
133
+ │   │   └── .gitkeep
109
134
  │   ├── spec_helper.rb
110
135
  │   └── vcr_helper.rb
111
136
  └── views
@@ -1,4 +1,37 @@
1
- require 'daiku/cli'
2
- require 'daiku/version'
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ lib_path = File.expand_path('../lib', __FILE__)
6
+ ($:.unshift lib_path) unless ($:.include? lib_path)
3
7
 
4
8
  module Daiku ; end
9
+
10
+ require 'daiku/core_ext'
11
+
12
+ require 'daiku/plugin'
13
+ require 'daiku/plugins'
14
+
15
+ require 'daiku/plugins/database-sql'
16
+ require 'daiku/plugins/database-sql/cli'
17
+
18
+ require 'daiku/plugins/datamapper'
19
+ require 'daiku/plugins/datamapper/cli'
20
+
21
+ require 'daiku/plugins/grunt'
22
+ require 'daiku/plugins/grunt/cli'
23
+
24
+ require 'daiku/plugins/honeybadger'
25
+ require 'daiku/plugins/honeybadger/cli'
26
+
27
+ require 'daiku/plugins/newrelic'
28
+ require 'daiku/plugins/newrelic/cli'
29
+
30
+ require 'daiku/plugins/sidekiq'
31
+ require 'daiku/plugins/sidekiq/cli'
32
+
33
+ require 'daiku/plugins/vcr'
34
+ require 'daiku/plugins/vcr/cli'
35
+
36
+ require 'daiku/version'
37
+ require 'daiku/cli'
@@ -1,16 +1,5 @@
1
1
  APP_NAME=<%= @app %>
2
2
  APP_TITLE=<%= @app %>
3
- ASSETS_BUILDER=<%= @assets %>
4
- <% if @with_sidekiq -%>
5
- AUTH_USERNAME=<%= @app %>
6
- AUTH_PASSWORD=<%= @app %>
7
- <% end -%>
8
- <% if @datamapper -%>
9
- DATABASE_URL=postgres://localhost/<%= @app %>
10
- DB_NAME=<%= @app %>
11
- <% end -%>
12
- HONEYBADGER_PRIVATE_KEY=<%= @honeybadger_private_key %>
13
- HONEYBADGER_PUBLIC_KEY=<%= @honeybadger_public_key %>
14
3
  RACK_ENV=development
15
4
  PORT=<%= @port %>
16
5
  PUMA_MAX_THREADS=8
@@ -0,0 +1 @@
1
+ <%= @node %>
@@ -1 +1 @@
1
- <%= @ruby_version -%>
1
+ <%= @ruby -%>
@@ -2,16 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - <%= @ruby_version %>
5
- <% if @datamapper -%>
6
5
  services:
7
- - postgresql
8
6
  addons:
9
- postgresql: 9.3
10
- before_script:
11
- - psql -c 'create database "<%= @app -%>_test";' -U postgres
12
- - 'bundle exec rake db:hstore'
13
- - 'bundle exec rake db:migrate'
14
- <% end -%>
7
+ before_script:
15
8
  notifications:
16
9
  template:
17
10
  - "%{repository}:%{branch} - %{message} [%{build_url}]"
@@ -1,31 +1,14 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- ruby <%= "'#{@ruby_version}'" %>
3
+ ruby <%= "'#{@ruby}'" %>
4
4
 
5
5
  gem 'activesupport', '~> 4.0.0', require: false
6
6
  gem 'dalli'
7
7
  gem 'escape_utils'
8
- gem 'honeybadger'
9
8
  gem 'nokogiri'
10
9
  gem 'oj'
11
10
  gem 'pry', require: false
12
11
  gem 'puma', require: false
13
- <%= "gem 'sidekiq'\n" if @with_sidekiq -%>
14
-
15
- <% if @datamapper -%>
16
- group :datamapper do
17
- gem 'dm-aspects'
18
- gem 'dm-aggregates'
19
- gem 'dm-core'
20
- gem 'dm-migrations'
21
- gem 'dm-pager'
22
- gem 'dm-postgres-adapter'
23
- gem 'dm-postgres-types'
24
- gem 'dm-timestamps'
25
- gem 'dm-transactions'
26
- gem 'dm-validations'
27
- end
28
- <% end -%>
29
12
 
30
13
  group :web do
31
14
  gem 'sinatra', '~> 1.4.4', require: 'sinatra/base'
@@ -35,7 +18,6 @@ end
35
18
 
36
19
  group :production, :staging do
37
20
  gem 'rack-ssl', require: 'rack/ssl', :group => :web
38
- <%= " gem 'newrelic_rpm'\n" unless @no_newrelic -%>
39
21
  end
40
22
 
41
23
  group :rake do
@@ -43,24 +25,11 @@ group :rake do
43
25
  end
44
26
 
45
27
  group :test do
46
- <%= " gem 'database_cleaner'\n" if @datamapper -%>
47
28
  gem 'rack-test', require: 'rack/test'
48
29
  gem 'minitest'
49
30
  gem 'minitest-spec-context'
50
31
  gem 'minitest-reporters', require: 'minitest/reporters'
51
32
  gem 'mocha', require: 'mocha/setup'
52
- <% if @with_vcr -%>
53
- gem 'vcr', require: false
54
- gem 'webmock', '< 1.12', require: false
55
- <% end -%>
56
- end
57
-
58
- group :assets do
59
- gem 'sass'
60
- end
61
-
62
- group :development do
63
- gem 'debugger', require: false
64
33
  end
65
34
 
66
35
  group :development, :test do
@@ -1,5 +1,2 @@
1
- web: bundle exec puma -t ${PUMA_MIN_THREADS:-0}:${PUMA_MAX_THREADS:-16} -w ${PUMA_WORKERS:-0} -p $PORT -e $RACK_ENV -C config/puma.rb
1
+ web: bundle exec puma -t ${PUMA_MIN_THREADS:-0}:${PUMA_MAX_THREADS:-16} -w ${PUMA_WORKERS:-0} -p $PORT -e $RACK_ENV -C config/puma.rb
2
2
  console: bundle exec ./bin/console
3
- <% if @with_sidekiq -%>
4
- sidekiq: bundle exec sidekiq -q default -r ./lib/boot.rb
5
- <% end -%>
@@ -7,9 +7,11 @@ ENV['RACK_ENV'] ||= 'development'
7
7
  lib_path = File.expand_path('../lib', __FILE__)
8
8
  ($:.unshift lib_path) unless ($:.include? lib_path)
9
9
 
10
- # require farm
10
+ # bundler
11
11
  require 'bundler'
12
12
  Bundler.require(:default, ENV['RACK_ENV'], :rake)
13
+
14
+ # require farm
13
15
  require 'dotenv/tasks'
14
16
  require 'rake/testtask'
15
17
 
@@ -13,7 +13,6 @@ Bundler.require(:default, :web)
13
13
  require './app'
14
14
 
15
15
  # middleware stack
16
- use Honeybadger::Rack::ErrorNotifier
17
16
  if %w(production staging).include? ENV['RACK_ENV']
18
17
  use Rack::SSL, hsts: { subdomains: true }
19
18
  end
@@ -22,14 +21,5 @@ use Rack::Deflater
22
21
  use Rack::Runtime
23
22
 
24
23
  # make the jump
25
- run App
24
+ run app
26
25
 
27
- <% if @with_sidekiq -%>
28
- require 'sidekiq/web'
29
- map '/sidekiq' do
30
- Sidekiq::Web.use Rack::Auth::Basic do |username, password|
31
- username == ENV['AUTH_USERNAME'] && password == ENV['AUTH_PASSWORD']
32
- end
33
- run Sidekiq::Web
34
- end
35
- <% end -%>
@@ -1,4 +1 @@
1
1
  preload_app!
2
- #on_restart do
3
- #Redis.current.client.reconnect
4
- #end
@@ -23,18 +23,12 @@ require 'active_support/core_ext/numeric/conversions'
23
23
 
24
24
 
25
25
  # errors
26
- require File.join($app_root, 'config/honeybadger')
27
26
  require 'errors/app'
28
27
 
29
28
  # models
30
- <% if @datamapper -%>
31
- require File.join($app_root, 'config/datamapper')
32
- DataMapper.finalize
33
- <% end -%>
34
29
 
35
30
  # services
36
31
 
37
- # reports
38
-
39
32
  # values
40
33
 
34
+ # jobs
@@ -3,8 +3,9 @@
3
3
  require 'thor'
4
4
 
5
5
  module Daiku
6
- class CLI < Thor
7
- include Thor::Actions
6
+ class CLI < ::Thor
7
+ include ::Thor::Actions
8
+ class_option :version, type: :boolean
8
9
 
9
10
  def self.source_root
10
11
  File.expand_path('../', __FILE__)
@@ -12,73 +13,71 @@ module Daiku
12
13
 
13
14
  desc "new APP", "Generate a new application with daiku"
14
15
  method_option :port, required: true, aliases: '-p', type: :numeric, desc: 'Port this app should run on locally.'
15
- method_option :ruby_version, default: '2.1.2', desc: 'Specify the version of ruby this project should use.'
16
- method_option :models, default: 'datamapper', aliases: '-m', desc: 'Choose the data modeling tool this project uses.', enum: ['datamapper', 'none']
17
- method_option :assets, default: 'grunt', aliases: '-a', desc: 'Choose the assets workflow this project uses.', enum: ['grunt', 'none']
18
- method_option :'honeybadger-private-key', desc: "Honeybadger Private API Key"
19
- method_option :'honeybadger-public-key', desc: "Honeybadger Private API Key"
20
- method_option :'no-newrelic', type: :boolean, desc: "Don't use New Relic."
21
- method_option :'with-vcr', type: :boolean, desc: "Include `vcr` in this project's TDD stack."
22
- method_option :'with-sidekiq', type: :boolean, desc: "Set this project up to use `sidekiq` for background processing."
16
+ method_option :ruby, default: '2.1.5', desc: 'Specify the version of ruby this project should use.'
17
+ method_option :node, default: 'v0.10.33', desc: 'Specify the version of node this project should use.'
18
+ method_option :assets, aliases: '-a', desc: 'Choose the assets workflow this project uses.', enum: Daiku::Plugins.plugin_names('assets')
19
+ method_option :errors, aliases: '-e', desc: 'Choose the error reporting lib this project uses.', enum: Daiku::Plugins.plugin_names('errors')
20
+ method_option :jobs, aliases: '-j', desc: 'Choose the background jobs lib this project uses.', enum: Daiku::Plugins.plugin_names('jobs')
21
+ method_option :models, aliases: '-m', desc: 'Choose the data modeling lib this project uses.', enum: Daiku::Plugins.plugin_names('models')
22
+ method_option :monitors, aliases: '-M', desc: 'Choose the monitoring lib this project uses.', enum: Daiku::Plugins.plugin_names('monitors')
23
+ method_option :vcr, type: :boolean, desc: "Include `vcr` in this project's BDD stack?", default: false
24
+ method_option :sql, type: :boolean, desc: "SQL or No-SQL? If SQL, assumes postgresql", default: true
23
25
  def new(app)
24
- @app = app
25
- @port = options[:port]
26
- @ruby_version = options[:ruby_version]
26
+ @app = app
27
+ @port = options[:port]
28
+ @ruby = options[:ruby]
27
29
  @models = options[:models]
28
30
  @assets = options[:assets]
29
- @honeybadger_private_key = options[:'honeybadger-private-key']
30
- @honeybadger_public_key = options[:'honeybadger-public-key']
31
- @no_newrelic = options[:'no-newrelic']
32
- @with_vcr = options[:'with-vcr']
33
- @with_sidekiq = options[:'with-sidekiq']
34
-
35
- case @models
36
- when 'datamapper'
37
- @datamapper = true
38
- when 'none'
39
- @datamapper = false
40
- end
41
-
42
- case @assets
43
- when 'grunt'
44
- @grunt = true
45
- when 'none'
46
- @grunt = false
47
- end
31
+ @jobs = options[:jobs]
48
32
 
49
33
  # do the dew
50
34
  say "Generating #{app} app..."
51
35
  directory('_app', app)
52
36
  chmod("#{app}/bin/console", 'a+x')
53
- template("_templates/#{@models}.rb.tt", "#{app}/config/#{@models}.rb")
54
- copy_file('_templates/db_helper.rb', "#{app}/spec/db_helper.rb") if @datamapper
55
37
 
56
- if @grunt
57
- directory('_grunt', app)
38
+ if @assets
39
+ invoke plugins[@assets][:class].cli, [@app], options
40
+ end
41
+
42
+ if @errors
43
+ invoke plugins[@errors][:class].cli, [@app], options
44
+ end
45
+
46
+ if @jobs
47
+ invoke plugins[@jobs][:class].cli, [@app], options
58
48
  end
59
49
 
60
- if @with_vcr
61
- copy_file('_templates/vcr_helper.rb', "#{app}/spec/vcr_helper.rb")
62
- empty_directory("#{app}/spec/_cassettes")
63
- create_file("#{app}/spec/_cassettes/.gitkeep", "")
50
+ if @models
51
+ invoke plugins[@models][:class].cli, [@app], options
64
52
  end
65
53
 
66
- if @with_sidekiq
67
- template('_templates/sidekiq.rb.tt', "#{app}/config/sidekiq.rb")
68
- empty_directory("#{app}/lib/jobs")
69
- create_file("#{app}/lib/jobs/.gitkeep", "")
70
- append_to_file("#{app}/lib/boot.rb") do
71
- "# jobs\n" +
72
- "require File.join($app_root, 'config/sidekiq')"
73
- end
54
+ if @monitors
55
+ invoke plugins[@monitors][:class].cli, [@app], options
56
+ end
57
+
58
+ if options[:sql]
59
+ invoke plugins['database-sql'][:class].cli, [@app], options
60
+ else
61
+ say_status 'skipped', "--no-sql option is not supported yet", :yellow
62
+ end
63
+
64
+ if options[:vcr]
65
+ invoke plugins['vcr'][:class].cli, [@app], options
74
66
  end
75
67
 
76
68
  say "Done!"
77
69
  end
78
70
 
79
- desc "version", "Prints version number"
71
+ desc "version", "Show the daiku version"
80
72
  def version
81
73
  say "Daiku v#{Daiku::VERSION}"
82
74
  end
75
+ default_task :version
76
+
77
+ no_tasks do
78
+ def plugins
79
+ Daiku::Plugins.register_plugins
80
+ end
81
+ end
83
82
  end
84
83
  end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ class Object
4
+ def try(*a, &b)
5
+ if a.empty? && block_given?
6
+ yield self
7
+ else
8
+ public_send(*a, &b) if respond_to?(a.first)
9
+ end
10
+ end
11
+
12
+ def try!(*a, &b)
13
+ if a.empty? && block_given?
14
+ yield self
15
+ else
16
+ public_send(*a, &b)
17
+ end
18
+ end
19
+ end
20
+
21
+ class NilClass
22
+ def try(*args)
23
+ nil
24
+ end
25
+
26
+ def try!(*args)
27
+ nil
28
+ end
29
+ end
30
+
31
+ class String
32
+ def strip_heredoc
33
+ indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
34
+ gsub(/^[ \t]{#{indent}}/, '')
35
+ end
36
+ end
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugin
5
+ def self.plugin_name(name)
6
+ meta[:name] = name
7
+ end
8
+
9
+ def self.plugin_type(type)
10
+ meta[:type] = type
11
+ end
12
+
13
+ def self.meta
14
+ @meta = { class: Kernel.const_get(self.name) } if @meta.nil?
15
+ @meta
16
+ end
17
+
18
+ def self.cli
19
+ meta[:class]::CLI
20
+ end
21
+
22
+ def self.cli_path
23
+ File.expand_path('../', __FILE__)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ def self.find_plugins
6
+ Daiku::Plugins.constants.map do |plugin|
7
+ Daiku::Plugins.const_get(plugin.to_s, false)
8
+ end
9
+ end
10
+
11
+ def self.register_plugins
12
+ Hash[*find_plugins.map do |plugin|
13
+ [plugin.meta[:name], plugin.meta]
14
+ end.flatten]
15
+ end
16
+
17
+ def self.has_plugins?(type)
18
+ register_plugins.values.any? do |plugin|
19
+ plugin[:type] == type
20
+ end
21
+ end
22
+
23
+ def self.filter_plugins(value, filter = :type)
24
+ register_plugins.values.select do |plugin|
25
+ plugin[filter] == value
26
+ end
27
+ end
28
+
29
+ def self.plugin_names(type = nil)
30
+ plugins = if type.nil?
31
+ register_plugins.values
32
+ else
33
+ filter_plugins(type, :type)
34
+ end
35
+ plugins.map { |plugin| plugin[:name] }
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class DatabaseSql < ::Daiku::Plugin
6
+ plugin_name 'database-sql'
7
+ plugin_type 'config'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class DatabaseSql
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+ class_option :'db-name', desc: 'development database name'
12
+ class_option :'db-url', desc: 'development database connection url'
13
+
14
+ def self.source_root
15
+ File.expand_path('../', __FILE__)
16
+ end
17
+
18
+ def dotenv
19
+ dbname = options.fetch(:'db-name') { "postgres://localhost/#{app}" }
20
+ dburl = options.fetch(:'db-url') { app }
21
+ append_to_file "#{app}/.env", "DATABASE_NAME=#{dbname}"
22
+ append_to_file "#{app}/.env", "DATABASE_URL=#{dburl}"
23
+ end
24
+
25
+ def config
26
+ template('_templates/db_helper.rb.tt', "#{app}/spec/db_helper.rb")
27
+ end
28
+
29
+ def gemfile
30
+ insert_into_file "#{app}/Gemfile", " gem 'database_cleaner'\n", after: "group :test do\n"
31
+ end
32
+
33
+ def travisyml
34
+ insert_into_file "#{app}/.travis.yml", " - postgresql\n", after: "services:\n"
35
+ insert_into_file "#{app}/.travis.yml", " postgresql: 9.3\n", after: "addons:\n"
36
+ insert_into_file "#{app}/.travis.yml", %Q( - psql -c 'create database "#{app}_test";' -U postgres\n), after: "before_script:\n"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Datamapper < ::Daiku::Plugin
6
+ plugin_name 'datamapper'
7
+ plugin_type 'models'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Datamapper
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+
12
+ def self.source_root
13
+ File.expand_path('../', __FILE__)
14
+ end
15
+
16
+ def bootrb
17
+ insert_into_file "#{app}/lib/boot.rb", :after => "#models\n" do
18
+ <<-DMREQ.strip_heredoc
19
+ require File.join($app_root, 'config/datamapper')
20
+ # insert require statements for models here
21
+ DataMapper.finalize
22
+ DMREQ
23
+ end
24
+ end
25
+
26
+ def config
27
+ template('_templates/datamapper.rb.tt', "#{app}/config/datamapper.rb")
28
+ end
29
+
30
+ def gemfile
31
+ content = <<-DMGEMS.strip_heredoc
32
+ group :datamapper do
33
+ gem 'dm-aspects'
34
+ gem 'dm-aggregates'
35
+ gem 'dm-core'
36
+ gem 'dm-migrations'
37
+ gem 'dm-pager'
38
+ gem 'dm-postgres-adapter'
39
+ gem 'dm-postgres-types'
40
+ gem 'dm-timestamps'
41
+ gem 'dm-transactions'
42
+ gem 'dm-validations'
43
+ end
44
+ DMGEMS
45
+ append_to_file "#{app}/Gemfile", content
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Grunt < ::Daiku::Plugin
6
+ plugin_name 'grunt'
7
+ plugin_type 'assets'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "analytics": false,
3
+ "directory":"assets/vendor"
4
+ }
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Grunt
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+
12
+ def self.source_root
13
+ File.expand_path('../', __FILE__)
14
+ end
15
+
16
+ def config
17
+ template '_templates/.bowerrc', "#{app}/.bowerrc"
18
+ template '_templates/bower.json.tt', "#{app}/bower.json"
19
+ template '_templates/Gruntfile.coffee.tt', "#{app}/Gruntfile.coffee"
20
+ template '_templates/package.json.tt', "#{app}/package.json"
21
+ directory '_config', "#{app}/.grunt"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Honeybadger < ::Daiku::Plugin
6
+ plugin_name 'honeybadger'
7
+ plugin_type 'errors'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Honeybadger
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+ class_option :'honeybadger-private-key', desc: "Honeybadger Private API Key"
12
+ class_option :'honeybadger-public-key', desc: "Honeybadger Private API Key"
13
+
14
+ def self.source_root
15
+ File.expand_path('../', __FILE__)
16
+ end
17
+
18
+ def bootrb
19
+ insert_into_file "#{app}/lib/boot.rb", "require File.join($app_root, 'config/honeybadger')\n", after: "#errors\n"
20
+ end
21
+
22
+ def config
23
+ template('_templates/honeybadger.rb.tt', "#{app}/config/honeybadger.rb")
24
+ end
25
+
26
+ def dotenv
27
+ honeybadger_private_key = options.fetch(:'honeybadger-private-key') { '' }
28
+ honeybadger_public_key = options.fetch(:'honeybadger-public-key') { '' }
29
+ append_to_file "#{app}/.env", "HONEYBADGER_PRIVATE_KEY=#{honeybadger_private_key}"
30
+ append_to_file "#{app}/.env", "HONEYBADGER_PUBLIC_KEY=#{honeybadger_public_key}"
31
+ end
32
+
33
+ def gemfile
34
+ insert_into_file "#{app}/Gemfile", "gem 'honeybadger'\n", after: "gem 'escape_utils'\n"
35
+ end
36
+
37
+ def rackup
38
+ insert_into_file "#{app}/config.ru", "use Honeybadger::Rack::ErrorNotifier\n", after: "# middleware stack\n"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Newrelic < ::Daiku::Plugin
6
+ plugin_name 'newrelic'
7
+ plugin_type 'monitors'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Newrelic
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+
12
+ def self.source_root
13
+ File.expand_path('../', __FILE__)
14
+ end
15
+
16
+ def gemfile
17
+ insert_into_file "#{app}/Gemfile", " gem 'newrelic_rpm'\n", after: "group :production, :staging do\n"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Sidekiq < ::Daiku::Plugin
6
+ plugin_name 'sidekiq'
7
+ plugin_type 'jobs'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Sidekiq
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+
12
+ def self.source_root
13
+ File.expand_path('../', __FILE__)
14
+ end
15
+
16
+ def bootrb
17
+ insert_into_file "#{app}/lib/boot.rb", "require File.join($app_root, 'config/sidekiq')\n", after: "# jobs\n"
18
+ end
19
+
20
+ def config
21
+ template('_templates/sidekiq.rb.tt', "#{app}/config/sidekiq.rb")
22
+ empty_directory("#{app}/lib/jobs")
23
+ create_file("#{app}/lib/jobs/.gitkeep", "")
24
+ end
25
+
26
+ def dotenv
27
+ append_to_file "#{app}/.env", "SIDEKIQ_USERNAME=#{app}\n"
28
+ append_to_file "#{app}/.env", "SIDEKIQ_PASSWORD=#{app}\n"
29
+ end
30
+
31
+ def gemfile
32
+ insert_into_file "#{app}/Gemfile", "gem 'sidekiq'\n", after: "gem 'puma', require: false\n"
33
+ end
34
+
35
+ def procfile
36
+ append_to_file "#{app}/Procfile", "sidekiq: bundle exec sidekiq -q default -r ./lib/boot.rb\n"
37
+ end
38
+
39
+ def rackup
40
+ content = <<-SKMW.strip_heredoc
41
+ require 'sidekiq/web'
42
+ map '/sidekiq' do
43
+ Sidekiq::Web.use Rack::Auth::Basic do |username, password|
44
+ username == ENV['SIDEKIQ_USERNAME'] && password == ENV['SIDEKIQ_PASSWORD']
45
+ end
46
+ run Sidekiq::Web
47
+ SKMW
48
+ append_to_file "#{app}/config.ru", content
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ module Daiku
4
+ class Plugins
5
+ class Vcr < ::Daiku::Plugin
6
+ plugin_name 'vcr'
7
+ plugin_type 'config'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'thor'
4
+
5
+ module Daiku
6
+ class Plugins
7
+ class Vcr
8
+ class CLI < ::Thor::Group
9
+ include ::Thor::Actions
10
+ argument :app
11
+
12
+ def self.source_root
13
+ File.expand_path('../', __FILE__)
14
+ end
15
+
16
+ def config
17
+ template('_templates/vcr_helper.rb.tt', "#{app}/spec/vcr_helper.rb")
18
+ empty_directory("#{app}/spec/_cassettes")
19
+ create_file("#{app}/spec/_cassettes/.gitkeep", "")
20
+ end
21
+
22
+ def gemfile
23
+ insert_into_file "#{app}/Gemfile", after: " gem 'mocha', require: 'mocha/setup'\n" do
24
+ " gem 'vcr', require: false\n" +
25
+ " gem 'webmock', '< 1.12', require: false\n"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Daiku
2
- VERSION = "0.0.12"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Daiku::Plugins do
6
+ subject { Daiku::Plugins }
7
+ let(:plugins) do
8
+ [
9
+ Daiku::Plugins::DatabaseSql,
10
+ Daiku::Plugins::Datamapper,
11
+ Daiku::Plugins::Grunt,
12
+ Daiku::Plugins::Honeybadger,
13
+ Daiku::Plugins::Newrelic,
14
+ Daiku::Plugins::Sidekiq,
15
+ Daiku::Plugins::Vcr
16
+ ]
17
+ end
18
+
19
+ let(:plugins_hash) do
20
+ hash = {}
21
+ plugins.each do |plugin|
22
+ hash[plugin.meta[:name]] = plugin.meta
23
+ end
24
+ hash
25
+ end
26
+
27
+ let(:plugin_names) do
28
+ plugins.map do |plugin|
29
+ plugin.meta[:name]
30
+ end
31
+ end
32
+
33
+ it "can find plugins" do
34
+ subject.find_plugins.must_equal plugins
35
+ end
36
+
37
+ it "can register plugins" do
38
+ subject.register_plugins.must_equal plugins_hash
39
+ end
40
+
41
+ it "returns true if a plugin of given type is present" do
42
+ subject.has_plugins?('models').must_equal true
43
+ end
44
+
45
+ it "returns false if a plugin of given type is NOT present" do
46
+ subject.has_plugins?('example').must_equal false
47
+ end
48
+
49
+ it "can filter plugins by type" do
50
+ subject.filter_plugins('models', :type).must_equal [subject::Datamapper.meta]
51
+ end
52
+
53
+ it "returns names of all plugins" do
54
+ subject.plugin_names.must_equal plugin_names
55
+ end
56
+
57
+ it "returns names of plugins of type: models" do
58
+ subject.plugin_names('models').must_equal ['datamapper']
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ ENV['RACK_ENV'] = 'test'
4
+
5
+ lib_path = File.expand_path('../../lib', __FILE__)
6
+ ($:.unshift lib_path) unless ($:.include? lib_path)
7
+
8
+ Bundler.setup(:default, ENV['RACK_ENV'])
9
+
10
+ require 'daiku'
11
+ require 'minitest/autorun'
12
+ require 'minitest/reporters'
13
+
14
+ MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
15
+
16
+ require 'mocha/setup'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: daiku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Marden
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -70,6 +70,7 @@ files:
70
70
  - lib/daiku.rb
71
71
  - lib/daiku/_app/.env.tt
72
72
  - lib/daiku/_app/.gitignore
73
+ - lib/daiku/_app/.node-version
73
74
  - lib/daiku/_app/.ruby-version.tt
74
75
  - lib/daiku/_app/.slugignore
75
76
  - lib/daiku/_app/.travis.yml.tt
@@ -84,7 +85,7 @@ files:
84
85
  - lib/daiku/_app/assets/stylesheets/app.scss
85
86
  - lib/daiku/_app/bin/console
86
87
  - lib/daiku/_app/config.ru.tt
87
- - lib/daiku/_app/config/honeybadger.rb
88
+ - lib/daiku/_app/config/pony.rb.tt
88
89
  - lib/daiku/_app/config/puma.rb
89
90
  - lib/daiku/_app/lib/boot.rb.tt
90
91
  - lib/daiku/_app/lib/core_ext/frame_options.rb
@@ -102,25 +103,44 @@ files:
102
103
  - lib/daiku/_app/spec/spec_helper.rb
103
104
  - lib/daiku/_app/views/index.slim.tt
104
105
  - lib/daiku/_app/views/layout.slim
105
- - lib/daiku/_grunt/.bowerrc
106
- - lib/daiku/_grunt/.grunt/aliases.yaml
107
- - lib/daiku/_grunt/.grunt/coffee.coffee
108
- - lib/daiku/_grunt/.grunt/imagemin.coffee
109
- - lib/daiku/_grunt/.grunt/robotstxt.coffee
110
- - lib/daiku/_grunt/.grunt/sass.coffee
111
- - lib/daiku/_grunt/.grunt/slim.coffee
112
- - lib/daiku/_grunt/.grunt/uglify.coffee
113
- - lib/daiku/_grunt/Gruntfile.coffee
114
- - lib/daiku/_grunt/bower.json.tt
115
- - lib/daiku/_grunt/package.json.tt
116
- - lib/daiku/_templates/bower.json.tt
117
- - lib/daiku/_templates/datamapper.rb.tt
118
- - lib/daiku/_templates/db_helper.rb
119
- - lib/daiku/_templates/pony.rb.tt
120
- - lib/daiku/_templates/sidekiq.rb.tt
121
- - lib/daiku/_templates/vcr_helper.rb
122
106
  - lib/daiku/cli.rb
107
+ - lib/daiku/core_ext.rb
108
+ - lib/daiku/plugin.rb
109
+ - lib/daiku/plugins.rb
110
+ - lib/daiku/plugins/database-sql.rb
111
+ - lib/daiku/plugins/database-sql/_templates/db_helper.rb.tt
112
+ - lib/daiku/plugins/database-sql/cli.rb
113
+ - lib/daiku/plugins/datamapper.rb
114
+ - lib/daiku/plugins/datamapper/_templates/datamapper.rb.tt
115
+ - lib/daiku/plugins/datamapper/cli.rb
116
+ - lib/daiku/plugins/grunt.rb
117
+ - lib/daiku/plugins/grunt/_config/aliases.yaml
118
+ - lib/daiku/plugins/grunt/_config/coffee.coffee
119
+ - lib/daiku/plugins/grunt/_config/imagemin.coffee
120
+ - lib/daiku/plugins/grunt/_config/robotstxt.coffee
121
+ - lib/daiku/plugins/grunt/_config/sass.coffee
122
+ - lib/daiku/plugins/grunt/_config/slim.coffee
123
+ - lib/daiku/plugins/grunt/_config/uglify.coffee
124
+ - lib/daiku/plugins/grunt/_templates/.bowerrc
125
+ - lib/daiku/plugins/grunt/_templates/.bowerrc.tt
126
+ - lib/daiku/plugins/grunt/_templates/Gruntfile.coffee
127
+ - lib/daiku/plugins/grunt/_templates/bower.json.tt
128
+ - lib/daiku/plugins/grunt/_templates/package.json.tt
129
+ - lib/daiku/plugins/grunt/cli.rb
130
+ - lib/daiku/plugins/honeybadger.rb
131
+ - lib/daiku/plugins/honeybadger/_templates/honeybadger.rb.tt
132
+ - lib/daiku/plugins/honeybadger/cli.rb
133
+ - lib/daiku/plugins/newrelic.rb
134
+ - lib/daiku/plugins/newrelic/cli.rb
135
+ - lib/daiku/plugins/sidekiq.rb
136
+ - lib/daiku/plugins/sidekiq/_templates/sidekiq.rb.tt
137
+ - lib/daiku/plugins/sidekiq/cli.rb
138
+ - lib/daiku/plugins/vcr.rb
139
+ - lib/daiku/plugins/vcr/_templates/vcr_helper.rb.tt
140
+ - lib/daiku/plugins/vcr/cli.rb
123
141
  - lib/daiku/version.rb
142
+ - spec/daiku/plugins_spec.rb
143
+ - spec/spec_helper.rb
124
144
  homepage: https://github.com/xentek/daiku
125
145
  licenses:
126
146
  - MIT
@@ -145,4 +165,6 @@ rubygems_version: 2.2.2
145
165
  signing_key:
146
166
  specification_version: 4
147
167
  summary: Craft lightweight ruby applications
148
- test_files: []
168
+ test_files:
169
+ - spec/daiku/plugins_spec.rb
170
+ - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- {
2
- "name": "<%= @app %>",
3
- "main": ["assets/stylesheets/app.scss", "assets/javascripts/app.js"],
4
- "dependencies": {
5
- "jquery": "~2.0.3",
6
- "requirejs": null,
7
- "html5shiv": "~3.7.0",
8
- }
9
- }