asproject 0.1.21
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +0 -0
- data/History.txt +0 -0
- data/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +16 -0
- data/README.txt +3 -0
- data/TODO.txt +10 -0
- data/bin/asclass +16 -0
- data/bin/asproject +16 -0
- data/lib/asclass.rb +254 -0
- data/lib/asclass_arguments.rb +147 -0
- data/lib/asproject.rb +248 -0
- data/lib/asproject/version.rb +9 -0
- data/lib/asproject_arguments.rb +175 -0
- data/lib/asproject_base.rb +43 -0
- data/lib/asproject_utils.rb +57 -0
- data/lib/eclipse_project.rb +32 -0
- data/lib/path_finder.rb +286 -0
- data/lib/platform.rb +107 -0
- data/lib/project.rb +82 -0
- data/lib/template_resolver.rb +144 -0
- data/lib/test_suite_generator.rb +128 -0
- data/rakefile.rb +85 -0
- data/setup.rb +1585 -0
- data/templates/asclass/as2/Class.as +11 -0
- data/templates/asclass/as2/Component.as +8 -0
- data/templates/asclass/as2/Interface.as +3 -0
- data/templates/asclass/as2/TestCase.as +30 -0
- data/templates/asclass/as2/TestSuite.as +15 -0
- data/templates/asclass/as3/Class.as +9 -0
- data/templates/asclass/as3/Component.as +9 -0
- data/templates/asclass/as3/Component.mxml +1 -0
- data/templates/asclass/as3/Interface.as +6 -0
- data/templates/asclass/as3/TestCase.as +30 -0
- data/templates/asclass/as3/TestSuite.as +18 -0
- data/templates/asproject/as2/project/rakefile.rb +18 -0
- data/templates/asproject/as2/project/src/AsProject.as +13 -0
- data/templates/asproject/as2/project/test/AsProjectRunner.as +12 -0
- data/templates/asproject/as3/project/rakefile.rb +18 -0
- data/templates/asproject/as3/project/src/AsProject.as +9 -0
- data/templates/asproject/as3/project/src/AsProjectRunner.as +11 -0
- data/templates/asproject/asunit2/project/lib/asunit/AsUnitUi.swf +0 -0
- data/templates/asproject/asunit2/project/lib/asunit/Sys.as +70 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanel.as +182 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTest.as +84 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextArea.as +111 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextAreaTest.as +26 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTitleBar.as +81 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ResizeHandle.as +35 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollArrow.as +34 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollHandle.as +43 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollListener.as +10 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/TextScroller.as +169 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Rectangle.as +29 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Triangle.as +27 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/AsUnit.as +19 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assert.as +408 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assertion.as +27 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Reflection.as +68 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Test.as +3 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCase.as +191 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCaseXml.as +31 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestFailure.as +15 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestResult.as +15 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestRunner.as +41 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSetup.as +19 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSuite.as +22 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/Main.as +325 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/RemoteVersion.as +24 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/SuccessMeter.as +32 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Comparable.as +7 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventListener.as +29 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventSource.as +89 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnClient.as +42 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnGateway.as +47 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnServer.as +61 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as +58 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Observable.as +11 -0
- data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/TextFile.as +30 -0
- data/templates/asproject/asunit25/project/lib/asunit/AsUnitTestRunner.as +13 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionFailedError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionPassedError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/ClassNotFoundError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/IllegalOperationError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InvocationTargetError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +7 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Assert.as +376 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertMock.as +15 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertTest.as +59 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/ITestListener.as +13 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Test.as +11 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCase.as +277 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseMock.as +23 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseTest.as +29 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseXml.as +38 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestResult.as +168 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestSuite.as +102 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/BaseTestRunner.as +101 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/IResultPrinter.as +8 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/ResultPrinter.as +254 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/SuccessBar.as +41 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/TestRunner.as +17 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIterator.as +24 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIteratorTest.as +52 -0
- data/templates/asproject/asunit25/project/lib/asunit/asunit/util/Iterator.as +5 -0
- data/templates/asproject/asunit3/project/lib/asunit/AsUnitTestRunner.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AbstractMemberCalledError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AssertionFailedError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/ClassNotFoundError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +10 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Assert.as +271 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCase.as +52 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCaseExample.as +71 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Test.as +15 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCase.as +351 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCaseExample.as +73 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestFailure.as +47 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestListener.as +22 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestResult.as +158 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestSuite.as +115 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/BaseTestRunner.as +15 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/TestSuiteLoader.as +9 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/Version.as +11 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexRunner.as +19 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexTestRunner.as +55 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/ResultPrinter.as +245 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/TestRunner.as +121 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/ArrayIterator.as +26 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Iterator.as +9 -0
- data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Properties.as +30 -0
- data/templates/asproject/asunit3/project/lib/asunit/mx/managers/LayoutManager.as +945 -0
- data/templates/asproject/config/project/config/asclass_config.rb +58 -0
- data/templates/asproject/fb2as/project/.actionScriptProperties +21 -0
- data/templates/asproject/fb2as/project/.project +29 -0
- data/templates/asproject/fdt/project/.as2_classpath +6 -0
- data/templates/asproject/fdt/project/.project +19 -0
- data/templates/ide/mate/Create Class.tmCommand +37 -0
- data/templates/ide/mate/Rebuild Test Suites.tmCommand +33 -0
- data/templates/ide/mate/Run Rake Task.tmCommand +127 -0
- metadata +266 -0
data/lib/asproject.rb
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
$:.push(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'yaml'
|
5
|
+
require 'optparse'
|
6
|
+
require 'fileutils'
|
7
|
+
require 'erb'
|
8
|
+
require 'ftools'
|
9
|
+
|
10
|
+
require 'asproject/version'
|
11
|
+
require 'asproject_base'
|
12
|
+
require 'platform.rb'
|
13
|
+
require 'asproject_utils'
|
14
|
+
require 'template_resolver'
|
15
|
+
require 'path_finder'
|
16
|
+
require 'project'
|
17
|
+
require 'eclipse_project'
|
18
|
+
require 'asproject_arguments'
|
19
|
+
|
20
|
+
module AsProject
|
21
|
+
class AsProject < AsProjectBase
|
22
|
+
@@ASPROJECT_FILE_NAME = 'AsProject'
|
23
|
+
@@TEMPLATE_TYPE = 'asproject'
|
24
|
+
@@DEFAULT_TEMPLATES = ['as3', 'fb2as', 'asunit3', 'config']
|
25
|
+
|
26
|
+
def initialize(args=nil)
|
27
|
+
execute(args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute(args=nil)
|
31
|
+
begin
|
32
|
+
@should_create_project = true
|
33
|
+
@created_files = []
|
34
|
+
if(args.nil?)
|
35
|
+
@execution_dir = Dir.pwd
|
36
|
+
else
|
37
|
+
@execution_dir = args.execution_dir
|
38
|
+
@project_name = args.project_name
|
39
|
+
end
|
40
|
+
@path_finder = PathFinder.new(@execution_dir)
|
41
|
+
parse_args(args)
|
42
|
+
|
43
|
+
@resolver = AsProjectResolver.new(self)
|
44
|
+
if(@arguments.copy_to_home)
|
45
|
+
copy_templates_to_user_home
|
46
|
+
end
|
47
|
+
|
48
|
+
out '---------------------------'
|
49
|
+
begin
|
50
|
+
project = @path_finder.current_project
|
51
|
+
@should_create_project = false
|
52
|
+
msg = ">> Working in existing project #{project_name} at: " + project
|
53
|
+
rescue
|
54
|
+
if(@arguments.project_name == '')
|
55
|
+
finish
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
msg = ">> Creating a new project at: #{@execution_dir}#{File::SEPARATOR}#{@project_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
out msg
|
62
|
+
|
63
|
+
if(@arguments.project_name == '')
|
64
|
+
@execution_dir = File.expand_path(@path_finder.current_project)
|
65
|
+
@path_finder.execution_dir = @execution_dir
|
66
|
+
@arguments.execution_dir = @execution_dir
|
67
|
+
else
|
68
|
+
create_project
|
69
|
+
end
|
70
|
+
|
71
|
+
if(@arguments.copy_to_project)
|
72
|
+
copy_templates_to_project
|
73
|
+
end
|
74
|
+
|
75
|
+
copy_templates(@arguments.selected_templates)
|
76
|
+
|
77
|
+
finish
|
78
|
+
rescue ProjectError => e
|
79
|
+
out e.message
|
80
|
+
exit
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def parse_args args
|
85
|
+
if(args.nil?)
|
86
|
+
@arguments = ProjectArguments.new
|
87
|
+
@arguments.should_create = @should_create_project
|
88
|
+
@arguments.path_finder = @path_finder
|
89
|
+
@arguments.default_templates = @@DEFAULT_TEMPLATES
|
90
|
+
@arguments.project_templates = @path_finder.get_available_templates(@@TEMPLATE_TYPE)
|
91
|
+
@arguments.execution_dir = @execution_dir
|
92
|
+
@arguments.parse!(ARGV)
|
93
|
+
if(@should_create_project)
|
94
|
+
@project_name = @arguments.project_name
|
95
|
+
end
|
96
|
+
else
|
97
|
+
@execution_dir = args.execution_dir
|
98
|
+
@project_name = args.project_name
|
99
|
+
@path_finder = PathFinder.new(@execution_dir)
|
100
|
+
@arguments = args
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def create_project
|
105
|
+
if(File.exists? project_path)
|
106
|
+
if(@arguments.force?)
|
107
|
+
msg = <<EOF
|
108
|
+
|
109
|
+
Are you sure you want to replace the entire directory at:
|
110
|
+
#{project_path}?
|
111
|
+
|
112
|
+
(y)es or (n)o
|
113
|
+
EOF
|
114
|
+
out msg
|
115
|
+
response = gets.chomp!
|
116
|
+
if(response == 'y')
|
117
|
+
FileUtils.rm_rf(project_path)
|
118
|
+
out '>> Deleted: [' + project_path + ']'
|
119
|
+
else
|
120
|
+
raise ProjectError.new('Was unable to create the project at: ' + project_path)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
raise ProjectError.new('Directory at ' + project_path + ' already exists, use -f (--force) option to clobber.')
|
124
|
+
end
|
125
|
+
end
|
126
|
+
Dir.mkdir(project_path)
|
127
|
+
@created_files << project_path
|
128
|
+
# create_config_yaml
|
129
|
+
end
|
130
|
+
|
131
|
+
def copy_templates(templates, target=nil, type=nil, render=true)
|
132
|
+
if(target.nil?)
|
133
|
+
target = project_path
|
134
|
+
end
|
135
|
+
if(type.nil?)
|
136
|
+
type = @@TEMPLATE_TYPE
|
137
|
+
end
|
138
|
+
templates.each do |template|
|
139
|
+
@resolver.copy_files(@path_finder.get_template(type, template), target, render).each do |file|
|
140
|
+
@created_files << file
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def copy_templates_to_user_home(type=nil)
|
146
|
+
if(type.nil?)
|
147
|
+
copy_templates_to_user_home('asproject')
|
148
|
+
copy_templates_to_user_home('asclass')
|
149
|
+
return
|
150
|
+
end
|
151
|
+
user_templates = File.join(@path_finder.user_asproject_home, 'templates', type)
|
152
|
+
templates = @path_finder.get_children(@path_finder.get_gem_template(type, ''))
|
153
|
+
templates.each do |template|
|
154
|
+
target = File.join(user_templates, template)
|
155
|
+
if(!File.exists?(target))
|
156
|
+
File.makedirs(target)
|
157
|
+
end
|
158
|
+
@created_files << target
|
159
|
+
@resolver.copy_files(@path_finder.get_gem_template(type, template), target, false).each do |file|
|
160
|
+
@created_files << file
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def copy_templates_to_project(type=nil)
|
166
|
+
if(type.nil?)
|
167
|
+
copy_templates_to_project('asproject')
|
168
|
+
copy_templates_to_project('asclass')
|
169
|
+
return
|
170
|
+
end
|
171
|
+
project_templates = File.join(project_path, 'config', 'templates', type)
|
172
|
+
templates = @path_finder.get_available_templates(type)
|
173
|
+
templates.each do |template|
|
174
|
+
template_target = File.join(project_templates, template)
|
175
|
+
if(!File.exists?(template_target))
|
176
|
+
File.makedirs(template_target)
|
177
|
+
@created_files << template_target
|
178
|
+
copy_templates(template, template_target, type, false)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def presumed_project_name
|
184
|
+
e_project_name = eclipse_project_name
|
185
|
+
if(!e_project_name.nil?)
|
186
|
+
return e_project_name
|
187
|
+
else
|
188
|
+
return File.basename(@execution_dir)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def eclipse_project_name
|
193
|
+
if(File.exists?(File.join(@execution_dir, '.project')))
|
194
|
+
begin
|
195
|
+
@eclipse_project = EclipseProject.new(@execution_dir)
|
196
|
+
if(!@eclipse_project.project_name.nil?)
|
197
|
+
return @eclipse_project.project_name
|
198
|
+
end
|
199
|
+
rescue
|
200
|
+
return nil
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def project_name
|
206
|
+
return @project_name
|
207
|
+
end
|
208
|
+
|
209
|
+
def project_path
|
210
|
+
return File.join(@execution_dir, @arguments.project_name)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
#######################################
|
215
|
+
# ignore_file?
|
216
|
+
@@COPY_IGNORE_FILES = ['.', '..', '.svn', '.DS_Store', 'CVS', '.cvs' 'Thumbs.db']
|
217
|
+
# Do not copy files found in the ignore_files list
|
218
|
+
def AsProject.ignore_file? file
|
219
|
+
@@COPY_IGNORE_FILES.each do |name|
|
220
|
+
if(name == file)
|
221
|
+
return true
|
222
|
+
end
|
223
|
+
end
|
224
|
+
return false
|
225
|
+
end
|
226
|
+
|
227
|
+
#######################################
|
228
|
+
# AsProjectResolver
|
229
|
+
class AsProjectResolver < TemplateResolver
|
230
|
+
|
231
|
+
def initialize(context)
|
232
|
+
super()
|
233
|
+
@context = context
|
234
|
+
end
|
235
|
+
|
236
|
+
def instance_name
|
237
|
+
return @context.uncapitalize(project_name)
|
238
|
+
end
|
239
|
+
|
240
|
+
def project_name
|
241
|
+
@context.project_name
|
242
|
+
end
|
243
|
+
|
244
|
+
def project_path
|
245
|
+
return @context.project_path
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
|
2
|
+
module AsProject
|
3
|
+
|
4
|
+
#######################################
|
5
|
+
# ProjectArguments
|
6
|
+
class ProjectArguments < Hash
|
7
|
+
attr_accessor :path_finder, :selected_templates, :execution_dir,
|
8
|
+
:default_templates, :default_home_templates, :project_templates,
|
9
|
+
:copy_to_home, :copy_to_project, :project_name, :verbose,
|
10
|
+
:should_create
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self[:project_name] = ''
|
14
|
+
self[:copy_to_project] = false
|
15
|
+
self[:copy_to_home] = false
|
16
|
+
self[:default_templates] = false
|
17
|
+
self[:default_home_templates] = false
|
18
|
+
self[:force] = false
|
19
|
+
self[:should_create] = true
|
20
|
+
self[:verbose] = true
|
21
|
+
self[:selected_templates] = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse!(args)
|
25
|
+
if(@path_finder.nil?)
|
26
|
+
raise ProjectError.new('ProjectArguments needs a path_finder in order to work properly')
|
27
|
+
end
|
28
|
+
|
29
|
+
opts = OptionParser.new do |opts|
|
30
|
+
opts.banner = <<EOF
|
31
|
+
|
32
|
+
Usage: #$0 [options] ProjectName
|
33
|
+
|
34
|
+
Project templates are easily modified and extended, if the files and directories created aren't exactly what you want, use the -c or -C option and edit the templates in your current project or your home path.
|
35
|
+
|
36
|
+
Using -c will place templates in:
|
37
|
+
#{Dir.pwd}/(ProjectName)/config/templates
|
38
|
+
|
39
|
+
Using -C will place templates in:
|
40
|
+
#{@path_finder.user_asproject_home}
|
41
|
+
(Changes will impact all projects that don't have local templates)
|
42
|
+
|
43
|
+
Using -t requires one or more project templates. These values are passed in as a comma-delimited string.
|
44
|
+
Available choices for this particular installation are: #{@project_templates.join(', ')}
|
45
|
+
|
46
|
+
Templates will be used when found in the first folder of the following list:
|
47
|
+
1) ./{ProjectName}/config/templates
|
48
|
+
2) #{@path_finder.user_asproject_home}/templates
|
49
|
+
3) #{@path_finder.gem_asproject_home}/templates
|
50
|
+
|
51
|
+
Options:
|
52
|
+
EOF
|
53
|
+
opts.on('-c', '--copy-templates', "Copy templates to {ProjectName}/config/templates") do
|
54
|
+
self[:copy_to_project] = true
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on('-C', '--copy-templates-to-home', "Copy templates to this user account") do
|
58
|
+
self[:copy_to_home] = true
|
59
|
+
end
|
60
|
+
|
61
|
+
# opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml,asunit'") do
|
62
|
+
# self[:default_templates] = true
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# opts.on('-D', '--default-templates-to-home', "Set the default templates for this user account") do
|
66
|
+
# self[:default_home_templates] = true
|
67
|
+
# end
|
68
|
+
|
69
|
+
opts.on('-f', '--force', "Force creation - overwrite if necessary") do
|
70
|
+
self[:force] = true
|
71
|
+
end
|
72
|
+
|
73
|
+
opts.on('-q', '--quiet', "Do not display created file names") do
|
74
|
+
self[:verbose] = false
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on('-t', '--template(s) [STRING]', "Define which project template(s) to use.") do |str|
|
78
|
+
# Handle space-delimited vs comma-delimited? Do I need to do this?
|
79
|
+
self[:selected_templates] = process_templates(str)
|
80
|
+
end
|
81
|
+
|
82
|
+
opts.on_tail('-h', '--help', 'display this help and exit') do
|
83
|
+
puts opts
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
if(args.length == 0)
|
88
|
+
puts ''
|
89
|
+
puts "[WARNING] Please enter a name for your new project, or use the 'c', 'C', 'd' or 'D' options"
|
90
|
+
puts opts
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
end
|
94
|
+
opts.parse!(args)
|
95
|
+
|
96
|
+
if(self[:should_create])
|
97
|
+
while(args.size > 1)
|
98
|
+
self[:selected_templates] << args.shift
|
99
|
+
end
|
100
|
+
self[:project_name] = clean_name(args.shift.to_s)
|
101
|
+
else
|
102
|
+
while(args.size > 0)
|
103
|
+
self[:selected_templates] << args.shift
|
104
|
+
end
|
105
|
+
end
|
106
|
+
if(self[:selected_templates].size == 0)
|
107
|
+
self[:selected_templates] = @default_templates
|
108
|
+
end
|
109
|
+
verify_templates(self[:selected_templates])
|
110
|
+
end
|
111
|
+
|
112
|
+
def process_templates(str)
|
113
|
+
str = str.split(', ').join(',')
|
114
|
+
if(!str.index(' ').nil? && str.index(',').nil?)
|
115
|
+
templates = str.split(' ')
|
116
|
+
else
|
117
|
+
templates = str.split(',')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def verify_templates(templates)
|
122
|
+
templates.each do |template|
|
123
|
+
if(!@project_templates.index template)
|
124
|
+
msg = <<EOF
|
125
|
+
|
126
|
+
Template [#{template}] was not found!
|
127
|
+
|
128
|
+
Please try again with one of the following available templates:
|
129
|
+
#{@project_templates.join(', ')}
|
130
|
+
EOF
|
131
|
+
raise ProjectError.new(msg)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def clean_name(name)
|
137
|
+
if(name.index("/") || name.index("."))
|
138
|
+
raise ProjectError.new('Project Name must not contain slashes or dots')
|
139
|
+
end
|
140
|
+
return name
|
141
|
+
end
|
142
|
+
|
143
|
+
def project_name
|
144
|
+
return self[:project_name]
|
145
|
+
end
|
146
|
+
|
147
|
+
def selected_templates
|
148
|
+
return self[:selected_templates]
|
149
|
+
end
|
150
|
+
|
151
|
+
def default_templates
|
152
|
+
return self[:default_templates]
|
153
|
+
end
|
154
|
+
|
155
|
+
def default_home_templates
|
156
|
+
return self[:default_home_templates]
|
157
|
+
end
|
158
|
+
|
159
|
+
def copy_to_home
|
160
|
+
return self[:copy_to_home]
|
161
|
+
end
|
162
|
+
|
163
|
+
def copy_to_project
|
164
|
+
return self[:copy_to_project]
|
165
|
+
end
|
166
|
+
|
167
|
+
def verbose
|
168
|
+
return self[:verbose]
|
169
|
+
end
|
170
|
+
|
171
|
+
def force?
|
172
|
+
return self[:force]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
module AsProject
|
3
|
+
class AsProjectBase
|
4
|
+
def out(msg)
|
5
|
+
if(@arguments.verbose)
|
6
|
+
puts msg
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def capitalize(word)
|
11
|
+
chars = word.split('')
|
12
|
+
chars[0].upcase!
|
13
|
+
return chars.join('')
|
14
|
+
end
|
15
|
+
|
16
|
+
def uncapitalize(word)
|
17
|
+
chars = word.split('')
|
18
|
+
chars[0].downcase!
|
19
|
+
return chars.join('')
|
20
|
+
end
|
21
|
+
|
22
|
+
def finish
|
23
|
+
if(@arguments.verbose)
|
24
|
+
puts '---------------------------'
|
25
|
+
if(@created_files.size == 0)
|
26
|
+
puts '>> No files were created'
|
27
|
+
return
|
28
|
+
end
|
29
|
+
@created_files.each do |file|
|
30
|
+
put_created(file)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def put_created(file)
|
36
|
+
if(@arguments.execution_dir.index(Dir.pwd))
|
37
|
+
puts '>> Created file at: ' + file.gsub(@arguments.execution_dir, '.')
|
38
|
+
else
|
39
|
+
puts '>> Created file at: ' + file
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|