potassium 1.3.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1 -1
- data/.ruby_style.yml +6 -2
- data/CHANGELOG.md +19 -1
- data/README.md +79 -74
- data/circle.yml +9 -0
- data/docs/CONTRIBUTING.md +132 -0
- data/docs/{dsl.md → DSL.md} +146 -18
- data/lib/potassium/{templates/application/assets → assets}/.bowerrc +0 -0
- data/lib/potassium/assets/.buildpacks +3 -0
- data/lib/potassium/{templates/application/assets → assets}/.editorconfig +0 -0
- data/lib/potassium/assets/.env.example.erb +8 -0
- data/lib/potassium/assets/.hound.yml +2 -0
- data/lib/potassium/{templates/application/assets → assets}/.pryrc +0 -0
- data/lib/potassium/assets/.rubocop.yml +3 -0
- data/lib/potassium/assets/.ruby_style.yml +0 -0
- data/lib/potassium/assets/Dockerfile.ci +4 -0
- data/lib/potassium/assets/Procfile +1 -0
- data/lib/potassium/assets/README.md.erb +2 -0
- data/lib/potassium/assets/README.yml +83 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/active_admin.js.coffee +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/admin_user_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/comment_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/init_activeadmin_angular.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/active_admin/pundit_page_policy.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/api_error_concern.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/base_controller.rb +0 -0
- data/lib/potassium/{templates/application/assets → assets}/api/responder.rb +0 -0
- data/lib/potassium/assets/bin/cibuild.erb +27 -0
- data/lib/potassium/assets/bin/setup.erb +22 -0
- data/lib/potassium/assets/bin/setup_heroku.erb +21 -0
- data/lib/potassium/{templates/application/assets → assets}/bower.json +0 -0
- data/lib/potassium/assets/circle.yml +16 -0
- data/lib/potassium/assets/config/database_mysql.yml.erb +25 -0
- data/lib/potassium/assets/config/database_postgresql.yml.erb +25 -0
- data/lib/potassium/assets/config/environments/staging.rb +5 -0
- data/lib/potassium/assets/config/puma.rb +29 -0
- data/lib/potassium/assets/config/secrets.yml.erb +14 -0
- data/lib/potassium/assets/docker-compose.ci.yml +6 -0
- data/lib/potassium/{templates/application/assets → assets}/es.yml +0 -0
- data/lib/potassium/{templates/application/assets → assets}/testing/.rspec +0 -0
- data/lib/potassium/{templates/application/assets → assets}/testing/rails_helper.rb +0 -0
- data/lib/potassium/cli/commands/create.rb +55 -4
- data/lib/potassium/cli/commands/install.rb +27 -13
- data/lib/potassium/{templates/application/generator.rb → generators/application.rb} +7 -2
- data/lib/potassium/{templates/application/recipe_generator.rb → generators/recipe.rb} +11 -2
- data/lib/potassium/helpers/answer-helpers.rb +21 -0
- data/lib/potassium/{templates/application/helpers → helpers}/callback-helpers.rb +0 -0
- data/lib/potassium/helpers/docker-helpers.rb +37 -0
- data/lib/potassium/{templates/application/helpers → helpers}/environment-helpers.rb +0 -0
- data/lib/potassium/{templates/application/helpers → helpers}/gem-helpers.rb +6 -2
- data/lib/potassium/helpers/info-helpers.rb +16 -0
- data/lib/potassium/helpers/readme-helpers.rb +85 -0
- data/lib/potassium/{templates/application/helpers → helpers}/template-dsl.rb +8 -0
- data/lib/potassium/helpers/template-helpers.rb +97 -0
- data/lib/potassium/{templates/application/helpers → helpers}/variable-helpers.rb +0 -0
- data/lib/potassium/recipe.rb +2 -0
- data/lib/potassium/{templates/application/recipes → recipes}/admin.rb +36 -6
- data/lib/potassium/recipes/angular_admin.rb +56 -0
- data/lib/potassium/recipes/api.rb +43 -0
- data/lib/potassium/recipes/aws_sdk.rb +5 -0
- data/lib/potassium/recipes/bower.rb +13 -0
- data/lib/potassium/recipes/ci.rb +42 -0
- data/lib/potassium/recipes/cleanup.rb +10 -0
- data/lib/potassium/recipes/database.rb +42 -0
- data/lib/potassium/recipes/delayed_job.rb +41 -0
- data/lib/potassium/recipes/devise.rb +64 -0
- data/lib/potassium/recipes/editorconfig.rb +5 -0
- data/lib/potassium/recipes/env.rb +10 -0
- data/lib/potassium/recipes/git.rb +13 -0
- data/lib/potassium/recipes/github.rb +27 -0
- data/lib/potassium/recipes/heroku.rb +138 -0
- data/lib/potassium/recipes/i18n.rb +26 -0
- data/lib/potassium/recipes/paperclip.rb +37 -0
- data/lib/potassium/recipes/production.rb +7 -0
- data/lib/potassium/recipes/pry.rb +10 -0
- data/lib/potassium/recipes/puma.rb +19 -0
- data/lib/potassium/recipes/pundit.rb +61 -0
- data/lib/potassium/recipes/rack_cors.rb +21 -0
- data/lib/potassium/recipes/readme.rb +7 -0
- data/lib/potassium/recipes/ruby.rb +23 -0
- data/lib/potassium/recipes/script.rb +16 -0
- data/lib/potassium/recipes/secrets.rb +5 -0
- data/lib/potassium/recipes/staging.rb +5 -0
- data/lib/potassium/recipes/style.rb +13 -0
- data/lib/potassium/recipes/testing.rb +37 -0
- data/lib/potassium/templates/application.rb +67 -0
- data/lib/potassium/templates/recipe.rb +12 -0
- data/lib/potassium/text_spinner.rb +0 -5
- data/lib/potassium/version.rb +2 -1
- data/potassium.gemspec +3 -0
- data/spec/fakes/bin/heroku +5 -0
- data/spec/fakes/bin/hub +5 -0
- data/spec/features/ci_spec.rb +14 -0
- data/spec/features/github_spec.rb +22 -0
- data/spec/features/heroku_spec.rb +61 -0
- data/spec/features/new_project_spec.rb +38 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/support/fake_github.rb +25 -0
- data/spec/support/fake_heroku.rb +77 -0
- data/spec/support/potassium_test_helpers.rb +98 -0
- metadata +149 -62
- data/lib/potassium/templates/application/assets/.rbenv-vars.example +0 -8
- data/lib/potassium/templates/application/assets/config/database_mysql.yml +0 -40
- data/lib/potassium/templates/application/assets/config/database_postgresql.yml +0 -26
- data/lib/potassium/templates/application/helpers/recipe-helpers.rb +0 -5
- data/lib/potassium/templates/application/helpers/template-helpers.rb +0 -35
- data/lib/potassium/templates/application/recipe_template.rb +0 -23
- data/lib/potassium/templates/application/recipes/angular_admin.rb +0 -26
- data/lib/potassium/templates/application/recipes/api.rb +0 -22
- data/lib/potassium/templates/application/recipes/asks/admin.rb +0 -9
- data/lib/potassium/templates/application/recipes/asks/api.rb +0 -2
- data/lib/potassium/templates/application/recipes/asks/database.rb +0 -9
- data/lib/potassium/templates/application/recipes/asks/devise.rb +0 -10
- data/lib/potassium/templates/application/recipes/asks/i18n.rb +0 -8
- data/lib/potassium/templates/application/recipes/asks/paperclip.rb +0 -2
- data/lib/potassium/templates/application/recipes/asks/pundit.rb +0 -4
- data/lib/potassium/templates/application/recipes/aws_sdk.rb +0 -1
- data/lib/potassium/templates/application/recipes/bower.rb +0 -3
- data/lib/potassium/templates/application/recipes/checks/devise.rb +0 -1
- data/lib/potassium/templates/application/recipes/database.rb +0 -22
- data/lib/potassium/templates/application/recipes/dependencies/admin.rb +0 -3
- data/lib/potassium/templates/application/recipes/devise.rb +0 -28
- data/lib/potassium/templates/application/recipes/editorconfig.rb +0 -1
- data/lib/potassium/templates/application/recipes/git.rb +0 -9
- data/lib/potassium/templates/application/recipes/i18n.rb +0 -9
- data/lib/potassium/templates/application/recipes/paperclip.rb +0 -20
- data/lib/potassium/templates/application/recipes/production.rb +0 -3
- data/lib/potassium/templates/application/recipes/pry.rb +0 -6
- data/lib/potassium/templates/application/recipes/pundit.rb +0 -33
- data/lib/potassium/templates/application/recipes/rack-cors.rb +0 -15
- data/lib/potassium/templates/application/recipes/rbenv.rb +0 -23
- data/lib/potassium/templates/application/recipes/readme.rb +0 -2
- data/lib/potassium/templates/application/recipes/testing.rb +0 -32
- data/lib/potassium/templates/application/recipes/unicorn.rb +0 -5
- data/lib/potassium/templates/application/template.rb +0 -58
@@ -1,22 +1,28 @@
|
|
1
1
|
require 'levenshtein'
|
2
2
|
require 'inquirer'
|
3
|
-
require
|
3
|
+
require 'potassium/generators/recipe'
|
4
|
+
require 'potassium/recipe'
|
4
5
|
|
5
6
|
module Potassium::CLI
|
6
7
|
desc "Installs a new feature or library"
|
7
8
|
command :install do |c|
|
8
|
-
c.
|
9
|
+
c.switch "force",
|
10
|
+
desc: "Whether to force the recipe installation",
|
11
|
+
default_value: false
|
12
|
+
c.action do |_global_options, options, args|
|
9
13
|
if args.first.nil?
|
10
14
|
index = Ask.list('Select a recipe to install', recipe_name_list)
|
11
15
|
ARGV << recipe_name_list[index]
|
12
|
-
Potassium::RecipeGenerator
|
16
|
+
template = Potassium::RecipeGenerator
|
17
|
+
template.cli_options = options
|
18
|
+
template.start
|
19
|
+
elsif recipe_exists?(args)
|
20
|
+
template = Potassium::RecipeGenerator
|
21
|
+
template.cli_options = options
|
22
|
+
template.start
|
13
23
|
else
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
guess = guess_recipe_name(args)
|
18
|
-
puts "Oops! Sorry, that recipe doesn't exist. Were you looking for this?: #{guess}"
|
19
|
-
end
|
24
|
+
guess = guess_recipe_name(args)
|
25
|
+
puts "Oops! Sorry, that recipe doesn't exist. Were you looking for this?: #{guess}"
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -34,11 +40,19 @@ module Potassium::CLI
|
|
34
40
|
end
|
35
41
|
|
36
42
|
def self.recipe_name_list
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
43
|
+
list = []
|
44
|
+
|
45
|
+
source_root = File.expand_path('../../../recipes', __FILE__)
|
46
|
+
Dir.entries(source_root).each do |file_name|
|
47
|
+
if file_name.end_with?('.rb')
|
48
|
+
recipe_name = file_name.gsub('.rb', '')
|
49
|
+
require "potassium/recipes/#{recipe_name}"
|
50
|
+
recipe_class = Recipes.const_get(recipe_name.camelize)
|
51
|
+
list << recipe_name if recipe_class.method_defined?(:install)
|
52
|
+
end
|
41
53
|
end
|
54
|
+
|
55
|
+
list
|
42
56
|
end
|
43
57
|
|
44
58
|
def self.find_closest_recipe(recipe_list, possible_recipe)
|
@@ -1,13 +1,18 @@
|
|
1
1
|
require "rails/generators"
|
2
2
|
require "rails/generators/rails/app/app_generator"
|
3
3
|
require "inquirer"
|
4
|
+
require "potassium/recipe"
|
4
5
|
|
5
6
|
module Potassium
|
6
7
|
class ApplicationGenerator < Rails::Generators::AppGenerator
|
8
|
+
class << self
|
9
|
+
attr_accessor :cli_options
|
10
|
+
end
|
11
|
+
|
7
12
|
def finish_template
|
8
|
-
require_relative "
|
13
|
+
require_relative "../helpers/template-dsl"
|
9
14
|
TemplateDSL.extend_dsl(self, source_path: __FILE__)
|
10
|
-
template_location = File.expand_path('
|
15
|
+
template_location = File.expand_path('../templates/application.rb', File.dirname(__FILE__))
|
11
16
|
instance_eval File.read(template_location), template_location
|
12
17
|
super
|
13
18
|
end
|
@@ -1,13 +1,22 @@
|
|
1
1
|
require "rails/generators"
|
2
2
|
require "rails/generators/rails/app/app_generator"
|
3
3
|
require "inquirer"
|
4
|
+
require "potassium/recipe"
|
5
|
+
|
6
|
+
class Rails::AppBuilder
|
7
|
+
include Rails::ActionMethods
|
8
|
+
end
|
4
9
|
|
5
10
|
module Potassium
|
6
11
|
class RecipeGenerator < Rails::Generators::NamedBase
|
12
|
+
class << self
|
13
|
+
attr_accessor :cli_options
|
14
|
+
end
|
15
|
+
|
7
16
|
def run_generator
|
8
|
-
require_relative "
|
17
|
+
require_relative "../helpers/template-dsl"
|
9
18
|
TemplateDSL.extend_dsl(self, source_path: __FILE__)
|
10
|
-
template_location = File.expand_path('
|
19
|
+
template_location = File.expand_path('../templates/recipe.rb', File.dirname(__FILE__))
|
11
20
|
instance_eval File.read(template_location), template_location
|
12
21
|
end
|
13
22
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AnswerHelpers
|
2
|
+
def answer(key, &fallback)
|
3
|
+
found = get(:answers)[key]
|
4
|
+
found.nil? ? fallback.call : found
|
5
|
+
end
|
6
|
+
|
7
|
+
def load_answers
|
8
|
+
set(:answers, extract_answers(self.class.cli_options))
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def extract_answers(options)
|
14
|
+
options.except(
|
15
|
+
"version-check", :"version-check",
|
16
|
+
"force", :force
|
17
|
+
).reduce({}) do |hash, (k, v)|
|
18
|
+
hash.merge(k => v == "none" ? nil : v)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class DockerHelpers
|
2
|
+
def initialize(compose_path)
|
3
|
+
@compose_path = compose_path
|
4
|
+
@compose = YAML.load(File.read(compose_path))
|
5
|
+
end
|
6
|
+
|
7
|
+
def add_link(target_service, linked_service)
|
8
|
+
service = @compose[target_service]
|
9
|
+
unless service['links'].is_a? Array
|
10
|
+
service['links'] = []
|
11
|
+
end
|
12
|
+
service['links'].push(linked_service)
|
13
|
+
save
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_env(target_service, variable_key, variable_value)
|
17
|
+
service = @compose[target_service]
|
18
|
+
unless service['environment'].is_a? Hash
|
19
|
+
service['environment'] = {}
|
20
|
+
end
|
21
|
+
service['environment'][variable_key] = variable_value
|
22
|
+
save
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_service(name, definition)
|
26
|
+
service = {}
|
27
|
+
service[name] = YAML.load(definition)
|
28
|
+
@compose.merge!(service)
|
29
|
+
save
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def save
|
35
|
+
File.open(@compose_path, 'w') { |f| f.write @compose.to_yaml }
|
36
|
+
end
|
37
|
+
end
|
File without changes
|
@@ -32,8 +32,7 @@ module GemHelpers
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def build_gemfile
|
35
|
-
call_gem_for_gathered_gems
|
36
|
-
fix_withespace_issues
|
35
|
+
fix_withespace_issues if call_gem_for_gathered_gems
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
@@ -42,6 +41,8 @@ module GemHelpers
|
|
42
41
|
ensure_variable(:gems, {})
|
43
42
|
gems = get(:gems)
|
44
43
|
|
44
|
+
return false if gems.empty?
|
45
|
+
|
45
46
|
base_gems = gems.delete([:base]) || []
|
46
47
|
|
47
48
|
call_gem_for_gems(base_gems)
|
@@ -51,6 +52,8 @@ module GemHelpers
|
|
51
52
|
call_gem_for_gems(env_gems)
|
52
53
|
end
|
53
54
|
end
|
55
|
+
|
56
|
+
true
|
54
57
|
end
|
55
58
|
|
56
59
|
def call_gem_for_gems(gems)
|
@@ -75,5 +78,6 @@ module GemHelpers
|
|
75
78
|
|
76
79
|
def fix_withespace_issues
|
77
80
|
gsub_file("Gemfile", /^group/, "\ngroup")
|
81
|
+
gsub_file("Gemfile", /^\n\n/, "\n")
|
78
82
|
end
|
79
83
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module ReadmeHelpers
|
2
|
+
def add_readme_section(header, section, iterpolation_values = {})
|
3
|
+
section_data = readme_section_data(header, section, iterpolation_values)
|
4
|
+
add_readme_header(header, iterpolation_values)
|
5
|
+
|
6
|
+
insert_into_readme(section_data[:header_title]) do
|
7
|
+
<<-HERE.gsub(/^ {6}/, '')
|
8
|
+
|
9
|
+
### #{section_data[:title]}
|
10
|
+
|
11
|
+
#{section_data[:body]}
|
12
|
+
HERE
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_readme_header(header, iterpolation_values = {})
|
17
|
+
header_data = readme_header_data(header, iterpolation_values)
|
18
|
+
return if read_file("README.md").match("## #{header_data[:title]}")
|
19
|
+
|
20
|
+
if header_data[:body]
|
21
|
+
insert_into_readme do
|
22
|
+
<<-HERE.gsub(/^ {8}/, '')
|
23
|
+
|
24
|
+
## #{header_data[:title]}
|
25
|
+
|
26
|
+
#{header_data[:body]}
|
27
|
+
HERE
|
28
|
+
end
|
29
|
+
else
|
30
|
+
insert_into_readme do
|
31
|
+
<<-HERE.gsub(/^ {8}/, '')
|
32
|
+
|
33
|
+
## #{header_data[:title]}
|
34
|
+
HERE
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def readme_header_data(header, iterpolation_values)
|
40
|
+
file = get_readme
|
41
|
+
header_data = file["readme"]["headers"][header.to_s]
|
42
|
+
|
43
|
+
{
|
44
|
+
title: header_data["title"],
|
45
|
+
body: interpolate_text(header_data["body"], iterpolation_values)
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def readme_section_data(header, section, iterpolation_values)
|
50
|
+
file = get_readme
|
51
|
+
header_data = file["readme"]["headers"][header.to_s]
|
52
|
+
section_data = header_data["sections"][section.to_s]
|
53
|
+
|
54
|
+
{
|
55
|
+
header_title: header_data["title"],
|
56
|
+
title: interpolate_text(section_data["title"], iterpolation_values),
|
57
|
+
body: interpolate_text(section_data["body"], iterpolation_values)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
def interpolate_text(text, iterpolation_values)
|
62
|
+
return unless text
|
63
|
+
b = binding
|
64
|
+
iterpolation_values.each { |k, v| singleton_class.send(:define_method, k) { v } }
|
65
|
+
ERB.new(text).result(b)
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_readme
|
69
|
+
file = File.expand_path("../../assets/README.yml", __FILE__)
|
70
|
+
YAML.load(File.read(file))
|
71
|
+
end
|
72
|
+
|
73
|
+
def insert_into_readme(after_text = nil, &block)
|
74
|
+
if after_text
|
75
|
+
line = "#{after_text}\n"
|
76
|
+
insert_into_file "README.md", after: line do
|
77
|
+
block.call
|
78
|
+
end
|
79
|
+
else
|
80
|
+
append_to_file "README.md" do
|
81
|
+
block.call
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -4,14 +4,22 @@ module TemplateDSL
|
|
4
4
|
require_relative './variable-helpers'
|
5
5
|
require_relative './environment-helpers'
|
6
6
|
require_relative './gem-helpers'
|
7
|
+
require_relative './docker-helpers'
|
7
8
|
require_relative './callback-helpers'
|
9
|
+
require_relative './answer-helpers'
|
10
|
+
require_relative './info-helpers'
|
11
|
+
require_relative './readme-helpers'
|
8
12
|
|
9
13
|
object.send :extend, TemplateHelpers
|
10
14
|
object.send :extend, VariableHelpers
|
11
15
|
object.send :extend, EnvironmentHelpers
|
12
16
|
object.send :extend, GemHelpers
|
13
17
|
object.send :extend, CallbackHelpers
|
18
|
+
object.send :extend, AnswerHelpers
|
19
|
+
object.send :extend, InfoHelpers
|
20
|
+
object.send :extend, ReadmeHelpers
|
14
21
|
|
15
22
|
object.send :source_path, source_path
|
23
|
+
object.load_answers
|
16
24
|
end
|
17
25
|
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module TemplateHelpers
|
2
|
+
def app_name
|
3
|
+
@app_name || app_name_from_file
|
4
|
+
end
|
5
|
+
|
6
|
+
def load_recipe(recipe_name)
|
7
|
+
@recipes ||= {}
|
8
|
+
@recipes[recipe_name] ||= get_recipe_class(recipe_name.to_sym).new(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(recipe_name)
|
12
|
+
recipe = load_recipe(recipe_name)
|
13
|
+
recipe.create
|
14
|
+
end
|
15
|
+
|
16
|
+
def ask(recipe_name)
|
17
|
+
recipe = load_recipe(recipe_name)
|
18
|
+
recipe.ask
|
19
|
+
end
|
20
|
+
|
21
|
+
def install(recipe_name)
|
22
|
+
recipe = load_recipe(recipe_name)
|
23
|
+
|
24
|
+
if !recipe.respond_to?(:installed?) || !recipe.installed? || force?
|
25
|
+
recipe.install
|
26
|
+
else
|
27
|
+
info "#{recipe_name.to_s.titleize} is already installed"
|
28
|
+
info "Use --force to force the installation"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def eval_file(source)
|
33
|
+
location = File.expand_path(find_in_source_paths(source))
|
34
|
+
unique_name = SecureRandom.hex
|
35
|
+
|
36
|
+
define_singleton_method unique_name do
|
37
|
+
instance_eval File.read(location)
|
38
|
+
end
|
39
|
+
|
40
|
+
public_send unique_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def source_path(path)
|
44
|
+
define_singleton_method :source_paths do
|
45
|
+
[File.expand_path(File.dirname(path))]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def erase_comments(file)
|
50
|
+
gsub_file file, /^\s*#[^\n]*\n/, ''
|
51
|
+
end
|
52
|
+
|
53
|
+
# TODO: Refactor to be able to reuse it and reduce the duplication and confusion.
|
54
|
+
def cut_comments(file, limit: 100)
|
55
|
+
gsub_file file, /^\s*#[^\n]*\n/ do |match|
|
56
|
+
if match.size > limit
|
57
|
+
match.partition(/[\w\W]{#{limit - 1}}/).reject(&:blank?).map do |line|
|
58
|
+
(line.size == limit - 1) ? "#{line}-" : "# #{line}"
|
59
|
+
end.join("\n")
|
60
|
+
else
|
61
|
+
match
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def file_exist?(file_path)
|
67
|
+
File.exist?(file_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def dir_exist?(dir_path)
|
71
|
+
Dir.exist?(dir_path)
|
72
|
+
end
|
73
|
+
|
74
|
+
def read_file(file_path)
|
75
|
+
fail "#{file_path} does not exist in destination" unless file_exist?(file_path)
|
76
|
+
File.read(file_path)
|
77
|
+
end
|
78
|
+
|
79
|
+
def cli_options
|
80
|
+
self.class.cli_options
|
81
|
+
end
|
82
|
+
|
83
|
+
def force?
|
84
|
+
cli_options[:force]
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def get_recipe_class(recipe_name)
|
90
|
+
require_relative "../recipes/#{recipe_name}"
|
91
|
+
Recipes.const_get(recipe_name.to_s.camelize)
|
92
|
+
end
|
93
|
+
|
94
|
+
def app_name_from_file
|
95
|
+
File.read('config/application.rb').match(/module\s(.*)/)[1].underscore.dasherize
|
96
|
+
end
|
97
|
+
end
|
File without changes
|
@@ -1,12 +1,43 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class Recipes::Admin < Rails::AppBuilder
|
2
|
+
def ask
|
3
|
+
if selected?(:authentication)
|
4
|
+
admin_mode = answer(:admin) { Ask.confirm("Do you want to use ActiveAdmin?") }
|
5
|
+
set(:admin_mode, admin_mode)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
if selected?(:admin_mode)
|
11
|
+
if selected?(:authentication)
|
12
|
+
add_active_admin
|
13
|
+
else
|
14
|
+
info "ActiveAdmin can't be installed because Devise isn't enabled."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def install
|
20
|
+
devise = load_recipe(:devise)
|
21
|
+
if devise.installed?
|
22
|
+
add_active_admin
|
23
|
+
else
|
24
|
+
info "ActiveAdmin can't be installed because Devise isn't installed."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def installed?
|
29
|
+
gem_exists?(/activeadmin/)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def add_active_admin
|
3
35
|
gather_gem 'activeadmin', github: 'activeadmin'
|
4
36
|
gather_gem 'activeadmin_addons'
|
5
37
|
gather_gem 'active_skin'
|
6
38
|
|
7
39
|
after(:gem_install, wrap_in_action: :admin_install) do
|
8
40
|
generate "active_admin:install"
|
9
|
-
|
10
41
|
line = "ActiveAdmin.setup do |config|"
|
11
42
|
initializer = "config/initializers/active_admin.rb"
|
12
43
|
gsub_file initializer, /(#{Regexp.escape(line)})/mi do |_match|
|
@@ -24,7 +55,6 @@ if selected?(:admin_mode)
|
|
24
55
|
|
25
56
|
line = "@import \"active_admin/base\";"
|
26
57
|
style = "app/assets/stylesheets/active_admin.css.scss"
|
27
|
-
|
28
58
|
style = File.exist?(style) ? style : "app/assets/stylesheets/active_admin.scss"
|
29
59
|
|
30
60
|
gsub_file style, /(#{Regexp.escape(line)})/mi do |_match|
|
@@ -38,8 +68,8 @@ if selected?(:admin_mode)
|
|
38
68
|
@import "active_skin";
|
39
69
|
HERE
|
40
70
|
end
|
71
|
+
|
72
|
+
generate "activeadmin_addons:install"
|
41
73
|
end
|
42
|
-
else
|
43
|
-
say "ActiveAdmin can't be installed because Devise isn't enabled.", :red
|
44
74
|
end
|
45
75
|
end
|