Sha256: 55b17212a5f7d86ab8e3748a3712e6a1f8464b80c4da1bba0f095cae59649232

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

command = ARGV[0]

error(%%
No command specified, please use one of the following
  new:     start a new project
  update:  update mvp inside current project
%) unless command

case command.downcase
when 'new'
  project = if ARGV[1]
    ARGV[1]
  else
    $stdin.reopen(File.open("/dev/tty", "r"))
    print "Project name? "
    STDIN.gets.chomp
  end

  error('Must specify a project name') if project == ""

  slug = slugify(project)

  puts
  run "cp -r #{File.dirname(__FILE__)}/../project #{slug}"

  puts
  puts "\n== Initializing Project =="
  files = Dir.glob("#{slug}/**/*").select { |f| File.file?(f) }
  files.each do |file_name|
    begin
      text = File.read(file_name)
      new_contents = text.gsub(/__PROJECT_NAME__/, project)
                         .gsub(/__PROJECT_NAME_SLUG__/, slug)

      File.open(file_name, "w") {|file| file.puts new_contents }
    rescue

    end
  end
  run "cd #{slug} && rm -rf .git && git init"

  run "cd #{slug}; bin/setup", "\n== Project Setup"

when 'update'
  run "bundle update minimum_viable_product"
  # npm has a bug where it won't update new dependencies
  # https://github.com/npm/npm/issues/1341
  run "rm -rf node_modules; npm install"
when '-v','version'
  version = File.read(File.dirname(__FILE__) + '/../VERSION')
  puts "Version #{version}"
end

BEGIN {
  def slugify(name)
    slug = name.gsub(/'/, '').gsub(/[^a-z0-9]+/, '_')
    slug.chop! if slug[-1] == '-'
    slug
  end

  def error(message)
    puts
    puts "Error: #{message}"
    exit 1
  end

  def run(cmd, message=nil)
    if message
      puts
      puts message
    end

    system cmd
  end
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mvpkit-1.1.2 bin/mvp
mvpkit-1.1.1 bin/mvp
mvpkit-1.1.0 bin/mvp
mvpkit-1.0.4 bin/mvp
mvpkit-1.0.3 bin/mvp
mvpkit-1.0.2 bin/mvp
mvpkit-1.0.1 bin/mvp
mvpkit-1.0.0 bin/mvp