Class: Railspack::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/railspack/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



11
12
13
# File 'lib/railspack/cli.rb', line 11

def self.source_root
  File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#generateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/railspack/cli.rb', line 17

def generate
  run_npm_install = options[:install]

  build_package_json
  copy_file("index.js", "frontend/index.js")
  copy_file("registerComponent.js", "frontend/registerComponent.js")
  copy_file("react_helper.rb", "app/helpers/react_helper.rb")
  copy_file("babelrc.js", ".babelrc")
  copy_file("webpack.js", "webpack.config.babel.js")

  if run_npm_install
    unless npm_available?
      puts "NPM is not installed, please install and then run `npm install` manually"
      return
    end

    puts "Running `npm install`"
    exec("npm install")
  end

end