Class: WritersRoom::Commands::Init

Inherits:
Thor
  • Object
show all
Defined in:
lib/writers_room/cli/init.rb

Instance Method Summary collapse

Instance Method Details

#init(project_name) ⇒ Object



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
# File 'lib/writers_room/cli/init.rb', line 28

def init(project_name)
  require_relative "../producer"

  project_path = File.join(Dir.pwd, project_name)

  if File.exist?(project_path)
    say "Error: Directory '#{project_name}' already exists!", :red
    exit 1
  end

  medium_id = options[:medium]

  if medium_id.nil? || medium_id.empty?
    medium = choose_medium
  else
    begin
      medium = WritersRoom::MediumRegistry.find(medium_id)
    rescue WritersRoom::Error
      say "Error: Unknown medium '#{medium_id}'. Available: #{WritersRoom::MediumRegistry.ids.join(', ')}", :red
      exit 1
    end
  end

  medium_id = medium.id.to_s

  say "Creating WritersRoom project: #{project_name} (#{medium.label})", :green

  # Create project config file
  config_path = File.join(project_path, "config.yml")
  FileUtils.mkdir_p(project_path)

  config_data = {
    "provider" => options[:provider],
    "model_name" => options[:model]
  }
  File.write(config_path, YAML.dump(config_data))

  # Create project with metadata
  producer = WritersRoom::Producer.create_project(
    project_path,
    name: project_name,
    concept: options[:concept],
    medium: medium_id
  )

  say "Created project directory: #{project_path}", :green
  say "Created configuration: config.yml", :green
  say "Created project metadata: project.md", :green
  say "Created directories: #{medium.scaffolded_dirs.join(', ')}", :green
  say ""
  say "Configuration:", :cyan
  say "  Provider:   #{options[:provider]}", :white
  say "  Model:      #{options[:model]}", :white
  say "  Medium:     #{medium.label}", :white

  if options[:concept] && !options[:concept].empty?
    say ""
    say "Concept:", :cyan
    say "  #{producer.metadata.concept}", :white
  end

  say ""
  say "Your WritersRoom project is ready!", :green
  say ""
  say "Next steps:", :cyan
  say "  1. cd #{project_name}", :white
  say "  2. Run 'wr' to start an interactive writing session", :white
  next_steps_for_medium(medium).each_with_index do |step, i|
    say "  #{i + 3}. #{step}", :white
  end
rescue StandardError => e
  say "Error initializing project: #{e.message}", :red
  say e.backtrace.join("\n"), :red if ENV["DEBUG"]
  exit 1
end