monkey-gun 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9001e75ecdd3f6ad3c05685f1731af1e34ad1cdd
4
+ data.tar.gz: cd014460a3950d762009e6258d7688fdf5082880
5
+ SHA512:
6
+ metadata.gz: f56bdd698641d3de12ff3fc8109a4486696b1906649ef078f5baf99835424495bfa51d217f67496ab998f872cc2247f479d5c4a5d9865fd1370284673c48b50d
7
+ data.tar.gz: 7828fb5724c80f8cd39fa18ee34c58aee02e8101300d4744cc39e1495203fc96c9c62e2e7b7f31a50fac8954655c3d0e5ec8ce6303f5d0342d2e60a38ecc4276
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monkey-gun.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 juliogarciag
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Monkey::Gun
2
+
3
+ This is an opionionated project creator based in the assumption that server-rendered applications will be replaced by single-page applications in the near future. Javascript frameworks are here to stay and what our backend frameworks should evolve to be API generators.
4
+
5
+ ## Installation
6
+
7
+ Install it globally with this:
8
+
9
+ $ gem install monkey-gun
10
+
11
+ ## Usage
12
+
13
+ The assumption in the structure is the following:
14
+
15
+ - A folder for your API code. The assumption here is to use Rails, ActiveModelSerializers and PostgreSQL.
16
+ - A folder for your client side app code. We are assuming Ember because we like.
17
+ - A folder to test your API code in order to make a bridge with the client side.
18
+ - A Rakefile or a Capfile and a deploy folder for your deployment tasks. We can deploy against S3, DigitalOcean or whatever or maybe we can deploy to Github-Pages or Heroku. This is the only decision you have to do. There is an option that takes the values `capistrano` and `rake` and make the correct arrangement.
19
+ - A single repository for all of this. Manage multiple repositories can be an early optimization that can make things more complex and we need to start as simple as possible.
20
+
21
+ Well, after acknowledging this, here are the instructions:
22
+
23
+ ```sh
24
+ $ monkey-gun create hello-world
25
+ ```
26
+
27
+ ## Roadmap
28
+ - Make Rails and Ember optional to allow using any other framework in case somebody else likes any other thing.
29
+ - Include a fully-fledged Capfile for deployments, not only run `cap:i`.
30
+
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it ( https://github.com/juliogarciag/monkey-gun/fork )
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thor'
4
+ require 'pathname'
5
+ require_relative '../lib/monkey/gun'
6
+
7
+ class MonkeyGunCLI < Thor
8
+ include Thor::Actions
9
+ include Monkey::Gun::CliHelpers
10
+
11
+ desc 'create APP_NAME', 'create APP_NAME opinionated project structure'
12
+ def create(app_name)
13
+ self.app_name = app_name
14
+
15
+ setup
16
+
17
+ assert_requirements!
18
+ create_project_main_dir
19
+ create_deploy_files
20
+ create_api_application
21
+ create_api_tests
22
+ create_client_application
23
+
24
+ teardown
25
+ end
26
+
27
+ private
28
+
29
+ attr_accessor :app_name, :here_path, :here_gemfile, :initial_directory
30
+
31
+ def setup
32
+ self.here_path = File.dirname(File.expand_path(__FILE__))
33
+ self.here_gemfile = Pathname.new(here_path).join('../Gemfile')
34
+ self.initial_directory = Dir.pwd
35
+ end
36
+
37
+ def teardown
38
+ remove_dir "#{app_name}/#{app_name}-api/.git"
39
+ remove_dir "#{app_name}/#{app_name}/.git"
40
+ run "git add -A"
41
+ run "git commit -m 'Initial Commit'"
42
+ end
43
+
44
+ def assert_requirements!
45
+ check_for_binaries!(:ruby, :bundle) { "You need Ruby with Bundler installed before going on." }
46
+ check_for_binaries!(:node, :npm) { "You need Node with NPM installed before going on." }
47
+ check_for_binaries!(:ember) { "You need install ember-cli first: npm install -g ember-cli" }
48
+ end
49
+
50
+ def create_project_main_dir
51
+ Dir.mkdir(app_name)
52
+ Dir.chdir(app_name)
53
+ create_file "#{app_name}/README.md", "##{app_name} project\n"
54
+ run "git init"
55
+ end
56
+
57
+ def create_api_application
58
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec rails new #{app_name}-api --template=#{here_path}/templates/rails_template.rb --skip-sprockets --skip-turbolinks --skip-spring --skip-test-unit --database=postgresql"
59
+ end
60
+
61
+ def create_api_tests
62
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec restspec install #{app_name}-api-tests --api-prefix=http://localhost:3000"
63
+ end
64
+
65
+ def create_client_application
66
+ run "ember new #{app_name}"
67
+ end
68
+
69
+ def create_deploy_files
70
+ deploy_option = ask("What will you use for deployments?", :limited_to => ['rake', 'capistrano'])
71
+
72
+ main_gemfile = Pathname.new(Dir.pwd).join('Gemfile')
73
+
74
+ if deploy_option == 'rake'
75
+ create_file "#{app_name}/Rakefile"
76
+ create_file "#{app_name}/Gemfile", "source \"https://rubygems.org\"\n\ngem \"rake\""
77
+ else
78
+ create_file "#{app_name}/Gemfile", "source \"https://rubygems.org\"\n\ngem \"capistrano\""
79
+ run "BUNDLE_GEMFILE=#{main_gemfile} bundle exec cap install"
80
+ set_capistrano
81
+ end
82
+
83
+ run "BUNDLE_GEMFILE=#{main_gemfile} bundle install"
84
+ end
85
+
86
+ def set_capistrano
87
+ # Modify Capfile
88
+ prepend_to_file "#{app_name}/Capfile", "set :deploy_config_path, 'deploy/deploy.rb'\nset :stage_config_path, 'deploy/stages'\n\n"
89
+ gsub_file "#{app_name}/Capfile", "Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }",
90
+ "Dir.glob('deploy/lib/capistrano/tasks/*.rake').each { |r| import r }"
91
+
92
+ # Structure
93
+ empty_directory "#{app_name}/config/lib/capistrano/tasks"
94
+ remove_dir "#{app_name}/lib"
95
+ run "mv config/ deploy/"
96
+ run "mv deploy/deploy deploy/stages"
97
+ end
98
+ end
99
+
100
+ MonkeyGunCLI.start(ARGV)
@@ -0,0 +1,84 @@
1
+ require 'json'
2
+ require 'pathname'
3
+
4
+ # README
5
+ remove_file "README.rdoc"
6
+ create_file "README.md", "##{app_name}\n\nTODO: Write an awesome README\n"
7
+
8
+ # Rbenv-Vars
9
+ create_file ".rbenv-vars.example", "PRODUCTION_DATABASE_PASSWORD=\n"
10
+ run "cp .rbenv-vars.example .rbenv-vars"
11
+
12
+ append_to_file '.gitignore', ".rbenv-vars\n"
13
+
14
+ # Ruby Version
15
+ create_file ".ruby-version", "2.1.2"
16
+
17
+ # Gems
18
+ gem 'active_model_serializers'
19
+ gem 'responders'
20
+
21
+ gem_group :development, :test do
22
+ gem 'rspec-rails'
23
+ gem 'factory_girl_rails'
24
+ gem 'pry-byebug'
25
+ gem 'zeus'
26
+ gem 'guard-rspec', require: false
27
+ gem 'pry-rails'
28
+ gem 'faker'
29
+ gem 'shoulda-matchers', require: false
30
+ gem 'rspec-nc', require: false
31
+ gem 'rspec-legacy_formatters', require: false
32
+ end
33
+
34
+ here_gemfile = Pathname.new(Dir.pwd).join('Gemfile')
35
+
36
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle install"
37
+
38
+ # RSpec
39
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec rails g rspec:install"
40
+ comment_lines 'spec/spec_helper.rb', "require 'rspec/autorun'"
41
+ inject_into_file 'spec/spec_helper.rb', "\n config.include FactoryGirl::Syntax::Methods\n", after: "config.order = \"random\"\n"
42
+ prepend_to_file 'spec/spec_helper.rb', "require 'rspec'\n"
43
+
44
+ # Zeus
45
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec zeus init"
46
+
47
+ ## zeus.json
48
+ zeus_json = JSON.parse(File.read('zeus.json'))
49
+ zeus_json['plan']['boot']['default_bundle']['test_environment']['prerake_test'] = begin
50
+ {'rake:test' => []}
51
+ end
52
+ gsub_file 'zeus.json', /^[\w\W]*$/, JSON.pretty_generate(zeus_json)
53
+
54
+ ## custom_plan.rb
55
+ gsub_file 'custom_plan.rb', /class CustomPlan[\w\W]+end/ do
56
+ <<-RUBY
57
+ class CustomPlan < Zeus::Rails
58
+ def prerake_test
59
+ require 'rake'
60
+ end
61
+
62
+ define_method "rake:test" do
63
+ Rake.application.run
64
+ end
65
+ end
66
+ RUBY
67
+ end
68
+
69
+ # Guard
70
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec guard init rspec"
71
+ gsub_file 'Guardfile', 'guard :rspec do', "guard :rspec, cmd: 'zeus rspec' do"
72
+
73
+ # API
74
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec rails g responders:install"
75
+
76
+ remove_file "config/locales/responders.en.yml"
77
+ gsub_file "lib/application_responder.rb", " include Responders::HttpCacheResponder\n", ""
78
+ gsub_file "app/controllers/application_controller.rb", "respond_to :html", "respond_to :json"
79
+
80
+ # Database
81
+ gsub_file "config/database.yml", "#{app_name.upcase}_DATABASE_PASSWORD", "PRODUCTION_DATABASE_PASSWORD"
82
+
83
+ run "BUNDLE_GEMFILE=#{here_gemfile} bundle exec rake db:create"
84
+ run "RAILS_ENV=test BUNDLE_GEMFILE=#{here_gemfile} bundle exec rake db:create"
@@ -0,0 +1,9 @@
1
+ require_relative "./gun/version"
2
+
3
+ module Monkey
4
+ module Gun
5
+ # Your code goes here...
6
+ end
7
+ end
8
+
9
+ require_relative './gun/cli_helpers'
@@ -0,0 +1,18 @@
1
+ module Monkey
2
+ module Gun
3
+ module CliHelpers
4
+ def check_for_binaries!(*binaries, &message_block)
5
+ binaries.each do |bin|
6
+ check_for_binary!(bin.to_s, &message_block)
7
+ end
8
+ end
9
+
10
+ def check_for_binary!(binary, &message_block)
11
+ bin_location = `which #{binary.to_s}`
12
+ if bin_location.nil? || bin_location.empty?
13
+ raise message_block.call || ''
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Monkey
2
+ module Gun
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'monkey/gun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "monkey-gun"
8
+ spec.version = Monkey::Gun::VERSION
9
+ spec.authors = ["juliogarciag"]
10
+ spec.email = ["julioggonz@gmail.com"]
11
+ spec.summary = %q{Opinionated organization of projects}
12
+ spec.description = %q{Opinionated organization of projects}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['monkey-gun']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "thor", "~> 0.19.1"
24
+ spec.add_dependency "rails", "~> 4.2.0"
25
+ spec.add_dependency "restspec", "~> 0.1"
26
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monkey-gun
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - juliogarciag
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: restspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ description: Opinionated organization of projects
84
+ email:
85
+ - julioggonz@gmail.com
86
+ executables:
87
+ - monkey-gun
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/monkey-gun
97
+ - bin/templates/rails_template.rb
98
+ - lib/monkey/gun.rb
99
+ - lib/monkey/gun/cli_helpers.rb
100
+ - lib/monkey/gun/version.rb
101
+ - monkey-gun.gemspec
102
+ homepage: ''
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.14
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Opinionated organization of projects
126
+ test_files: []