tap 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/History +28 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +71 -43
  4. data/Rakefile +81 -64
  5. data/Tutorial +235 -0
  6. data/bin/tap +80 -44
  7. data/lib/tap.rb +41 -12
  8. data/lib/tap/app.rb +243 -246
  9. data/lib/tap/file_task.rb +357 -118
  10. data/lib/tap/generator.rb +88 -29
  11. data/lib/tap/generator/generators/config/config_generator.rb +4 -2
  12. data/lib/tap/generator/generators/config/templates/config.erb +1 -2
  13. data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
  14. data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
  15. data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
  16. data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
  17. data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
  18. data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
  19. data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
  20. data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
  21. data/lib/tap/generator/generators/package/package_generator.rb +38 -0
  22. data/lib/tap/generator/generators/package/templates/package.erb +186 -0
  23. data/lib/tap/generator/generators/root/root_generator.rb +14 -9
  24. data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
  25. data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
  26. data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
  27. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
  28. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
  29. data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
  30. data/lib/tap/generator/generators/script/script_generator.rb +17 -0
  31. data/lib/tap/generator/generators/script/templates/script.erb +42 -0
  32. data/lib/tap/generator/generators/task/task_generator.rb +1 -1
  33. data/lib/tap/generator/generators/task/templates/task.erb +24 -16
  34. data/lib/tap/generator/generators/task/templates/test.erb +13 -17
  35. data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
  36. data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
  37. data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
  38. data/lib/tap/root.rb +108 -146
  39. data/lib/tap/script.rb +362 -0
  40. data/lib/tap/script/console.rb +28 -0
  41. data/lib/tap/script/destroy.rb +13 -1
  42. data/lib/tap/script/generate.rb +13 -1
  43. data/lib/tap/script/run.rb +100 -57
  44. data/lib/tap/support/batch_queue.rb +0 -3
  45. data/lib/tap/support/logger.rb +6 -3
  46. data/lib/tap/support/rake.rb +54 -0
  47. data/lib/tap/support/task_configuration.rb +169 -0
  48. data/lib/tap/support/tdoc.rb +198 -0
  49. data/lib/tap/support/tdoc/config_attr.rb +338 -0
  50. data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
  51. data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
  52. data/lib/tap/support/versions.rb +33 -1
  53. data/lib/tap/task.rb +339 -227
  54. data/lib/tap/test.rb +86 -128
  55. data/lib/tap/test/env_vars.rb +16 -5
  56. data/lib/tap/test/file_methods.rb +373 -0
  57. data/lib/tap/test/subset_methods.rb +299 -180
  58. data/lib/tap/version.rb +2 -1
  59. data/lib/tap/workflow.rb +2 -0
  60. data/test/app/lib/app_test_task.rb +1 -0
  61. data/test/app_test.rb +327 -83
  62. data/test/check/binding_eval.rb +23 -0
  63. data/test/check/define_method_check.rb +22 -0
  64. data/test/check/dependencies_check.rb +175 -0
  65. data/test/check/inheritance_check.rb +22 -0
  66. data/test/file_task_test.rb +524 -291
  67. data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
  68. data/test/root/glob/two.txt +0 -0
  69. data/test/root_test.rb +330 -262
  70. data/test/script_test.rb +194 -0
  71. data/test/support/audit_test.rb +5 -2
  72. data/test/support/combinator_test.rb +10 -10
  73. data/test/support/rake_test.rb +35 -0
  74. data/test/support/task_configuration_test.rb +272 -0
  75. data/test/support/tdoc_test.rb +363 -0
  76. data/test/support/templater_test.rb +2 -2
  77. data/test/support/versions_test.rb +32 -0
  78. data/test/tap_test_helper.rb +39 -0
  79. data/test/task_base_test.rb +115 -0
  80. data/test/task_class_test.rb +56 -4
  81. data/test/task_execute_test.rb +29 -0
  82. data/test/task_test.rb +89 -70
  83. data/test/test/env_vars_test.rb +48 -0
  84. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
  85. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
  86. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
  87. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
  88. data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
  89. data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
  90. data/test/test/file_methods/test_assert_output_files_equal/expected/one.txt +1 -0
  91. data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
  92. data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
  93. data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
  94. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
  95. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
  96. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
  97. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
  98. data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
  99. data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
  100. data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
  101. data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
  102. data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
  103. data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
  104. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
  105. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
  106. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
  107. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
  108. data/test/test/file_methods_test.rb +204 -0
  109. data/test/test/subset_methods_test.rb +93 -33
  110. data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
  111. data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
  112. data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
  113. data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
  114. data/test/test/test_file_task_test/expected/one.txt +1 -0
  115. data/test/test/test_file_task_test/expected/two.txt +1 -0
  116. data/test/test/test_file_task_test/input/one.txt +1 -0
  117. data/test/test/test_file_task_test/input/two.txt +1 -0
  118. data/test/test_test.rb +143 -3
  119. data/test/workflow_test.rb +2 -0
  120. data/vendor/rails_generator.rb +56 -0
  121. data/vendor/rails_generator/base.rb +263 -0
  122. data/vendor/rails_generator/commands.rb +581 -0
  123. data/vendor/rails_generator/generated_attribute.rb +42 -0
  124. data/vendor/rails_generator/lookup.rb +209 -0
  125. data/vendor/rails_generator/manifest.rb +53 -0
  126. data/vendor/rails_generator/options.rb +143 -0
  127. data/vendor/rails_generator/scripts.rb +83 -0
  128. data/vendor/rails_generator/scripts/destroy.rb +7 -0
  129. data/vendor/rails_generator/scripts/generate.rb +7 -0
  130. data/vendor/rails_generator/scripts/update.rb +12 -0
  131. data/vendor/rails_generator/simple_logger.rb +46 -0
  132. data/vendor/rails_generator/spec.rb +44 -0
  133. metadata +180 -196
  134. data/lib/tap/generator/generators/root/templates/app.yml +0 -19
  135. data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
  136. data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
  137. data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
  138. data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
  139. data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
  140. data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
  141. data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
  142. data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
  143. data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
  144. data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
  145. data/lib/tap/script/server.rb +0 -12
  146. data/lib/tap/support/rap.rb +0 -38
  147. data/lib/tap/test/inference_methods.rb +0 -298
  148. data/test/task/config/task_with_config.yml +0 -1
  149. data/test/test/inference_methods_test.rb +0 -311
