app_archetype 1.2.8 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -1
  3. data/Gemfile.lock +102 -73
  4. data/README.md +166 -29
  5. data/app_archetype.gemspec +22 -19
  6. data/bin/app_archetype +20 -0
  7. data/bin/archetype +1 -1
  8. data/lib/app_archetype/cli.rb +171 -139
  9. data/lib/app_archetype/commands/delete_template.rb +58 -0
  10. data/lib/app_archetype/commands/find_templates.rb +66 -0
  11. data/lib/app_archetype/commands/list_templates.rb +49 -0
  12. data/lib/app_archetype/commands/new_template.rb +42 -0
  13. data/lib/app_archetype/commands/open_manifest.rb +48 -0
  14. data/lib/app_archetype/commands/print_path.rb +20 -0
  15. data/lib/app_archetype/commands/print_template_variables.rb +67 -0
  16. data/lib/app_archetype/commands/print_version.rb +19 -0
  17. data/lib/app_archetype/commands/render_template.rb +178 -0
  18. data/lib/app_archetype/commands.rb +13 -0
  19. data/lib/app_archetype/generators.rb +4 -3
  20. data/lib/app_archetype/template/manifest.rb +17 -1
  21. data/lib/app_archetype/template_manager.rb +13 -6
  22. data/lib/app_archetype/version.rb +1 -1
  23. data/lib/app_archetype.rb +40 -23
  24. data/lib/core_ext/string.rb +18 -12
  25. data/scripts/create_new_command +32 -0
  26. data/scripts/generators/command/manifest.json +15 -0
  27. data/scripts/generators/command/template/lib/app_archetype/commands/{{command_name.snake_case}}.rb.hbs +17 -0
  28. data/spec/app_archetype/cli/presenters_spec.rb +99 -99
  29. data/spec/app_archetype/cli/prompts_spec.rb +291 -291
  30. data/spec/app_archetype/cli_spec.rb +296 -65
  31. data/spec/app_archetype/commands/delete_template_spec.rb +132 -0
  32. data/spec/app_archetype/commands/find_templates_spec.rb +130 -0
  33. data/spec/app_archetype/commands/list_templates_spec.rb +55 -0
  34. data/spec/app_archetype/commands/new_template_spec.rb +84 -0
  35. data/spec/app_archetype/commands/open_manifest_spec.rb +113 -0
  36. data/spec/app_archetype/commands/print_path_spec.rb +22 -0
  37. data/spec/app_archetype/commands/print_template_variables_spec.rb +158 -0
  38. data/spec/app_archetype/commands/print_version_spec.rb +21 -0
  39. data/spec/app_archetype/commands/render_template_spec.rb +479 -0
  40. data/spec/app_archetype/generators_spec.rb +1 -1
  41. data/spec/app_archetype/template/manifest_spec.rb +31 -1
  42. data/spec/app_archetype/template_manager_spec.rb +32 -0
  43. data/spec/app_archetype_spec.rb +65 -0
  44. metadata +155 -80
  45. data/lib/app_archetype/cli/presenters.rb +0 -106
  46. data/lib/app_archetype/cli/prompts.rb +0 -152
@@ -1,152 +0,0 @@
1
- require 'highline'
2
-
3
- module AppArchetype
4
- class CLI < ::Thor
5
- # CLI output presenters
6
- module Prompts
7
- ##
8
- # Variable prompt question. Asked when evaluating template
9
- # variables
10
- #
11
- # @param [AppArchetype::Template::Variable] variable
12
- #
13
- # @return [Proc]
14
- #
15
- VAR_PROMPT_MESSAGE = lambda do |variable|
16
- "\nEnter value for `#{variable.name}` variable\n\n"\
17
- "DESCRIPTION: #{variable.description}\n"\
18
- "TYPE: #{variable.type}\n"\
19
- "DEFAULT: #{variable.default}"
20
- end
21
-
22
- class <<self
23
- ##
24
- # Prompt returns a TTY prompt object for asking the user
25
- # questions.
26
- #
27
- # @return [HighLine]
28
- def prompt
29
- HighLine.new
30
- end
31
-
32
- ##
33
- # A yes/no prompt for asking the user a yes or no question.
34
- #
35
- # @return [Boolean]
36
- #
37
- def yes?(message)
38
- prompt.ask("#{message} [Y/n]", String) { |input| input.strip == 'Y' }
39
- end
40
-
41
- ##
42
- # Prompt for requesting user input.
43
- #
44
- # A default can be provided in the event the user does not
45
- # provide an answer.
46
- #
47
- # Validator also performs type conversion by default it is
48
- # a string
49
- #
50
- # @param message [String]
51
- # @param default [Object]
52
- # @param validator [Object|Lambda]
53
- #
54
- # @return [Object]
55
- #
56
- def ask(message, validator: String, default: nil)
57
- resp = prompt.ask(message, validator)
58
- return default if !default.nil? && resp.to_s.empty?
59
-
60
- resp
61
- end
62
-
63
- ##
64
- # Y/N prompt to ensure user is sure they wish to delete
65
- # the selected template
66
- #
67
- # @param [AppArchetype::Template::Manifest] manifest
68
- #
69
- # @return [Boolean]
70
- def delete_template(manifest)
71
- yes?(
72
- "Are you sure you want to delete `#{manifest.name}`?"
73
- )
74
- end
75
-
76
- ##
77
- # Returns a variable prompt based on the type of variable
78
- # required. Once prompt has been executed, the response is
79
- # returned to the caller.
80
- #
81
- # When the value is set in the manifest, the set value is
82
- # returned without a prompt.
83
- #
84
- # For boolean and integer variables, the relevant prompt
85
- # function is called.
86
- #
87
- # By default the string variable prompt will be used.
88
- #
89
- # @param [AppArchetype::Template::Variable] var
90
- #
91
- # @return [Object]
92
- #
93
- def variable_prompt_for(var)
94
- return var.value if var.value?
95
- return boolean_variable_prompt(var) if var.type == 'boolean'
96
- return integer_variable_prompt(var) if var.type == 'integer'
97
-
98
- string_variable_prompt(var)
99
- end
100
-
101
- ##
102
- # Prompt for boolean variable. This quizzes the user as to
103
- # whether they want the variable set or not. The response
104
- # is returned to the caller.
105
- #
106
- # @param [AppArchetype::Template::Variable] variable
107
- #
108
- # @return [Boolean]
109
- #
110
- def boolean_variable_prompt(variable)
111
- yes?(
112
- VAR_PROMPT_MESSAGE.call(variable)
113
- )
114
- end
115
-
116
- ##
117
- # Prompt for integer. This quizzes the user for their
118
- # choice and then attempts to convert it to an integer.
119
- #
120
- # In the event a non integer value is entered, a
121
- # RuntimeError is thrown.
122
- #
123
- # @param [AppArchetype::Template::Variable] variable
124
- #
125
- # @return [Integer]
126
- #
127
- def integer_variable_prompt(variable)
128
- ask(
129
- VAR_PROMPT_MESSAGE.call(variable),
130
- default: variable.default,
131
- validator: Integer
132
- )
133
- end
134
-
135
- ##
136
- # Prompt for a string. Asks user for input and returns
137
- # it.
138
- #
139
- # @param [AppArchetype::Template::Variable] variable
140
- #
141
- # @return [String]
142
- #
143
- def string_variable_prompt(variable)
144
- ask(
145
- VAR_PROMPT_MESSAGE.call(variable),
146
- default: variable.default
147
- )
148
- end
149
- end
150
- end
151
- end
152
- end