Sha256: 38d81ec52cec8d8f11f96c87112728f3cd58e33e58491800fa68d4f42d60d676

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

module MiddlemanEmberScaffold
  module Generators
    class Scaffold < Thor
      include Thor::Actions
      def self.source_root
        File.expand_path(File.dirname(__FILE__), "../template")
      end

      desc "build scaffold", "Build a scaffold for a Middleman Ember Project"
      def scaffold(*args)
        destination_root=args[0]
        src = File.expand_path(File.join(File.dirname(__FILE__), "../template"))
        directory(src, destination_root)
        Dir.chdir(destination_root)
        run_bundle
        #puts 'Building scaffold....'
        #puts %x['cd #{destination_root}; middleman build']
      end



      #steal bundle command from rails app generator
      private
        def bundle_command(command)
          say_status :run, "bundle #{command}"

          # We are going to shell out rather than invoking Bundler::CLI.new(command)
          # because `mes new` loads the Thor gem and on the other hand bundler uses
          # its own vendored Thor, which could be a different version. Running both
          # things in the same process is a recipe for a night with paracetamol.
          #
          # We use backticks and #print here instead of vanilla #system because it
          # is easier to silence stdout in the existing test suite this way. The
          # end-user gets the bundler commands called anyway, so no big deal.
          #
          # We unset temporary bundler variables to load proper bundler and Gemfile.
          #
          # Thanks to James Tucker for the Gem tricks involved in this call.
          _bundle_command = Gem.bin_path('bundler', 'bundle')

          require 'bundler'
          Bundler.with_clean_env do
            print `"#{Gem.ruby}" "#{_bundle_command}" #{command}`
          end
        end

        def run_bundle
          bundle_command('install')
        end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mes-0.3.0 lib/middleman_ember_scaffold/generators/scaffold.rb
mes-0.2.3 lib/middleman_ember_scaffold/generators/scaffold.rb