data/lib/tap/generator.rb CHANGED
@@ -1,29 +1,88 @@
1
- require 'active_record' # required by rails_generator, for some reason
2
- require 'rails_generator'
3
- require 'tap/generator/options'
4
- require 'tap/generator/usage'
5
-
6
- module Tap
7
- module Generator
8
- module Generators # :nodoc:
9
- end
10
- end
11
- end
12
-
13
- # These modifications are to make the rails generators work for Tap
14
- module Rails # :nodoc:
15
- module Generator # :nodoc:
16
- class Base # :nodoc:
17
- include Tap::Generator::Options
18
-
19
- # Used to discover generators within tap. Adapted from code
20
- # in 'rails/rails_generator/lookup.rb'
21
- def self.use_tap_sources!
22
- reset_sources
23
- sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generator/generators")
24
- sources << PathSource.new(:builtin, Tap::App.instance.filepath(:generators))
25
- end
26
- end
27
- end
28
- end
29
-
1
+ require 'rails_generator'
2
+ require 'tap/generator/options'
3
+ require 'tap/generator/usage'
4
+
5
+ module Tap
6
+ # stub module definition so generators can use 'module Tap::Generator::Generators'
7
+ module Generator # :nodoc:
8
+ module Generators # :nodoc:
9
+ end
10
+ end
11
+ end
12
+
13
+ # These modifications are to make the rails generators work for Tap
14
+ module Rails # :nodoc:
15
+ module Generator # :nodoc:
16
+ class Base # :nodoc:
17
+ include Tap::Generator::Options
18
+
19
+ # Used to discover generators within tap. Adapted from code
20
+ # in 'rails/rails_generator/lookup.rb'
21
+ def self.use_tap_sources!
22
+ reset_sources
23
+ sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generator/generators")
24
+ sources << PathSource.new(:builtin, Tap::App.instance.filepath(:generators))
25
+ end
26
+ end
27
+
28
+ class NamedBase < Base # :nodoc:
29
+ attr_reader :class_name_without_nesting
30
+ end
31
+
32
+ module Commands # :nodoc:
33
+ class Create # :nodoc:
34
+
35
+ #--
36
+ # Adds a template_option to nest classes, so that "Some::ClassName" can be nested
37
+ #
38
+ # module Some
39
+ # class ClassName
40
+ # end
41
+ # end
42
+ #
43
+ # rather than
44
+ #
45
+ # class Some::ClassName
46
+ # end
47
+ #
48
+ # The problem is that with the latter representation, errors can be raised if 'Some'
49
+ # has not already been defined as a module.
50
+ #++
51
+ def template(relative_source, relative_destination, template_options = {})
52
+ file(relative_source, relative_destination, template_options) do |file|
53
+ # Evaluate any assignments in a temporary, throwaway binding.
54
+ vars = template_options[:assigns] || {}
55
+ b = binding
56
+ vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
57
+
58
+ # Render the source file with the temporary binding.
59
+ content = ERB.new(file.read, nil, '-').result(b)
60
+
61
+ # add nesting with two-space indentation
62
+ if template_options.has_key?(:class_nesting)
63
+ class_nesting = template_options[:class_nesting]
64
+
65
+ nestings = class_nesting.split(/::/)
66
+ lines = content.split(/\r?\n/)
67
+
68
+ depth = nestings.length
69
+ lines.collect! {|line| " " * depth + line}
70
+
71
+ nestings.reverse_each do |mod_name|
72
+ depth -= 1
73
+ lines.unshift(" " * depth + "module #{mod_name}")
74
+ lines << (" " * depth + "end")
75
+ end
76
+
77
+ content = lines.join("\n")
78
+ end
79
+
80
+ content
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
88
+
@@ -1,6 +1,6 @@
1
1
  module Tap::Generator::Generators
