-
-
Notifications
You must be signed in to change notification settings - Fork 627
/
install_generator.rb
97 lines (87 loc) · 3.55 KB
/
install_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require "rails/generators"
module ReactOnRails
module Generators
class InstallGenerator < Rails::Generators::Base
# --redux
class_option :redux,
type: :boolean,
default: false,
desc: "Install Redux gems and Redux version of Hello World Example",
aliases: "-R"
# --server-rendering
class_option :server_rendering,
type: :boolean,
default: false,
desc: "Add necessary files and configurations for server-side rendering",
aliases: "-S"
# --skip-js-linters
class_option :skip_js_linters,
type: :boolean,
default: false,
desc: "Skip installing JavaScript linting files",
aliases: "-j"
# --ruby-linters
class_option :ruby_linters,
type: :boolean,
default: false,
desc: "Install ruby linting files, tasks, and configs",
aliases: "-L"
# --ruby-linters
class_option :heroku_deployment,
type: :boolean,
default: false,
desc: "Install files necessary for deploying to Heroku",
aliases: "-H"
# --bootstrap
class_option :bootstrap,
type: :boolean,
default: true,
desc: "Integrate Bootstrap, initialize files and regarding configs",
aliases: "-B"
def run_generators # rubocop:disable Metrics/CyclomaticComplexity
return unless installation_prerequisites_met?
warn_if_nvm_is_not_installed
invoke_generators
end
private
def invoke_generators # rubocop:disable Metrics/CyclomaticComplexity
invoke "react_on_rails:base"
invoke "react_on_rails:react_no_redux" unless options.redux?
invoke "react_on_rails:react_with_redux" if options.redux?
invoke "react_on_rails:js_linters" unless options.skip_js_linters?
invoke "react_on_rails:ruby_linters" if options.ruby_linters?
invoke "react_on_rails:heroku_deployment" if options.heroku_deployment?
invoke "react_on_rails:bootstrap" if options.bootstrap?
end
# NOTE: other requirements for existing files such as .gitignore or application.
# js(.coffee) are not checked by this method, but instead produce warning messages
# and allow the build to continue
def installation_prerequisites_met?
!(missing_node? || missing_npm? || uncommitted_changes?)
end
def missing_npm?
return false unless `which npm`.blank?
error = "** npm is required. Please install it before continuing."
error << "https://www.npmjs.com/"
puts error
end
def missing_node?
return false unless `which node`.blank?
error = "** nodejs is required. Please install it before continuing."
error << "https://nodejs.org/en/"
puts error
end
def uncommitted_changes?
return false if ENV["COVERAGE"]
status = `git status`
return false if status.include?("nothing to commit, working directory clean")
error = "** You have uncommitted code. Please commit or stash your changes before continuing"
puts error
end
def warn_if_nvm_is_not_installed
return true unless `which nvm`.blank?
puts "** nvm is advised. Please consider installing it. https://github.com/creationix/nvm"
end
end
end
end