Sha256: 4117931aa67573ea4ffd5bd28a9afb1a6914e962b77f7b1fb5aa4981212bbba9

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'mwc/utils/command'
require 'mwc'

module Mwc
  module Commands
    # Create a new project
    class Init < Thor::Group
      include Thor::Actions
      include Utils::Command

      name 'init'
      usage 'init NAME'
      description 'create a new project'
      display_on { !Mwc.config.exist? }
      argument :name, type: :string, desc: 'project name'

      def create_project
        directory('app', name)
        self.destination_root = name
        Mwc.root = destination_root
      end

      # :nodoc:
      def create_mwcrc
        template('mwcrc.erb', '.mwcrc')
        Mwc.config = Pathname.new(destination_root).join('.mwcrc')
      end

      # :nodoc:
      def download_mruby
        # TODO: Allow choose download mode
        empty_directory('vendor')
        inside(mruby_directory.dirname) do
          run("curl -OL #{archive_url}")
          run("tar -zxf #{filename}")
          remove_file(filename)
          run("mv mruby-#{version} #{mruby_directory}")
        end
      end

      private

      # :nodoc:
      def version
        Mwc.mruby.version
      end

      # :nodoc:
      def archive_url
        "https://github.com/mruby/mruby/archive/#{filename}"
      end

      # :nodoc:
      def filename
        "#{version}.tar.gz"
      end

      # :nodoc:
      def mruby_directory
        Mwc.mruby.path
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mwc-0.4.0 lib/mwc/commands/init.rb
mwc-0.3.0 lib/mwc/commands/init.rb