2
2
  class ConfigGenerator < Rails::Generator::NamedBase # :nodoc:
3
- attr_accessor :default_config
3
+ attr_accessor :formatted_yaml
4
4
 
5
5
  def initialize(*args)
6
6
  super(*args)
@@ -12,11 +12,13 @@ module Tap::Generator::Generators
12
12
  record do |m|
13
13
  task_name = class_path.empty? ? class_name : File.join(class_path, class_name)
14
14
  task = @app.task(task_name)
15
- self.default_config = task.class.default_config
15
+ self.formatted_yaml = task.class.configurations.format_yaml
16
16
 
17
17
  config_path = @app.relative_filepath(:root, @app[:config])
18
18
  m.directory File.join(config_path, class_path)
19
19
  m.template "config.erb", File.join(config_path, class_name.underscore + ".yml")
20
+
21
+ # TODO -- add versioning
20
22
  end
21
23
  end
22
24
  end
@@ -1,2 +1 @@
1
- # Configurations for <%= class_name %>
2
- <%= default_config.stringify_keys.to_yaml %>
1
+ <%= formatted_yaml %>
@@ -1,21 +1,6 @@
1
- module Tap::Generator::Generators
2
- class FileTaskGenerator < Rails::Generator::NamedBase # :nodoc:
3
- def initialize(*args)
4
- super(*args)
5
- @destination_root = Tap::App.instance[:root]
6
- @app = Tap::App.instance
7
- end
1
+ require 'tap/generator/generators/task/task_generator'
8
2
 
9
- def manifest
10
- record do |m|
11
- lib_path = @app.relative_filepath(:root, @app[:lib])
12
- m.directory File.join(lib_path, class_path)
13
- m.template "task.erb", File.join(lib_path, class_name.underscore + ".rb")
14
-
15
- test_path = @app.relative_filepath(:root, @app[:test])
16
- m.directory File.join(test_path, class_path)
17
- m.template "test.erb", File.join(test_path, class_name.underscore + "_test.rb")
18
- end
19
- end
3
+ module Tap::Generator::Generators
4
+ class FileTaskGenerator < TaskGenerator # :nodoc:
20
5
  end
