Class: Ronin::Web::CLI::Commands::New::Webapp Private

Inherits:
Ronin::Web::CLI::Command show all
Includes:
Core::CLI::Generator
Defined in:
lib/ronin/web/cli/commands/new/webapp.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Generate a new ronin-web-server based webapp.

Usage

ronin-web new webapp [options] DIR

Options

    --port PORT                  The port the webpp will listen on by default (Default: 3000)
    --ruby-version VERSION       The desired ruby version for the project (Default: 3.1.3)
    --git                        Initializes a git repo
-D, --dockerfile                 Adds a Dockerfile to the new project
-h, --help                       Print help information

Arguments

DIR                              The directory to create

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

#run(path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-web new webapp command.

Parameters:

  • path (String)

    The path to the new project directory to create.

Since:

  • 1.0.0



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/ronin/web/cli/commands/new/webapp.rb', line 88

def run(path)
  @ruby_version = options[:ruby_version]
  @port         = options[:port]

  mkdir path
  mkdir File.join(path,'lib')
  mkdir File.join(path,'views')
  mkdir File.join(path,'public')

  erb '.ruby-version.erb', File.join(path,'.ruby-version')
  cp 'Gemfile', path
  erb 'app.rb.erb', File.join(path,'app.rb')
  cp 'config.ru', path

  if options[:dockerfile]
    erb 'Dockerfile.erb', File.join(path,'Dockerfile')
    erb 'docker-compose.yml.erb', File.join(path,'docker-compose.yml')
  end

  if options[:git]
    cp '.gitignore', path

    Dir.chdir(path) do
      sh 'git', 'init', '-q', '-b', 'main'
      sh 'git', 'add', '.'
      sh 'git', 'commit', '-q', '-m', 'Initial commit.'
    end
  end
end