class Teapot::Command::Create

Public Instance Methods

call() click to toggle source
# File lib/teapot/command/create.rb, line 36
def call
        logger = parent.logger
        
        nested = parent['--root', parent.options[: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].call
        
        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].call
                
                # Fetch any additional packages:
                Fetch[parent: nested].call
        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
generate_project(root, name, source, packages) click to toggle source
# 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