21
6
  end
@@ -1,25 +1,32 @@
1
- # == Documentation
1
+ # == Description
2
+ # Replace with a description for <%= class_name_without_nesting %>
3
+ # === Usage
4
+ # Replace with usage instructions
2
5
  #
3
- # === Command Line Usage
4
- # Replace with your command line usage instructions
5
- #
6
- class <%= class_name %> < Tap::FileTask
6
+ class <%= class_name_without_nesting %> < Tap::FileTask
7
+ # uncomment to:
8
+ # - pass all inputs to process at once
9
+ # - define a task that takes no inputs
10
+
11
+ #do_not_iterate
12
+
13
+ # use config to set task configurations
14
+ # configs have accessors by default
15
+
16
+ #config :key, 'value' # config documentation
7
17
 
8
18
  def process(input)
9
- # The process logic goes here. You don't have to use transform.
10
- # Do whatever works!
11
- output = infer_filepath(:data, input)
19
+ # The process logic goes here.
20
+ output = filepath(:data, input)
12
21
 
13
- make(output)
22
+ # prepare ensures the parent directory for
23
+ # output exists, and marks it for rollback
24
+ # in the event of an error
25
+ prepare(output)
14
26
 
15
27
  File.open(input) do |source|
16
28
  File.open(output, "w") do |target|
17
- target.write "<root>\n"
18
- while line = source.gets
19
- next unless line =~ /(\w+): (\w+)/
20
- target.write " <#{$1}>#{$2}</#{$1}>\n"
21
- end
22
- target.write "</root>"
29
+ # ... do something ...
23
30
  end
24
31
  end
25
32
  end
@@ -1,12 +1,23 @@
1
1
  require File.join(File.dirname(__FILE__), '<%= '../' * class_nesting_depth %>tap_test_helper.rb')
2
2
  require '<%= class_path.empty? ? file_name : File.join(class_path, file_name) %>'
3
3
 
4
- class <%= class_name %>Test < Test::Unit::TestCase
4
+ class <%= class_name_without_nesting %>Test < Test::Unit::TestCase
5
5
  acts_as_tap_test
6
6
 
7
7
  def test_<%= file_name.underscore %>
8
+ # this test will make input/expected directories for the
9
+ # test_<%= file_name.underscore %> the first time it is
10
+ # run. assert_expected_result_files runs t with all the
11
+ # input files and returns true only if the expected and
12
+ # output files are equal
13
+ #
14
+ # output files are cleaned up by default. to preserve
15
+ # them use:
16
+ #
17
+ # % tap run test keep_outputs=true
18
+
8
19
  t = <%= class_name %>.new
9
- file_task_test(t, :quiet => true)
20
+ assert_expected_result_files(t)
10
21
  end
11
22
 
12
23
  end
