Sha256: 933ec8d3c3e30d388d7eb45d979c8eb460df2050ef70af0d4f0dd14da98bb1e5

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

require 'fileutils'

module Prick::SubCommand
  def self.init(project_file, dir, name, title) # dir, name, and title can be nil
    cwd = Dir.getwd
    if dir
      !File.exist?(dir) or Prick.error "Directory #{dir} exists"
      FileUtils.mkdir_p(dir)
      Dir.chdir(dir)
    else
      dir = "."
    end
    dirname = File.basename(Dir.getwd)
    name ||= dirname
    title ||= name.gsub(/[_-]/, " ").capitalize

    # Note that the initial project file is invalid and is removed again after
    # the initial commit
    Command.command %(
      git init .
      dir=#{SHARE_PATH}/init
      for path in $dir/*; do
        source_file=$(basename $path)
        dest_file=$(sed 's/^dot\././' <<<$source_file)
        cp -a $dir/$source_file $dest_file
      done
      git add .
      git commit -am "Initial import"
      rm -f #{project_file} 
    ), fail: false
    Command.status == 0 or Prick.failure "Failed creating initial import"

    # Write (valid) configuration file
    state = State.new(project_file, nil, nil)
    state.name = name
    state.title = title
    state.prick_version = PrickVersion.new VERSION
    state.version = PrickVersion.new("0.0.0")
    state.save_project

    # Commit configuration file and create initial release
    Command.command %(
      set -e
      git add #{project_file}
      git commit -am "Release 0.0.0"
      git tag --message "Initial Release" v0.0.0
    ), fail: false
    Command.status == 0 or Prick.failure "Failed creating initial release"

    Dir.chdir(cwd)
    [dir, name]
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
prick-0.39.5 lib/prick/subcommand/prick-init.rb
prick-0.39.4 lib/prick/subcommand/prick-init.rb
prick-0.39.3 lib/prick/subcommand/prick-init.rb
prick-0.39.2 lib/prick/subcommand/prick-init.rb
prick-0.39.1 lib/prick/subcommand/prick-init.rb
prick-0.39.0 lib/prick/subcommand/prick-init.rb
prick-0.36.0 lib/prick/subcommand/prick-init.rb
prick-0.35.0 lib/prick/subcommand/prick-init.rb
prick-0.34.0 lib/prick/subcommand/prick-init.rb
prick-0.33.0 lib/prick/subcommand/prick-init.rb
prick-0.32.0 lib/prick/subcommand/prick-init.rb
prick-0.31.0 lib/prick/subcommand/prick-init.rb
prick-0.30.0 lib/prick/subcommand/prick-init.rb