Class: Commands::Create

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/nextgen/commands/create.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

RESERVED_NAMES =
%w[application destroy plugin runner test].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_path, _options) ⇒ Create

Returns a new instance of Create.



23
24
25
26
# File 'lib/nextgen/commands/create.rb', line 23

def initialize(app_path, _options)
  @app_path = File.expand_path(app_path)
  @app_name = File.basename(@app_path).gsub(/\W/, "_").squeeze("_").camelize
end

Class Method Details

.run(app_path, options) ⇒ Object



19
20
21
# File 'lib/nextgen/commands/create.rb', line 19

def self.run(app_path, options)
  new(app_path, options).run
end

Instance Method Details

#runObject

rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity



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
98
99
100
101
102
103
104
105
# File 'lib/nextgen/commands/create.rb', line 28

def run # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
  reserved_word_message if app_name_is_reserved_word?

  say <<~BANNER
    Welcome to nextgen, the interactive Rails app generator!

    You are about to create a Rails app named "#{cyan(app_name)}" in the following directory:

      #{cyan(app_path)}

    You'll be asked ~10 questions about database, test framework, and other options.
    The standard Rails "omakase" experience will be selected by default.

  BANNER

  continue_if "Ready to start?"

  rails_version = ask_rails_version
  @rails_opts = RailsOptions.new(version: rails_version)

  ask_database
  ask_full_stack_or_api
  ask_frontend_management unless rails_opts.api?
  ask_css unless rails_opts.api? || rails_opts.skip_asset_pipeline?
  ask_javascript unless rails_opts.api? || rails_opts.skip_asset_pipeline?
  ask_rails_features
  ask_rails_frameworks
  ask_test_framework
  ask_system_testing if rails_opts.frontend? && rails_opts.test_framework?
  reload_generators
  ask_optional_enhancements
  ask_js_package_manager if node?
  reload_generators

  say <<~SUMMARY

    OK! Your Rails app is ready to be created.
    The following options will be passed to `rails new`:

      #{rails_new_args.join("\n  ")}

    The following nextgen enhancements will also be applied in individual git commits via `rails app:template`:

      #{selected_generators.join(", ").scan(/\S.{0,75}(?:,|$)/).join("\n  ")}

  SUMMARY

  if node?
    say <<~NODE
      Based on the options you selected, your app will require a JavaScript runtime. For reference, you are using:

        node: #{capture_version("node")}
        yarn: #{capture_version("yarn")}
        npm:  #{capture_version("npm")}

    NODE
  end

  continue_if "Continue?"

  create_initial_commit_message
  create_package_json if node?
  Nextgen::RailsCommand.run "new", *rails_new_args
  Dir.chdir(app_path) do
    Nextgen::RailsCommand.run "app:template", "LOCATION=#{write_generators_script}"
  end

  say <<~DONE.gsub(/^/, "  ")


    #{green("Done!")}

    A Rails #{rails_opts.version_label} app was generated in #{cyan(app_path)}.
    Run #{yellow("bin/setup")} in that directory to get started.


  DONE
end