Class: Bridgetown::Commands::New

Inherits:
Bridgetown::Command show all
Includes:
Automations, GitHelpers
Defined in:
bridgetown-core/lib/bridgetown-core/commands/new.rb

Constant Summary collapse

DOCSURL =
"https://bridgetownrb.com/docs"
SUPPORTED_RACK_SERVERS =
%w[falcon puma].freeze

Constants included from Automations

Automations::CODEBERG_REGEX, Automations::CODEBERG_REPO_REGEX, Automations::CODEBERG_TREE_REGEX, Automations::GITHUB_BLOB_REGEX, Automations::GITHUB_REGEX, Automations::GITHUB_REPO_REGEX, Automations::GITHUB_TREE_REGEX, Automations::GITLAB_BLOB_REGEX, Automations::GITLAB_REGEX, Automations::GITLAB_REPO_REGEX, Automations::GITLAB_TREE_REGEX

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GitHelpers

#destroy_existing_repo, #initialize_new_repo, #user_default_branch

Methods included from Automations

#add_gem, #add_initializer, #add_npm_for_gem, #add_npm_package, #apply_from_url, #create_builder, included, #javascript_import, #remove_npm_package, #ruby_configure

Methods inherited from Bridgetown::Command

command_line, start, summary

Class Attribute Details

.created_site_dirObject

Returns the value of attribute created_site_dir.



40
41
42
# File 'bridgetown-core/lib/bridgetown-core/commands/new.rb', line 40

def created_site_dir
  @created_site_dir
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'bridgetown-core/lib/bridgetown-core/commands/new.rb', line 31

def self.exit_on_failure?
  false
end

.source_rootObject



35
36
37
# File 'bridgetown-core/lib/bridgetown-core/commands/new.rb', line 35

def self.source_root
  File.expand_path("../../site_template", __dir__)
end

Instance Method Details

#callObject

rubocop:disable Metrics



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
# File 'bridgetown-core/lib/bridgetown-core/commands/new.rb', line 43

def call # rubocop:disable Metrics
  case path
  when "--help", "-help", "-h"
    print_usage
    return
  end

  self.source_paths = [self.class.source_root]

  new_site_path = File.expand_path(path, Dir.pwd)
  @site_name = new_site_path.split(File::SEPARATOR).last

  if preserve_source_location?(new_site_path, options)
    say_status :conflict, "#{new_site_path} exists and is not empty.", :red
    Bridgetown.logger.abort_with(
      "Ensure #{new_site_path} is empty or else try again with `--force` to proceed and " \
      "overwrite any files."
    )
  end

  self.destination_root = self.class.created_site_dir = new_site_path

  say_status :create, new_site_path
  create_site new_site_path
  after_install new_site_path, path, options
rescue ArgumentError => e
  say_status :alert, e.message, :red
ensure
  self.class.created_site_dir = nil # reset afterwards, otherwise hanging tmp dirs in test
end