forked from lukebayes/project-sprouts
/
sprout.rb
132 lines (112 loc) · 3.2 KB
/
sprout.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
lib = File.expand_path File.dirname(__FILE__)
$:.unshift lib unless $:.include?(lib)
# External tools and std libs:
require 'rake'
require 'delegate'
require 'logger'
# Core, Process and Platform support:
require 'sprout/version'
require 'sprout/output_buffer'
require 'sprout/progress_bar'
require 'sprout/dir'
require 'sprout/string'
require 'sprout/errors'
require 'sprout/platform'
require 'sprout/process_runner'
require 'sprout/system'
require 'sprout/concern'
require 'sprout/ruby_feature'
##
# This is a fix for Issue #106
# http://code.google.com/p/projectsprouts/issues/detail?id=106
# Which is created because the new version (1.0.1) of RubyGems
# includes open-uri, while older versions do not.
# When open-uri is included twice, we get a bunch of nasty
# warnings because constants are being overwritten.
gem_version = Gem::Version.new(Gem::RubyGemsVersion)
if(gem_version != Gem::Version.new('1.0.1'))
require 'open-uri'
end
# File, Archive and Network support:
require 'sprout/archive_unpacker'
require 'sprout/file_target'
require 'sprout/remote_file_loader'
require 'sprout/remote_file_target'
# External Packaging and distribution support:
require 'sprout/rdoc_parser'
require 'sprout/specification'
require 'sprout/executable'
require 'sprout/command_line'
# Generators
require 'sprout/generator'
# Libraries
require 'sprout/library'
module Sprout
class << self
##
# @return [Dir] The system-specific path to the writeable cache directory
# where Sprouts will look for downloaded archives.
#
# puts ">> Sprout Cache: #{Sprout.cache}"
#
def cache
File.join(home, 'cache')
end
##
# @return [Dir] The location where the currently-running version of Sprouts
# will write files and generators and their templates.
#
# puts ">> Sprout home: #{Sprout.home}"
#
def home
File.join(current_system.application_home('sprouts'), Sprout::VERSION::MAJOR_MINOR)
end
##
# @return [Dir] The location where Sprouts will look for generators and their
# templates.
#
# puts ">> Generator Cache: #{Sprout.generator_cache}"
#
def generator_cache
File.join cache, 'generators'
end
##
# @return [Sprout::System] That is currently being used to
# determine features like the cache path and how external processes
# are executed.
#
# system = Sprout.current_system
# puts ">> System: #{system.inspect}"
#
def current_system
Sprout::System.create
end
def stdout=(out)
@stdout = out
end
def stdout
@stdout ||= $stdout
end
def stderr=(err)
@stderr = err
end
def stderr
@stderr ||= $stderr
end
##
# @return [File] Path to the file from the 'caller' property of
# a Ruby exception.
#
# Note: It's a real bummer that this string is colon delimited -
# The value on Windows often includes a colon...
# Once again, Windows is dissed by fundamental Ruby decisions.
def file_from_caller caller_string
parts = caller_string.split(':')
str = parts.shift
while(parts.size > 0 && !File.exists?(str))
str << ":#{parts.shift}"
end
str
end
end
end