@@ -0,0 +1,21 @@
1
+ module Tap::Generator::Generators
2
+ class GeneratorGenerator < Rails::Generator::NamedBase # :nodoc:
3
+ def initialize(*args)
4
+ super(*args)
5
+ @destination_root = Tap::App.instance[:root]
6
+ @app = Tap::App.instance
7
+
8
+ raise "Sorry - generator names cannot be nested. Try '#{file_name}' by itself." unless class_path.empty?
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ generators_root = @app.relative_filepath(:root, @app[:generators])
14
+ m.directory File.join(generators_root, file_name, "templates")
15
+
16
+ m.template "generator.erb", File.join(generators_root, file_name, file_name + "_generator.rb")
17
+ m.template "usage.erb", File.join(generators_root, file_name, "USAGE")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ class <%= class_name_without_nesting %>Generator < Rails::Generator::NamedBase
2
+ def initialize(*args)
3
+ super(*args)
4
+ @destination_root = Tap::App.instance[:root]
5
+ @app = Tap::App.instance
6
+ end
7
+
8
+ def manifest
9
+ record do |m|
10
+ # Use statements like these to make directories you need.
11
+ # Note directories will be created relative to @destination_root
12
+ # (ie @app[:root]) so the target dir must be a relative filepath
13
+ #target_dir = @app.relative_filepath(:root, @app[:target])
14
+ #m.directory target_dir
15
+
16
+ # These statements would create the following files:
17
+ # templates/ruby_file.erb => target_dir/class_name.rb
18
+ # tempaltes/text_file.erb => target_dir/class_name.txt
19
+ #m.template "ruby_file.erb", File.join(target_dir, class_name.underscore + ".rb"), :class_nesting => class_nesting
20
+ #m.template "text_file.erb", File.join(target_dir, class_name.underscore + ".txt")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ <%= class_name %> Usage
@@ -0,0 +1,38 @@
1
+ require 'shellwords'
2
+ require 'pp'
3
+
4
+ module Tap::Generator::Generators
5
+ class PackageGenerator < Rails::Generator::NamedBase # :nodoc:
6
+ include Shellwords
7
+
8
+ attr_accessor :config, :argv, :package_file
9
+
10
+ def initialize(*args)
11
+ super(*args)
12
+ @destination_root = Tap::App.instance[:root]
13
+ @app = Tap::App.instance
14
+ end
15
+
16
+ def manifest
17
+ record do |m|
18
+ # read the config for the current root
19
+ @config = File.read Tap::Script.config_filepath(@app[:root])
20
+
21
+ # at this point ARGV still includes the package name,
22
+ # ie the commands should be argument 1
23
+ # Note: it's important to setup argv this way, from a single argument,
24
+ # so that options can be included in the packaged arguments:
25
+ # generate package raw_to_mgf "run --debug some/task"
26
+ # vs
27
+ # generate package raw_to_mgf run --debug some/task
28
+ # where '--debug' is applied to generate rather than run
29
+ @argv = PP.singleline_pp(shellwords(ARGV[1].to_s), '')
30
+
31
+ @package_file = class_path.empty? ? file_name : File.join(class_path, file_name)
32
+ filepath = "pkg/#{@package_file}.rb"
33
+ m.directory File.dirname(filepath)
34
+ m.template "package.erb", filepath
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,186 @@
1
+ #############################################
2
+ # HOW TO PACKAGE YOUR SCRIPT:
3
+ # 1. Attend to the parts marked TODO
4
+ # 2. Run rubyscript2exe as described below:
5
+ #
6
+ # % rubyscript2exe <%= package_file %>.rb
7
+ #
8
+ # NOTES:
9
+ # The 'rubyscript2exe' gem is required for packaging -- install using:
10
+ # % gem install rubyscript2exe
11
+ #
12
+ # The inputs you used when creating this script will supplied before
13
+ # the inputs you provide to the executable. Hence if you used:
14
+ # % tap generate package "run --quiet some/task"
15
+ #
16
+ # These will be equivalent commands:
17
+ # % tap run --quiet some/task INPUT1 INPUT2
18
+ # % <%= package_file %>.exe INPUT1 INPUT2
19
+ #
20
+ # Feel free to adjust this script to behave as you like -- whatever this
21
+ # script does will be packaged into the executable.
22
+ #
23
+ #############################################
24
+ #
25
+ # = Prompt Instructions
26
+ # Enter an empty line to continue.
27
+
28
+ require "tap"
29
+ require "tap/script"
30
+
31
+ # = TODO: add script requires
32
+ #
33
+ # Only what this script does will be packaged into the executable.
34
+ # You MUST specify tasks and other files that are not loaded during
35
+ # the 'rubyscript2exe' execution of this script. Usually this means
36
+ # require-ing any tasks that may get used.
37
+ #
38
+ # require 'some/task'
39
+
40
+ app = Tap::App.instance
41
+ script = Tap::Script.instance
42
+
43
+ # = TODO: check arguments
44
+ # Make sure these are what you want later in this script they're unshifted
45
+ # onto ARGV, ie they'll be hard-coded into the executable.
46
+ script_argv = <%= argv %>
47
+
48
+ # = TODO: check configurations
49
+ #
50
+ # This configures the packaged app the same as the current tap.yml
51
+ # Check that the configurations look the way you want them to, or
52
+ # set the executable to load it's own configurations, as by:
53
+ # config_file = Tap::Script.config_filepath(Dir.pwd)
54
+ # config = Tap::Script.read_config(config_file)
55
+ #
56
+ app_config = %Q{<%= config.gsub(/^\s*$|^#.*$/m, '') %>}
57
+
58
+ # = TODO: decide if you want to prompt when you get no inputs
59
+ # This can be handy if you want to be able to interact with the
60
+ # packaged script.
61
+ if ARGV.select {|arg| arg !~ /^-|^--/ }.empty?
62
+ puts Tap::Script.usage(__FILE__, "Prompt Instructions", :keep_headers => false)
63
+
64
+ while true
65
+ print "glob: "
66
+ line = gets.strip
67
+ break if line.empty?
68
+
69
+ line = line[1..-2] if line =~ /^".*"$/
70
+ ARGV << line
71
+ end
72
+ puts
73
+ end
74
+
75
+ # nice give the user a second before you exit, especially if you have a prompt
76
+ def exit(*args)
77
+ puts
78
+ puts "Hit enter to exit."
79
+ ARGV.clear
80
+ gets
81
+ super
82
+ end
83
+
84
+ #############################################
85
+ # These sections generally needs far less customization
86
+ #############################################
87
+
88
+ #
89
+ # configure the app
90
+ #
91
+ begin
92
+ config = YAML.load(app_config)
93
+ config = {} if config == false
94
+ script.configure_app(config)
95
+ rescue(Exception)
96
+ # catch errors and exit gracefully
97
+ # (errors usu from gem loading errors)
98
+ puts "Configuration error: #{$!.message}"
99
+ exit(1)
100
+ end
101
+
102
+ #
103
+ # add modifications for rubyscript2exe
104
+ #
105
+ require "rubyscript2exe"
106
+ if RUBYSCRIPT2EXE.is_compiling?
107
+ module Kernel
108
+ def exit_with_load_path_rewriting
109
+ [$", REQUIRE2LIB::LOADED].each do |loaded_files|
110
+ loaded_files.collect! do |load_path|
111
+ if File.expand_path(load_path) == load_path
112
+ $:.each do |root|
113
+ relative_load_path = Tap::Root.relative_filepath(File.expand_path(root), load_path, false)
114
+ unless relative_load_path == load_path
115
+ load_path = relative_load_path
116
+ break
117
+ end
118
+ end
119
+ end
120
+
121
+ load_path
122
+ end
123
+ end
124
+ exit_without_load_path_rewriting
125
+ end
126
+
127
+ alias exit_without_load_path_rewriting exit
128
+ alias exit exit_with_load_path_rewriting
129
+ end
130
+
131
+ else
132
+ script.config.script_paths.unshift RUBYSCRIPT2EXE.appdir("../lib/script")
133
+ Dependencies.load_paths.unshift RUBYSCRIPT2EXE.appdir("../lib")
134
+ Dir.chdir(RUBYSCRIPT2EXE.exedir)
135
+ end
136
+
137
+ #
138
+ # run before script
139
+ #
140
+ begin
141
+ eval(script.config.before.to_s)
142
+ rescue
143
+ puts "Error in before script."
144
+ if app.options.debug
145
+ raise
146
+ else
147
+ puts $!.message
148
+ exit(1)
149
+ end
150
+ end
151
+
152
+ # This is where the inputs used to create this script are unshifted
153
+ # onto ARGV, ahead of the user inputs.
154
+ script_argv.reverse_each {|arg| ARGV.unshift arg}
155
+
156
+ #
157
+ # run the script -- note that the first argument
158
+ # to ARGV is the script that gets run.
159
+ #
160
+ begin
161
+ load script.config.scripts[ARGV.shift]
162
+ rescue
163
+ if app.options.debug
164
+ raise
165
+ else
166
+ puts "Error."
167
+ puts $!.message
168
+ end
169
+ end
170
+
171
+ #
172
+ # run after script
173
+ #
174
+ begin
175
+ eval(script.config.after.to_s)
176
+ rescue
177
+ puts "Error in after script."
178
+ if app.options.debug
179
+ raise
180
+ else
181
+ puts $!.message
182
+ exit(1)
183
+ end
184
+ end
185
+
186
+ exit(0)