Class: Teapot::Command::Create
- Inherits:
- 
      Samovar::Command
      
        - Object
- Samovar::Command
- Teapot::Command::Create
 
- Defined in:
- lib/teapot/command/create.rb
Instance Method Summary collapse
Instance Method Details
#generate_project(root, name, source, packages) ⇒ Object
| 82 83 84 85 86 87 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/teapot/command/create.rb', line 82 def generate_project(root, name, source, packages) name = ::Build::Name.new(name) # Otherwise the initial commit will try to include teapot/ File.open(root + ".gitignore", "w") do |output| output.puts "teapot/" end # A very basic teapot file to pull in the initial dependencies. File.open(root + TEAPOT_FILE, "w") do |output| output.puts "\# Teapot v#{VERSION} configuration generated at #{Time.now.to_s}", '' output.puts "required_version #{LOADER_VERSION.dump}", '' output.puts "define_project #{name.target.dump} do |project|" output.puts "\tproject.title = #{name.text.dump}" output.puts "end", '' output.puts "\# Build Targets", '' output.puts "\# Configurations", '' output.puts "define_configuration 'development' do |configuration|" output.puts "\tconfiguration[:source] = #{source.dump}" output.puts "\tconfiguration.import #{name.target.dump}" packages.each do |name| output.puts "\tconfiguration.require #{name.dump}" end output.puts "end", '' output.puts "define_configuration #{name.target.dump} do |configuration|" output.puts "\tconfiguration.public!" output.puts "end" end end | 
#invoke ⇒ Object
| 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 | # File 'lib/teapot/command/create.rb', line 36 def invoke logger = parent.logger nested = parent['--root', parent.[:root] || name.gsub(/\s+/, '-').downcase] root = nested.root if root.exist? raise ArgumentError.new("#{root} already exists!") end # Create and set the project root: root.create repository = Rugged::Repository.init_at(root.to_s) logger.info "Creating project named #{name} at path #{root}..." generate_project(root, @name, @source, @packages) # Fetch the initial packages: Fetch[parent: nested].invoke context = nested.context selection = context.select target_names = selection.configuration.targets[:create] if target_names.any? # Generate the initial project files: Build[*target_names, parent: nested].invoke # Fetch any additional packages: Fetch[parent: nested].invoke end # Stage all files: index = repository.index index.add_all # Commit the initial project files: Rugged::Commit.create(repository, tree: index.write_tree(repository), message: "Initial project files.", parents: repository.empty? ? [] : [repository.head.target].compact, update_ref: 'HEAD' ) end |