sprout 0.3.35
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprout might be problematic. Click here for more details.
- data/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +9 -0
- data/bin/sprout +167 -0
- data/lib/command.rb +29 -0
- data/lib/file_target.rb +8 -0
- data/lib/generate.rb +37 -0
- data/lib/library.rb +18 -0
- data/lib/log.rb +46 -0
- data/lib/platform.rb +110 -0
- data/lib/progress_bar.rb +314 -0
- data/lib/project.rb +10 -0
- data/lib/project_model.rb +59 -0
- data/lib/remote_file_loader.rb +186 -0
- data/lib/remote_file_target.rb +44 -0
- data/lib/sprout.rb +340 -0
- data/lib/sprout/version.rb +9 -0
- data/lib/task.rb +20 -0
- data/lib/template.rb +37 -0
- data/lib/template_resolver.rb +204 -0
- data/lib/tool.rb +18 -0
- data/lib/user.rb +234 -0
- data/rakefile.rb +146 -0
- data/setup.rb +1585 -0
- metadata +105 -0
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 Pattern Park
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/bin/sprout
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Luke Bayes on 2007-4-29.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'optparse'
|
13
|
+
#require 'sprout'
|
14
|
+
require File.dirname(__FILE__) + '/../lib/sprout'
|
15
|
+
include PatternPark
|
16
|
+
|
17
|
+
OPTIONS = {
|
18
|
+
:locations => [],
|
19
|
+
:project_name => nil,
|
20
|
+
:found_project_name => nil,
|
21
|
+
:sprout_name => nil,
|
22
|
+
:update => false,
|
23
|
+
:update => false,
|
24
|
+
:clean => false
|
25
|
+
}
|
26
|
+
|
27
|
+
MANDATORY_OPTIONS = %w( sprout_name )
|
28
|
+
|
29
|
+
parser = OptionParser.new do |opts|
|
30
|
+
opts.banner = <<BANNER
|
31
|
+
Sprouts is an open-source, cross-platform project generation and configuration tool
|
32
|
+
If you would like to edit or remove installed sprout contents or definitions,
|
33
|
+
simply navigate to the following location:
|
34
|
+
|
35
|
+
#{User.application_home(:sprouts)}
|
36
|
+
|
37
|
+
Usage: #{File.basename($0)} [options]
|
38
|
+
|
39
|
+
Options are:
|
40
|
+
BANNER
|
41
|
+
opts.separator ""
|
42
|
+
opts.on("-s", "--sprout=NAME", String,
|
43
|
+
"The name of the sprout to create (e.g., as2 as3, haxe, or mxml)"
|
44
|
+
) do |name|
|
45
|
+
OPTIONS[:sprout_name] = name
|
46
|
+
end
|
47
|
+
opts.on("-l", "--locations=URL[,URL2,URL3]", String,
|
48
|
+
"Insert url(s) into the http search path for sprout definitions"
|
49
|
+
) do |name|
|
50
|
+
OPTIONS[:locations] = name.split(',')
|
51
|
+
end
|
52
|
+
opts.on("-f", "--force",
|
53
|
+
"Force project creation, overwrite if necessary"
|
54
|
+
) do |force|
|
55
|
+
OPTIONS[:force] = force
|
56
|
+
end
|
57
|
+
opts.on("-u", "--update",
|
58
|
+
"Update the local versions of all referenced sprouts"
|
59
|
+
) do
|
60
|
+
OPTIONS[:update] = true
|
61
|
+
end
|
62
|
+
opts.on("-h", "--help",
|
63
|
+
"Show this help message.") { puts opts; exit }
|
64
|
+
opts.parse!(ARGV)
|
65
|
+
|
66
|
+
OPTIONS[:project_name] = ARGV.pop
|
67
|
+
|
68
|
+
if(OPTIONS[:sprout_name].nil?)
|
69
|
+
puts "\n[ERROR] You MUST provide a sprout name.\n\n"
|
70
|
+
end
|
71
|
+
|
72
|
+
if(OPTIONS[:sprout_name] && !OPTIONS[:project_name])
|
73
|
+
dir = Sprout.project_path
|
74
|
+
begin
|
75
|
+
rakefile = Sprout.rakefile
|
76
|
+
if(!rakefile.nil? && File.exists?(rakefile))
|
77
|
+
require rakefile
|
78
|
+
name = ProjectModel.instance.project_name
|
79
|
+
end
|
80
|
+
rescue LoadError
|
81
|
+
name = File.basename(File.dirname(dir))
|
82
|
+
end
|
83
|
+
puts "\n[WARNING] No project name specified, Do you want to use '#{name}' as the project name and install the #{OPTIONS[:sprout_name]} sprout into #{dir}? [Yn]\n\n"
|
84
|
+
answer = $stdin.gets.chomp
|
85
|
+
if(answer.downcase != "y" && answer != "")
|
86
|
+
puts opts; exit
|
87
|
+
end
|
88
|
+
OPTIONS[:found_project_name] = name
|
89
|
+
end
|
90
|
+
|
91
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
92
|
+
puts opts; puts ''; exit
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
#############################################
|
97
|
+
|
98
|
+
sprout_name = OPTIONS[:sprout_name]
|
99
|
+
project_name = OPTIONS[:project_name]
|
100
|
+
found_project_name = OPTIONS[:found_project_name]
|
101
|
+
locations = OPTIONS[:locations]
|
102
|
+
update = OPTIONS[:update]
|
103
|
+
clean = OPTIONS[:clean]
|
104
|
+
|
105
|
+
#############################################
|
106
|
+
|
107
|
+
# Add the provided locations to the sprout search path
|
108
|
+
if(locations.size > 0)
|
109
|
+
Sprout.insert_locations(OPTIONS[:locations])
|
110
|
+
end
|
111
|
+
|
112
|
+
if(update)
|
113
|
+
Sprout.update = true
|
114
|
+
msg = <<EOF
|
115
|
+
[WARNING] Are you sure you want to clobber all local sprout definitions referenced by "#{sprout_name}"? [Yn]
|
116
|
+
EOF
|
117
|
+
puts msg
|
118
|
+
response = gets.chomp!
|
119
|
+
if(response != '' && response.downcase != 'y')
|
120
|
+
exit
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# Create a new named Project
|
125
|
+
if(sprout_name && project_name)
|
126
|
+
path = File.join(Sprout.project_path, project_name)
|
127
|
+
Sprout.project_path = path
|
128
|
+
if(File.exists?(path))
|
129
|
+
if(OPTIONS[:force])
|
130
|
+
FileUtils.rm_rf(path)
|
131
|
+
else
|
132
|
+
puts "[WARNING] Are you sure you want to destroy #{path} and all of it's contents? [Yn]"
|
133
|
+
result = gets.chomp!
|
134
|
+
if(result.downcase == 'y' || result == '')
|
135
|
+
FileUtils.rm_rf(path)
|
136
|
+
else
|
137
|
+
puts "[ERROR] Folder already exists at: #{path}, remove it or use -f to force project creation."
|
138
|
+
exit
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
FileUtils.makedirs(path)
|
143
|
+
str = ''
|
144
|
+
80.times do
|
145
|
+
str += '-'
|
146
|
+
end
|
147
|
+
puts str
|
148
|
+
puts ">> Creating Sprout #{sprout_name} at #{path}"
|
149
|
+
Sprout.project_name = project_name
|
150
|
+
TemplateResolver.instance.replace_all = true
|
151
|
+
sprout = Sprout.load(sprout_name)
|
152
|
+
sprout.execute
|
153
|
+
end
|
154
|
+
|
155
|
+
if(sprout_name && !project_name)
|
156
|
+
sprout = Sprout.load(sprout_name)
|
157
|
+
sprout.execute
|
158
|
+
end
|
159
|
+
|
160
|
+
# Resolve the sprout within the current project
|
161
|
+
if(found_project_name && update && sprout_name)
|
162
|
+
Sprout.project_name = found_project_name
|
163
|
+
sprout = Sprout.load(sprout_name)
|
164
|
+
sprout.execute
|
165
|
+
end
|
166
|
+
|
167
|
+
Log.flush
|
data/lib/command.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module PatternPark
|
3
|
+
|
4
|
+
class Command < Task
|
5
|
+
|
6
|
+
def type
|
7
|
+
return 'command'
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
dependencies.each do |dep|
|
12
|
+
dep.execute
|
13
|
+
end
|
14
|
+
# Create a project relevant pointer to this command instance
|
15
|
+
if(target.project_path && target.project_path != '')
|
16
|
+
to = File.join(Sprout.project_path, target.project_path)
|
17
|
+
FileUtils.makedirs(File.dirname(to))
|
18
|
+
File.open(to, 'w') do |file|
|
19
|
+
file.puts("PatternPark::Sprout.load('#{name}')")
|
20
|
+
file.puts("require 'command/#{name}'")
|
21
|
+
end
|
22
|
+
generate = File.join(Sprout.project_path, 'script', 'generate')
|
23
|
+
if(File.exists?(generate))
|
24
|
+
FileUtils.chmod(0755, generate)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/file_target.rb
ADDED
data/lib/generate.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
module PatternPark
|
3
|
+
|
4
|
+
class Generate
|
5
|
+
|
6
|
+
def self.new(args)
|
7
|
+
begin
|
8
|
+
if(args.size == 0)
|
9
|
+
raise UsageError.new('[ERROR] Generate requires at least one argument')
|
10
|
+
end
|
11
|
+
name = args.shift
|
12
|
+
path = Generate.command_path(name)
|
13
|
+
require path
|
14
|
+
cmd = eval(name.capitalize + "Command").new(args)
|
15
|
+
Log.flush
|
16
|
+
return cmd
|
17
|
+
rescue UsageError => e
|
18
|
+
puts e.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.command_path(name)
|
23
|
+
file = name + "_command.rb"
|
24
|
+
path = File.join(Sprout.project_path, 'script', 'command', file)
|
25
|
+
if(File.exists?(path))
|
26
|
+
return path
|
27
|
+
end
|
28
|
+
path = File.join(Sprout.cache, 'command', file)
|
29
|
+
puts "trying: " + path
|
30
|
+
if(File.exists?(path))
|
31
|
+
return path
|
32
|
+
end
|
33
|
+
raise UsageError.new("[ERROR] Generate could not find command named '#{file}'")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/library.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
module PatternPark
|
3
|
+
|
4
|
+
class Library < Sprout
|
5
|
+
|
6
|
+
def type
|
7
|
+
return 'library'
|
8
|
+
end
|
9
|
+
|
10
|
+
def execute
|
11
|
+
super
|
12
|
+
from = target.install_path
|
13
|
+
to = File.join(Sprout.project_path, target.project_path)
|
14
|
+
FileUtils.makedirs(to)
|
15
|
+
TemplateResolver.instance.copy_files(from, to, render)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/log.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
module PatternPark
|
3
|
+
|
4
|
+
class Log
|
5
|
+
@@debug = false
|
6
|
+
@@output = ''
|
7
|
+
@@printout = ''
|
8
|
+
|
9
|
+
def Log.debug=(debug)
|
10
|
+
@@debug = debug
|
11
|
+
end
|
12
|
+
|
13
|
+
def Log.debug
|
14
|
+
return @@debug
|
15
|
+
end
|
16
|
+
|
17
|
+
def Log.puts(msg)
|
18
|
+
@@output << msg + "\n"
|
19
|
+
Log.flush
|
20
|
+
end
|
21
|
+
|
22
|
+
def Log.print(msg)
|
23
|
+
@@printout << msg
|
24
|
+
Log.flush_print
|
25
|
+
end
|
26
|
+
|
27
|
+
def Log.printf(msg)
|
28
|
+
@@printout << msg
|
29
|
+
Log.flush_print
|
30
|
+
end
|
31
|
+
|
32
|
+
def Log.flush_print
|
33
|
+
if(!Log.debug)
|
34
|
+
$stdout.print @@printout
|
35
|
+
@@printout = ''
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def Log.flush
|
40
|
+
if(!Log.debug)
|
41
|
+
$stdout.puts @@output
|
42
|
+
@@output = ''
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/platform.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#
|
2
|
+
# platform.rb: naive platform detection for Ruby
|
3
|
+
# author: Matt Mower <self@mattmower.com>
|
4
|
+
#
|
5
|
+
|
6
|
+
# == Platform
|
7
|
+
#
|
8
|
+
# Platform is a simple module which parses the Ruby constant
|
9
|
+
# RUBY_PLATFORM and works out the OS, it's implementation,
|
10
|
+
# and the architecture it's running on.
|
11
|
+
#
|
12
|
+
# The motivation for writing this was coming across a case where
|
13
|
+
#
|
14
|
+
# +if RUBY_PLATFORM =~ /win/+
|
15
|
+
#
|
16
|
+
# didn't behave as expected (i.e. on powerpc-darwin-8.1.0)
|
17
|
+
#
|
18
|
+
# It is hoped that providing a library for parsing the platform
|
19
|
+
# means that we can cover all the cases and have something which
|
20
|
+
# works reliably 99% of the time.
|
21
|
+
#
|
22
|
+
# Please report any anomalies or new combinations to the author(s).
|
23
|
+
#
|
24
|
+
# == Use
|
25
|
+
#
|
26
|
+
# require "platform"
|
27
|
+
#
|
28
|
+
# defines
|
29
|
+
#
|
30
|
+
# Platform::OS (:unix,:win32,:vms,:os2)
|
31
|
+
# Platform::impl (:macosx,:linux,:mswin)
|
32
|
+
# Platform::arch (:powerpc,:x86,:alpha)
|
33
|
+
#
|
34
|
+
# if an unknown configuration is encountered any (or all) of
|
35
|
+
# these constant may have the value :unknown.
|
36
|
+
#
|
37
|
+
# To display the combination for your setup run
|
38
|
+
#
|
39
|
+
# ruby platform.rb
|
40
|
+
#
|
41
|
+
module Platform
|
42
|
+
os = nil
|
43
|
+
impl = nil
|
44
|
+
arch = nil
|
45
|
+
|
46
|
+
if RUBY_PLATFORM =~ /darwin/i
|
47
|
+
os = :unix
|
48
|
+
impl = :macosx
|
49
|
+
elsif RUBY_PLATFORM =~ /linux/i
|
50
|
+
os = :unix
|
51
|
+
impl = :linux
|
52
|
+
elsif RUBY_PLATFORM =~ /freebsd/i
|
53
|
+
os = :unix
|
54
|
+
impl = :freebsd
|
55
|
+
elsif RUBY_PLATFORM =~ /netbsd/i
|
56
|
+
os = :unix
|
57
|
+
impl = :netbsd
|
58
|
+
elsif RUBY_PLATFORM =~ /vista/i
|
59
|
+
os = :win32
|
60
|
+
impl = :vista
|
61
|
+
elsif RUBY_PLATFORM =~ /mswin/i
|
62
|
+
os = :win32
|
63
|
+
impl = :mswin
|
64
|
+
elsif RUBY_PLATFORM =~ /cygwin/i
|
65
|
+
os = :unix
|
66
|
+
impl = :cygwin
|
67
|
+
elsif RUBY_PLATFORM =~ /mingw/i
|
68
|
+
os = :win32
|
69
|
+
impl = :mingw
|
70
|
+
elsif RUBY_PLATFORM =~ /bccwin/i
|
71
|
+
os = :win32
|
72
|
+
impl = :bccwin
|
73
|
+
elsif RUBY_PLATFORM =~ /wince/i
|
74
|
+
os = :win32
|
75
|
+
impl = :wince
|
76
|
+
elsif RUBY_PLATFORM =~ /vms/i
|
77
|
+
os = :vms
|
78
|
+
impl = :vms
|
79
|
+
elsif RUBY_PLATFORM =~ /os2/i
|
80
|
+
os = :os2
|
81
|
+
impl = :os2 # maybe there is some better choice here?
|
82
|
+
else
|
83
|
+
os = :unknown
|
84
|
+
impl = :unknown
|
85
|
+
end
|
86
|
+
|
87
|
+
# whither AIX, SOLARIS, and the other unixen?
|
88
|
+
|
89
|
+
if RUBY_PLATFORM =~ /(i\d86)/i
|
90
|
+
arch = :x86
|
91
|
+
elsif RUBY_PLATFORM =~ /ia64/i
|
92
|
+
arch = :ia64
|
93
|
+
elsif RUBY_PLATFORM =~ /powerpc/i
|
94
|
+
arch = :powerpc
|
95
|
+
elsif RUBY_PLATFORM =~ /alpha/i
|
96
|
+
arch = :alpha
|
97
|
+
else
|
98
|
+
arch = :unknown
|
99
|
+
end
|
100
|
+
|
101
|
+
OS = os
|
102
|
+
IMPL = impl
|
103
|
+
ARCH = arch
|
104
|
+
# What about AMD, Turion, Motorola, etc..?
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
if __FILE__ == $0
|
109
|
+
puts "Platform OS=#{Platform::OS}, impl=#{Platform::IMPL}, arch=#{Platform::ARCH}"
|
110
|
+
end
|