bundlegem 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 045563549ab767462d8d41dad72cc7c1b9c36134
4
- data.tar.gz: 2a392ed207841bf8bd6d9e886269c1e8cb7c4d96
3
+ metadata.gz: 3dfd1e6343877a7582beb24298138a62f6180671
4
+ data.tar.gz: 22d2ad48252af45d5a98708e94d29a40fb56f0dd
5
5
  SHA512:
6
- metadata.gz: 5fcea6513756acc90fddb3fbfd55e0a57783eda99ef981c58dc796e5328e53f83134ca9176435a3e7a5674fed5a55543a3f8580bac0abd90a63f13580da95323
7
- data.tar.gz: 8774029ff42caa8f7a4b1e7c34a3eff21f1134ddac23639c0d6edee7ef980efe7c4c51f807813d30d71c470d7966a355511b1ec487274ae9507332d5db35e790
6
+ metadata.gz: cc5bb9ad05e1623e699ecf2d868f5cd48d60b31e9b03691b29f22150e416eeec3daad99a3259f99d46afaf3d0b107a3bb7622866326d356776a3f69d4ef8b2f9
7
+ data.tar.gz: b21541941978bf508bb0e399d722778f8ce0b90c6d0758a5b8d14ed5855bf4d820dd8c82a21a138b3fe7ee77558cdc86650e99ee583b17bccb66fd043b9cf114
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.swp
14
15
  mkmf.log
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # BundleGem: A Gem Project Generator with User Defined Templates
2
2
 
3
- I've more or less taken the code out of Bundler's `bundle gem` command, expanded on it and made it available as this repos (so credits to Bundler team).
3
+ I've more or less taken the code out of Bundler's `bundle gem` command, expanded on it and made it available as this repo (so credits to Bundler folks).
4
4
 
5
- The goal to the project is to allow users to define templates in the most native form for all technologist: Directory Structures, short command, and helpful commands which make the gem's usage completely visible!
5
+ The goal of the project is to allow users to define templates in the most native form to all technologist: Directory Structures, short commands, and helpful commands which make the gem's usage completely visible!
6
6
 
7
7
  The benefits of using this repo to create gems rather than bundler is that you can choose to create 'classes' of gems. By classes, I mean that there are different typs of 'gems', there are basic library gems, that are just code and can only be used from other code, there are command line application gems, those are gems that are run on the command line and include a binary file, and there are also web interface gems, those are gems which spin up a simple web interface and request that the user connect to it's server on what ever port it has spun up on. Depending on your field of specialty, you may be able to imagine other classes of gems that will aid you in your work.
8
8
 
@@ -23,7 +23,7 @@ $ bundlegem --newtemplate
23
23
  Specify a name for your gem template: my_service
24
24
  Specify description:
25
25
  Specify template tag name [MISC]:
26
- Cloning base project structure into ~/.bundlegem/gem_templates/my_service
26
+ Cloning base project structure into ~/.bundlegem/templates/my_service
27
27
  ...
28
28
  Complete!
29
29
  ```
@@ -34,10 +34,10 @@ $ bundlegem --list
34
34
  PREDEFINED:
35
35
  default - A basic ruby gem
36
36
  service - A gem that allows installation as a service to run as a daemon
37
-
37
+
38
38
  MISC:
39
- my_service -
40
-
39
+ my_service -
40
+
41
41
  EMBEDDED:
42
42
  arduino
43
43
 
@@ -52,8 +52,19 @@ $ cd /tmp
52
52
  $ bundlegem project_name -t my_service
53
53
  ```
54
54
 
55
+ ## Customizing Your Own Templates
56
+
57
+ Place your own templates in `~/.bunglegem/templates`. You can populate it with examples by running `bundlegem --install-best-templates`
58
+
59
+ You'll get a good idea as to the possibilities by inspecting the files in [templates](https://github.com/TheNotary/bundlegem/tree/master/lib/bundlegem/templates/newgem). Some quick tips follow:
60
+
61
+ - Files ending with a `.tt` extension will by written to new projects
62
+ - File **names** containing `#{name}` will have that symbol replaced by the project name defined on the CLI
63
+ - Within files, use `<%=config[:namespaced_path]%>` to have that reinterpreted as just the file name with underscores
64
+ - Have a look [under the hood](https://github.com/TheNotary/bundlegem/blob/master/lib/bundlegem/cli/gem.rb#L30-L43) to see other options and the context where the ERB.new takes place.
65
+
66
+
55
67
  ### Contributing
56
68
 
57
69
  Please feel free to speak up using the issue section if there's anything on your mind :)
58
70
  Do the usual fork routine and issue a pull request by all means.
59
-
data/bin/bundlegem CHANGED
@@ -6,30 +6,21 @@ require 'bundler'
6
6
  require 'bundlegem'
7
7
  # require 'bundlergem/friendly_errors'
8
8
 
9
+
9
10
  if ARGV.length < 1
10
- puts "error: you need to specify a gemname at least"
11
+ puts "error: you need to specify a name for the project being created\n\n"
12
+ puts Bundlegem::HELP_MSG
11
13
  exit 1
12
14
  end
13
15
 
14
16
  if ARGV[0] == "--help"
15
- puts "Usage: "
16
- puts " # creates a gem based on default template"
17
- puts " $ bundlegem gem_name "
18
- puts
19
- puts " # creates a gem using the service template built into gem"
20
- puts " $ bundlegem gem_name -t service "
21
- puts
22
- puts " # not implemented, but shoud create a new gem template in ~/.bundlegem/templates"
23
- puts " # that you'll love customizing to your personal preference"
24
- puts " $ bundlegem --newtemplate "
25
- puts
26
- puts " $ bundlegem --help # shows these strings"
17
+ puts Bundlegem::HELP_MSG
27
18
  exit 0
28
19
  end
29
20
 
30
21
  if ARGV[0] == "--list" or ARGV[0] == "-l"
31
22
  puts Bundlegem.list
32
- exit 0
23
+ exit 0
33
24
  end
34
25
 
35
26
  if ARGV[0] == "--newtemplate"
@@ -38,20 +29,25 @@ if ARGV[0] == "--newtemplate"
38
29
  Bundlegem.newtemplate(ARGV)
39
30
  end
40
31
 
41
-
32
+ if ARGV[0] == "--install-best-templates"
33
+ puts Bundlegem.install_best_templates
34
+ exit 0
35
+ end
42
36
 
43
37
  options = {"bin"=>false, "ext"=>false, :coc=> false}
44
- gem_name = ARGV[0] # gem name
45
-
46
- if ARGV.length > 1
47
- if ARGV[1] != "-t" and ARGV[1] != "--template"
48
- puts "you can ONLY use -t as an argument because I'm quite busy and should be doing something else right now!"
49
- exit 1
38
+ gem_name = ""
39
+ skip_i = -99
40
+
41
+ # Loop over CLI parameters
42
+ ARGV.each_with_index do |arg, i|
43
+ next if skip_i == i
44
+ if arg == "-t" or arg == "--template" # the item after this specifies the template to use
45
+ options.merge!({"template" => ARGV[i+1]})
46
+ skip_i = i+1
47
+ next
48
+ elsif !arg.include?("-") # this must be what they want as the gem_name
49
+ gem_name = arg
50
50
  end
51
-
52
- options.merge!({"template" => ARGV[2]})
53
51
  end
54
52
 
55
53
  Bundlegem.gem(options, gem_name)
56
-
57
-
data/changelog CHANGED
@@ -1,34 +1,21 @@
1
1
  ** 0.0.x **
2
- - Feature: Make each user defined gem have a subfolder that is the exact
3
- project structure, so the readme for the gem can exist without fear of it
4
- being copied into new projects
5
- - Feature: Gem's display names are based on what's specified in their
2
+ - CMD: --newtemplate to start new template
3
+ - I'll need to write a basic starter template that is educational
4
+
5
+
6
+ ** 0.0.7 **
7
+
8
+ - Feature: Ability to load templates from github via --install-best-templates
9
+ - Feature: Make each user defined gem have a subfolder that is the exact
10
+ project structure, so the readme for the gem can exist without fear of it
11
+ being copied into new projects
12
+ - Feature: Gem's display names are based on what's specified in their
6
13
  respective root .bundlegem
7
- - newgem template: fix Rake file and test organization
8
- - Default templates:
9
- * CLI file system app,
10
- * CLI with web client
11
- - Restore the original UI that was in bundler
12
- - Feature: Ability to load templates from github
13
- - Track a list of additional web templates in this repo
14
- - Allow for it to be listed
15
- - Hint the user to cd into ~/.bundlegem/gem_templates and clone any they choose
16
-
17
-
18
- - Behavior: gems in the ~/.bundlegem/gem_templates folder take precidence over
19
- built in gems? ...add prompt
20
- - Cleaning: Make create_gem build a string instead of puts so
21
- output can be squelched for testing
22
- - CMD: --templateize-current-directory to make the current directory into a
23
- new template
24
- - CORE: refactor the built-in gems so they look pretty (templates/newgem/lib/#{name}.rb.tt)
25
- * Need to implement partials that are stored inside the gem
26
-
27
- - CMD: --newtemplate to start new template
28
- - CMD: --default to set a gem_template as the default one (list should indicate this)
29
- - list doesn't display these becasue lib/bundlegem.rb:15
30
- - Built-in Template: cli_gem
31
- - Built-in Template: c_ext_gem
14
+ - Feature: Allow better CLI parsing so -t t_name can be the first couple
15
+ arguments or at the end
16
+ - Bugfix: cli_gem and c_ext_gem now show up in the list
17
+ - Bugfix: cli_gem and c_ext_gem had typos fixed
18
+
32
19
 
33
20
 
34
21
  ** 0.0.6 **
data/config/config CHANGED
@@ -1,4 +1,4 @@
1
1
  # Comments made to this file will not be preserved
2
2
  ---
3
3
  default_template: newgem
4
-
4
+ best_templates: https://github.com/TheNotary/arduino.git https://github.com/TheNotary/raspberry_pi_c.git https://github.com/TheNotary/docker_repo.git https://github.com/TheNotary/simple_frontend.git
@@ -43,18 +43,18 @@ module Bundlegem
43
43
  :bundler_version => bundler_dependency_version
44
44
  }
45
45
  ensure_safe_gem_name(name, constant_array)
46
-
46
+
47
47
  template_src = match_template_src
48
48
  template_directories = dynamically_generate_template_directories
49
49
  templates = dynamically_generate_templates(config)
50
-
50
+
51
51
  puts "Creating new project folder '#{name}'\n\n"
52
52
  create_template_directories(template_directories, target)
53
-
53
+
54
54
  templates.each do |src, dst|
55
55
  template("#{template_src}/#{src}", target.join(dst), config)
56
56
  end
57
-
57
+
58
58
 
59
59
  # Bundler.ui.info "Initializing git repo in #{target}"
60
60
  Dir.chdir(target) { `git init`; `git add .` }
@@ -62,20 +62,19 @@ module Bundlegem
62
62
  # Disabled thanks to removal of thor, might not be helpful...
63
63
  #if options[:edit]
64
64
  # # Open gemspec in editor
65
- #
65
+ #
66
66
  # # thor.run("#{options["edit"]} \"#{target.join("#{name}.gemspec")}\"")
67
67
  #end
68
-
68
+
69
69
  puts "\nComplete."
70
70
  end
71
71
 
72
72
  private
73
-
73
+
74
74
  def dynamically_generate_template_directories
75
75
  # return nil if options["template"].nil?
76
-
77
76
  template_src = TemplateManager.get_template_src(options)
78
-
77
+
79
78
  template_dirs = {}
80
79
  Dir.glob("#{template_src}/**/*").each do |f|
81
80
  next unless File.directory? f
@@ -87,7 +86,7 @@ module Bundlegem
87
86
 
88
87
  # This function should be eliminated over time so that other methods conform to the
89
88
  # new algo for generating templates automatically.
90
- # Really, this function generates a template_src to template_dst naming
89
+ # Really, this function generates a template_src to template_dst naming
91
90
  # structure so that a later method can copy all the template files from the
92
91
  # source and rename them properly
93
92
  def generate_templates_for_built_in_gems(config)
@@ -104,6 +103,7 @@ module Bundlegem
104
103
  'bin/console.tt' => "bin/console"
105
104
  }
106
105
 
106
+
107
107
  prompt_coc!(templates)
108
108
  prompt_mit!(templates, config)
109
109
  prompt_test_framework!(templates, config)
@@ -119,27 +119,27 @@ module Bundlegem
119
119
  end
120
120
  templates
121
121
  end
122
-
123
- # Figures out the translation between all the .tt file to their
122
+
123
+ # Figures out the translation between all the .tt file to their
124
124
  # destination names
125
125
  def dynamically_generate_templates(config)
126
126
  #if options["template"].nil? # if it's doing some of the built in template
127
127
  # return generate_templates_for_built_in_gems(config)
128
128
  #else
129
129
  template_src = TemplateManager.get_template_src(options)
130
-
130
+
131
131
  templates = {}
132
132
  Dir.glob("#{template_src}/**/{*,.*}.tt").each do |f|
133
133
  base_path = f[template_src.length+1..-1]
134
134
  templates.merge!(base_path => base_path.gsub(/\.tt$/, "").gsub('#{name}', "#{name}") )
135
135
  end
136
-
136
+
137
137
  raise_no_files_in_template_error! if templates.empty?
138
-
138
+
139
139
  return templates
140
140
  #end
141
141
  end
142
-
142
+
143
143
  def create_template_directories(template_directories, target)
144
144
  template_directories.each do |k,v|
145
145
  d = "#{target}/#{v}"
@@ -151,20 +151,20 @@ module Bundlegem
151
151
  # returns the full path of the template source
152
152
  def match_template_src
153
153
  template_src = TemplateManager.get_template_src(options)
154
-
154
+
155
155
  if File.exists?(template_src)
156
156
  return template_src # 'newgem' refers to the built in template that comes with the gem
157
157
  else
158
158
  raise_template_not_found! # else message the user that the template could not be found
159
159
  end
160
160
  end
161
-
162
-
161
+
162
+
163
163
  def resolve_name(name)
164
164
  Pathname.pwd.join(name).basename.to_s
165
165
  end
166
166
 
167
-
167
+
168
168
  def validate_ext_name
169
169
  return unless gem_name.index('-')
170
170
 
@@ -175,18 +175,18 @@ module Bundlegem
175
175
  exit 1
176
176
  end
177
177
 
178
-
178
+
179
179
  def bundler_dependency_version
180
- v = Gem::Version.new(Bundler::VERSION)
180
+ v = Gem::Version.new(Bundlegem::VERSION)
181
181
  req = v.segments[0..1]
182
182
  req << 'a' if v.prerelease?
183
183
  req.join(".")
184
184
  end
185
185
 
186
-
187
-
188
-
189
-
186
+
187
+
188
+
189
+
190
190
  #
191
191
  # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
192
192
  #
@@ -211,7 +211,7 @@ module Bundlegem
211
211
 
212
212
  source = File.expand_path(TemplateManager.find_in_source_paths(source.to_s))
213
213
  context = instance_eval("binding")
214
-
214
+
215
215
  make_file(destination, config) do
216
216
  content = ERB.new(::File.binread(source), nil, "-", "@output_buffer").result(context)
217
217
  content = block.call(content) if block
@@ -219,9 +219,9 @@ module Bundlegem
219
219
  end
220
220
 
221
221
  end
222
-
223
-
224
-
222
+
223
+
224
+
225
225
  #
226
226
  # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
227
227
  #
@@ -230,35 +230,41 @@ module Bundlegem
230
230
  puts " Writing #{destination} ..."
231
231
  File.open(destination, "wb") { |f| f.write block.call }
232
232
  end
233
-
234
-
235
-
233
+
234
+
235
+
236
236
  def raise_no_files_in_template_error!
237
- puts "Ooops, the template was found for '#{options['template']}' in ~/.bundlegem/gem_templates, "
238
- puts "but no files within it ended in .tt. Did you forget to rename the extensions of your files?"
239
- puts
240
- puts "Exiting..."
237
+ err_no_files_in_template = <<-HEREDOC
238
+ Ooops, the template was found for '#{options['template']}' in ~/.bundlegem/templates,
239
+ but no files within it ended in .tt. Did you forget to rename the extensions of your files?
240
+
241
+ Exiting...
242
+ HEREDOC
243
+ puts err_no_files_in_template
241
244
  exit
242
245
  end
243
-
246
+
244
247
  def raise_project_with_that_name_already_exists!
245
- puts "Ooops, a project with the name #{target} already exists."
246
- puts "Can't make project. Either delete that folder or choose a new project name"
247
- puts
248
- puts "Exiting..."
248
+ err_project_with_that_name_exists = <<-HEREDOC
249
+ Ooops, a project with the name #{target} already exists.
250
+ Can't make project. Either delete that folder or choose a new project name
251
+
252
+ Exiting...
253
+ HEREDOC
254
+ puts err_project_with_that_name_exists
249
255
  exit
250
256
  end
251
-
257
+
252
258
  def raise_template_not_found!
253
- err_missing_template = "Could not find template folder '#{options["template"]}' in `~/.bundle/gem_templates/`. Please check to make sure your desired template exists."
259
+ err_missing_template = "Could not find template folder '#{options["template"]}' in `~/.bundle/templates/`. Please check to make sure your desired template exists."
254
260
  puts err_missing_template
255
261
  Bundler.ui.error err_missing_template
256
262
  exit 1
257
263
  end
258
-
259
-
264
+
265
+
260
266
  ############# STUFF THAT SHOULD BE REMOVED DOWN THE ROAD
261
-
267
+
262
268
  # This asks the user if they want to setup rspec or test...
263
269
  # It's not class based, it's additive based... Plus bundlegem does this already
264
270
  def ask_and_set_test_framework
@@ -281,7 +287,7 @@ module Bundlegem
281
287
 
282
288
  test_framework
283
289
  end
284
-
290
+
285
291
  def ask_and_set(key, header, message)
286
292
  choice = options[key] # || Bundler.settings["gem.#{key}"]
287
293
 
@@ -293,7 +299,7 @@ module Bundlegem
293
299
 
294
300
  choice
295
301
  end
296
-
302
+
297
303
  def prompt_coc!(templates)
298
304
  if ask_and_set(:coc, "Do you want to include a code of conduct in gems you generate?",
299
305
  "Codes of conduct can increase contributions to your project by contributors who " \
@@ -305,7 +311,7 @@ module Bundlegem
305
311
  templates.merge!("CODE_OF_CONDUCT.md.tt" => "CODE_OF_CONDUCT.md")
306
312
  end
307
313
  end
308
-
314
+
309
315
  def prompt_mit!(templates, config)
310
316
  if ask_and_set(:mit, "Do you want to license your code permissively under the MIT license?",
311
317
  "This means that any other developer or company will be legally allowed to use your code " \
@@ -316,7 +322,7 @@ module Bundlegem
316
322
  templates.merge!("LICENSE.txt.tt" => "LICENSE.txt")
317
323
  end
318
324
  end
319
-
325
+
320
326
  def prompt_test_framework!(templates, config)
321
327
  namespaced_path = config[:namespaced_path]
322
328
  if test_framework = ask_and_set_test_framework
@@ -337,7 +343,7 @@ module Bundlegem
337
343
  end
338
344
  end
339
345
  end
340
-
346
+
341
347
  # This checks to see that the gem_name is a valid ruby gem name and will 'work'
342
348
  # and won't overlap with a bundlegem constant apparently...
343
349
  #
data/lib/bundlegem/cli.rb CHANGED
@@ -74,9 +74,9 @@ module Bundlegem
74
74
  def self.handle_no_command_error(command, has_namespace = $thor_runner)
75
75
  require 'bundlegem/cli/gem'
76
76
  Gem.new(options, name, self).run
77
-
78
-
79
-
77
+
78
+
79
+
80
80
  # return super unless command_path = Bundlegem.which("Bundlegem-#{command}")
81
81
 
82
82
  # Kernel.exec(command_path, *ARGV[1..-1])
@@ -94,7 +94,7 @@ module Bundlegem
94
94
  Init.new(options.dup).run
95
95
  end
96
96
 
97
-
97
+
98
98
 
99
99
  desc "version", "Prints the bundler's version information"
100
100
  def version
@@ -113,7 +113,7 @@ module Bundlegem
113
113
  method_option :mit, :type => :boolean, :desc => "Generate an MIT license file"
114
114
  method_option :test, :type => :string, :lazy_default => 'rspec', :aliases => '-t', :banner => "rspec",
115
115
  :desc => "Generate a test directory for your library, either rspec or minitest. Set a default with `bundle config gem.test rspec`."
116
- method_option :template, :type => :string, :lazy_default => "newgem", :aliases => '-u', :banner => "default", :desc => "Generate a gem based on the user's predefined template."
116
+ method_option :template, :type => :string, :lazy_default => "newgem", :aliases => '-u', :banner => "default", :desc => "Generate a gem based on the user's predefined template."
117
117
  def gem(name)
118
118
  # options = {"bin"=>false, "ext"=>false}
119
119
  # name = "gem_name"
@@ -2,37 +2,37 @@ require 'fileutils'
2
2
  require 'yaml'
3
3
 
4
4
  module Bundlegem
5
-
5
+
6
6
  class Configurator
7
7
  attr_accessor :user_defined_templates, :user_downloaded_templates
8
-
8
+
9
9
  def initialize
10
10
  @config_directory_root = "#{ENV['HOME']}/.bundlegem"
11
11
  @config_file = "#{@config_directory_root}/config"
12
- @user_defined_templates_path = "#{@config_directory_root}/gem_templates"
13
-
12
+ @user_defined_templates_path = "#{@config_directory_root}/templates"
13
+
14
14
  create_config_file_if_needed!
15
-
15
+
16
16
  @user_defined_templates = get_user_defined_templates
17
17
  @user_downloaded_templates = get_user_downloaded_templates
18
-
18
+
19
19
  # load configurations from config file
20
20
  @c = YAML.load_file @config_file
21
21
  end
22
-
22
+
23
23
  def default_template
24
24
  @c["default_template"]
25
25
  end
26
-
26
+
27
27
  def default_template=(val)
28
28
  @c["default_template"] = val
29
29
  File.write(@config_file, "# Comments made to this file will not be preserved\n#{YAML.dump(@c)}")
30
30
  end
31
-
31
+
32
32
  def built_in_templates
33
-
33
+
34
34
  end
35
-
35
+
36
36
  # not implemented yet
37
37
  def get_user_downloaded_templates
38
38
  []
@@ -40,39 +40,39 @@ module Bundlegem
40
40
 
41
41
  def get_user_defined_templates
42
42
  user_definition_directory = @user_defined_templates_path
43
- template_dirs = Dir.entries(user_definition_directory).select do |entry|
44
- File.directory?(File.join(user_definition_directory, entry)) and !(entry =='.' || entry == '..')
43
+ template_dirs = Dir.entries(user_definition_directory).select do |entry|
44
+ File.directory?(File.join(user_definition_directory, entry)) and !(entry =='.' || entry == '..')
45
45
  end
46
-
46
+
47
47
  pairs = []
48
48
  template_dirs.each do |dir|
49
49
  # open the dir and read the .bundlegem file to see what class of file it is
50
50
  # If there's no .bundlegem file in there, mark it misc
51
-
51
+
52
52
  begin
53
53
  f = File.read("#{@user_defined_templates_path}/#{dir}/.bundlegem")
54
54
  /category:\s*([\w\s]*$)/ =~ f
55
-
55
+
56
56
  category = $1.chomp
57
57
  rescue
58
58
  category = "MISC"
59
59
  end
60
-
60
+
61
61
  category = "MISC" if category.nil?
62
-
62
+
63
63
  pairs << {category => dir }
64
64
  end
65
65
  pairs
66
66
  end
67
-
67
+
68
68
  def create_config_file_if_needed!
69
69
  FileUtils.mkdir_p @user_defined_templates_path
70
- FileUtils.cp("#{SOcreate_new_templateURCE_ROOT}/config/config", @config_file) unless File.exists? @config_file
70
+ FileUtils.cp("#{SOURCE_ROOT}/config/config", @config_file) unless File.exists? @config_file
71
71
  end
72
-
72
+
73
73
  def create_new_template(template_name)
74
74
  puts "i'm still a stub"
75
75
  end
76
-
76
+
77
77
  end
78
- end
78
+ end
@@ -0,0 +1,28 @@
1
+ module Bundlegem
2
+ HELP_MSG = <<-HEREDOC
3
+ Use bundlegem to start a new project folder based on a predefined template.
4
+
5
+ Usage Examples:
6
+
7
+ # Make a new ruby gem
8
+ $ bundlegem your_gem_name
9
+
10
+ # List available teplates
11
+ $ bundlegem --list
12
+
13
+ # Create a ruby gem project using the built in service template
14
+ $ bundlegem your_gem_name -t service
15
+
16
+ # Download all my template files (configured in ~/.bundlegem/config)
17
+ $ bundlegem --install-best-templates
18
+
19
+ # not implemented, should create a new gem template in ~/.bundlegem/templates
20
+ # that you'll love customizing to your personal preference
21
+ $ bundlegem --newtemplate
22
+
23
+ $ bundlegem --help # shows this message
24
+ HEREDOC
25
+
26
+
27
+
28
+ end
@@ -1,43 +1,43 @@
1
1
  require 'fileutils'
2
2
 
3
3
  module Bundlegem
4
-
4
+
5
5
  # This class handles the logic for finding templates
6
- # in the user's dir, the gem's builtin templates
6
+ # in the user's dir, the gem's builtin templates
7
7
  # (and on the web some day)
8
8
  class TemplateManager
9
-
9
+
10
10
  class << self
11
-
11
+
12
12
  def create_new_template(template_name)
13
-
13
+
14
14
  end
15
-
16
-
15
+
16
+
17
17
  def get_default_template_name
18
18
  "newgem"
19
19
  end
20
-
20
+
21
21
  def get_template_src(options)
22
22
  template_name = options["template"].nil? ? get_default_template_name : options["template"]
23
-
23
+
24
24
  if template_exists_within_repo?(template_name)
25
- gem_template_location = get_internal_template_location
25
+ template_location = get_internal_template_location
26
26
  else
27
- gem_template_location = File.expand_path("~/.bundlegem/gem_templates")
27
+ template_location = File.expand_path("~/.bundlegem/templates")
28
28
  end
29
- template_src = "#{gem_template_location}/#{template_name}"
29
+ template_src = "#{template_location}/#{template_name}"
30
30
  end
31
-
32
-
31
+
32
+
33
33
  def get_internal_template_location
34
34
  File.expand_path("#{File.dirname(__FILE__)}/templates")
35
35
  end
36
-
36
+
37
37
  def template_exists_within_repo?(template_name)
38
38
  TemplateManager.file_in_source?(template_name)
39
39
  end
40
-
40
+
41
41
  #
42
42
  # EDIT: Reworked from Thor to not rely on Thor (or do so much unneeded stuff)
43
43
  #
@@ -46,14 +46,14 @@ module Bundlegem
46
46
  return src_in_source_path if File.exists?(src_in_source_path)
47
47
  target # failed, hopefully full path to a user specified gem template file
48
48
  end
49
-
50
- # Get's path to 'target' from within the gem's "templates" folder
49
+
50
+ # Get's path to 'target' from within the gem's "templates" folder
51
51
  # within the gem's source
52
52
  def file_in_source?(target)
53
53
  src_in_source_path = "#{File.dirname(__FILE__)}/templates/#{target}"
54
54
  File.exists?(src_in_source_path)
55
55
  end
56
-
56
+
57
57
  end
58
58
  end
59
- end
59
+ end
@@ -1,7 +1,5 @@
1
1
  == What's This?
2
2
 
3
- This is a gem skeleton template. Ideally you can define your own and place them into ~/.bundle/gem_templates and specify to use that template instead of the default template defined in bundler.
3
+ This is a gem skeleton template. Ideally you can define your own and place them into ~/.bundle/templates and specify to use that template instead of the default template defined in bundler.
4
4
 
5
5
  This skelton would be helpful if you needed to create a new ruby app that ran as a service on the installed machine. This skelton should include the base code required for building a daemon style ruby app, including an installation command, a start/stop/restart/status interface and of course a spot that says "# your daemon code goes here" where you could easily drop in, say, a write to a log file and a sleep 5000 instruction and you'd be pretty much set for rapidly spinning up a new gem of the daemon type.
6
-
7
-
@@ -1,3 +1,3 @@
1
1
  module Bundlegem
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/bundlegem.rb CHANGED
@@ -1,36 +1,41 @@
1
1
  require "bundlegem/version"
2
+ require "bundlegem/strings"
2
3
  require 'bundlegem/configurator'
3
4
  require 'bundlegem/template_manager'
4
5
 
6
+ require 'bundlegem/cli'
7
+
5
8
  SOURCE_ROOT = File.expand_path("#{File.dirname(__FILE__)}/..")
6
9
 
7
10
  module Bundlegem
8
-
11
+
9
12
  class << self
10
-
13
+
11
14
  # lists available templates
12
15
  def list
13
16
  configurator = Configurator.new
14
17
  # search through builtin
15
- available_templates = [ { "predefined" => "newgem" },
18
+ available_templates = [ { "predefined" => "newgem" },
19
+ { "predefined" => "c_extension_gem" },
20
+ { "predefined" => "cli_gem" },
16
21
  { "predefined" => "service" }]
17
-
22
+
18
23
  # search through user downloaded
19
24
  available_templates += configurator.user_downloaded_templates
20
-
25
+
21
26
  # search through user defined
22
27
  available_templates += configurator.user_defined_templates
23
28
 
24
29
  available_templates = group_hashes_by_key(available_templates)
25
30
  output_string = convert_grouped_hashes_to_output(available_templates)
26
-
31
+
27
32
  mark_default_template(output_string, configurator.default_template)
28
33
  end
29
-
34
+
30
35
  def gem(options, gem_name)
31
36
  require 'bundlegem/cli'
32
37
  require 'bundlegem/cli/gem'
33
-
38
+
34
39
  Bundlegem::CLI::Gem.new(options, gem_name).run
35
40
  end
36
41
 
@@ -38,23 +43,23 @@ module Bundlegem
38
43
  template_name = args[1]
39
44
  template_name = prompt_for_template_name if template_name.nil?
40
45
 
41
- # Copy newgem from within the repo to ~/.bundlegem/gem_templates/#{template_name}
46
+ # Copy newgem from within the repo to ~/.bundlegem/templates/#{template_name}
42
47
  TemplateManager.create_new_template(template_name)
43
48
  end
44
49
 
45
- def prompt_for_template_name
50
+ def prompt_for_template_name
46
51
  puts "Please specify a name for your template: "
47
52
  template_name = STDIN.gets.chomp.strip.gsub(" ", "_")
48
53
  end
49
54
 
50
- # input: [ { "predefined" => "default" },
55
+ # input: [ { "predefined" => "default" },
51
56
  # { "MISC" => "my_thing" },
52
57
  # { "prdefined" => "service" }
53
58
  # ]
54
59
  #
55
- # output: [ { "predefined" => ["default", "service"] },
60
+ # output: [ { "predefined" => ["default", "service"] },
56
61
  # { "MISC" => ["my_thing"] }
57
- # ]
62
+ # ]
58
63
  #
59
64
  def group_hashes_by_key(available_templates)
60
65
  h = {}
@@ -66,10 +71,10 @@ module Bundlegem
66
71
  end
67
72
  h
68
73
  end
69
-
70
- # input: [ { "predefined" => ["default", "service"] },
74
+
75
+ # input: [ { "predefined" => ["default", "service"] },
71
76
  # { "MISC" => ["my_thing"] }
72
- # ]
77
+ # ]
73
78
  def convert_grouped_hashes_to_output(available_templates)
74
79
  s = ""
75
80
  available_templates.each do |hash|
@@ -83,10 +88,10 @@ module Bundlegem
83
88
  end
84
89
  s
85
90
  end
86
-
91
+
87
92
  def mark_default_template(output_string, default_template)
88
93
  output_string.lines.reverse.map do |l|
89
- if l.strip == default_template
94
+ if l.strip == default_template
90
95
  l[1]= "*"
91
96
  "#{l.chomp} (default)\n"
92
97
  else
@@ -94,7 +99,7 @@ module Bundlegem
94
99
  end
95
100
  end.reverse.join
96
101
  end
97
-
102
+
98
103
  def which(executable)
99
104
  if File.file?(executable) && File.executable?(executable)
100
105
  executable
@@ -106,7 +111,23 @@ module Bundlegem
106
111
  path && File.expand_path(executable, path)
107
112
  end
108
113
  end
109
-
114
+
115
+ def install_best_templates
116
+ puts "Downloading templates from the following locations: #{ENV['best_templates']}"
117
+ ENV['best_templates'].split.each do |url|
118
+ uri = URI.parse(url)
119
+ template_folder_name = File.basename(uri.path).sub(/\.git$/, "")
120
+ if !File.exists?(template_folder_name)
121
+ cmd = "cd #{ENV['HOME']}/.bundlegem/templates && git clone #{url}"
122
+ cmd += " 2> /dev/null" if $test_env
123
+ `#{cmd}`
124
+ else
125
+ # TODO:
126
+ # Prompt to update the repo if they have a clean working state.
127
+ end
128
+ end
129
+ end
130
+
110
131
  end
111
-
132
+
112
133
  end
@@ -1,47 +1,70 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bundlegem do
4
-
4
+
5
5
  before :each do
6
6
  @mocked_home = "/tmp/bundlegem_mock_home"
7
- @template_root = "#{@mocked_home}/.bundlegem/gem_templates"
7
+ @template_root = "#{@mocked_home}/.bundlegem/templates"
8
8
  @dst_dir = "/tmp/bundle_gem_dst_dir"
9
9
 
10
10
  reset_test_env
11
- FileUtils.chdir("/tmp/bundle_gem_dst_dir")
11
+ FileUtils.chdir(@dst_dir)
12
12
  end
13
-
13
+
14
14
  it 'has a version number' do
15
15
  expect(Bundlegem::VERSION).not_to be nil
16
16
  end
17
17
 
18
- it 'does something useful' do
19
- require 'bundlegem/cli'
20
- end
21
-
22
18
  it 'creates a config file if needed and lists properly' do
23
19
  create_user_defined_template
24
-
20
+
25
21
  list_output = Bundlegem.list
26
-
27
- expect(list_output).to eq " PREDEFINED:\n * newgem (default)\n service\n\n MISC:\n empty_template\n\n"
22
+
23
+ expect(list_output).to eq " PREDEFINED:\n * newgem (default)\n c_extension_gem\n cli_gem\n service\n\n MISC:\n empty_template\n\n"
28
24
  expect(File.exists?("#{ENV['HOME']}/.bundlegem")).to be true
29
25
  end
30
-
26
+
31
27
  it "lists with good categories" do
32
28
  category = "ARDUINO"
33
29
  create_user_defined_template(category)
34
-
30
+
35
31
  list_output = Bundlegem.list
36
-
37
32
  expect(list_output.include?(category)).to be true
38
33
  end
39
-
40
- it "can generate the built-in gems fine" do
34
+
35
+ # what template is it being generated from? Default?
36
+ it "can generate the default built-in gem fine" do
41
37
  options = {"bin"=>false, "ext"=>false, :coc=> false}
42
- gem_name = "tmp_gem" # gem name
38
+ gem_name = "tmp_gem"
39
+
40
+ capture_stdout { Bundlegem.gem(options, gem_name) }
41
+ expect(File.exists?("#{@dst_dir}/#{gem_name}/README.md")).to be_truthy
42
+ end
43
+
44
+ it "can generate the c_ext gem fine" do
45
+ options = {"bin"=>false, "ext"=>false, :coc=> false, "template" => "c_extension_gem"}
46
+ gem_name = "tmp_gem"
47
+
48
+ capture_stdout { Bundlegem.gem(options, gem_name) }
49
+ expect(File.exists?("#{@dst_dir}/#{gem_name}/ext/tmp_gem/#{gem_name}.c")).to be_truthy
50
+ end
51
+
52
+
53
+ describe "install best templates" do
54
+
55
+ before :each do
56
+ setup_mock_web_template
57
+ end
58
+
59
+ after :each do
60
+ remove_mock_web_template
61
+ end
62
+
63
+ it "can download best templates from the web" do
64
+ capture_stdout { Bundlegem.install_best_templates }
65
+ expect(File.exists?("#{ENV['HOME']}/.bundlegem/templates/arduino/README.md")).to be_truthy
66
+ end
43
67
 
44
- Bundlegem.gem(options, gem_name)
45
68
  end
46
-
69
+
47
70
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ $test_env = true
2
3
  require 'bundlegem'
3
4
  require 'fileutils'
4
5
  require 'pry'
@@ -10,12 +11,25 @@ ENV['HOME'] = "/tmp/bundlegem_mock_home"
10
11
 
11
12
 
12
13
 
14
+
15
+ def setup_mock_web_template
16
+ ENV['best_templates'] = "#{ENV['HOME']}/arduino.git"
17
+ FileUtils.mkdir("#{ENV['HOME']}/arduino.git")
18
+ FileUtils.touch("#{ENV['HOME']}/arduino.git/README.md")
19
+ auth_settings = 'git config --local user.email "you@example.com" && git config --local user.name "test"'
20
+ `cd "#{ENV['HOME']}/arduino.git" && git init && git add . && #{auth_settings} && git commit -m "haxing"`
21
+ end
22
+
23
+ def remove_mock_web_template
24
+ FileUtils.rm_rf("#{ENV['HOME']}/arduino.git")
25
+ end
26
+
13
27
  def create_user_defined_template(category = nil)
14
28
  new_templates_dir = "#{@template_root}/empty_template"
15
-
29
+
16
30
  # Creates the gem template (empty folder)
17
31
  FileUtils.mkdir_p new_templates_dir
18
-
32
+
19
33
  # Writes the category
20
34
  File.open("#{new_templates_dir}/.bundlegem", "w+") do |f|
21
35
  f.puts "category: #{category}" unless category.nil?
@@ -26,8 +40,20 @@ end
26
40
  def reset_test_env
27
41
  FileUtils.rm_rf @mocked_home
28
42
  FileUtils.rm_rf @dst_dir
29
-
43
+
30
44
  FileUtils.mkdir_p @dst_dir
31
45
  FileUtils.mkdir_p @template_root
32
46
  end
33
47
 
48
+ # squelch stdout
49
+ # usage capture_stdout { a_method(a_signal.new, a_model, a_helper) }
50
+ def capture_stdout(&block)
51
+ original_stdout = $stdout
52
+ $stdout = fake = StringIO.new
53
+ begin
54
+ yield
55
+ ensure
56
+ $stdout = original_stdout
57
+ end
58
+ fake.string
59
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundlegem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheNotary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -104,6 +104,7 @@ files:
104
104
  - lib/bundlegem/cli/gem.rb
105
105
  - lib/bundlegem/configurator.rb
106
106
  - lib/bundlegem/friendly_errors.rb
107
+ - lib/bundlegem/strings.rb
107
108
  - lib/bundlegem/template_manager.rb
108
109
  - lib/bundlegem/templates/Executable
109
110
  - lib/bundlegem/templates/Executable.standalone
@@ -118,8 +119,8 @@ files:
118
119
  - lib/bundlegem/templates/c_extension_gem/bin/#{name}.tt
119
120
  - lib/bundlegem/templates/c_extension_gem/bin/console.tt
120
121
  - lib/bundlegem/templates/c_extension_gem/changelog.tt
121
- - lib/bundlegem/templates/c_extension_gem/ext/#{name}/#{newgem}.c.tt
122
- - lib/bundlegem/templates/c_extension_gem/ext/#{name}/#{newgem}.h.tt
122
+ - lib/bundlegem/templates/c_extension_gem/ext/#{name}/#{name}.c.tt
123
+ - lib/bundlegem/templates/c_extension_gem/ext/#{name}/#{name}.h.tt
123
124
  - lib/bundlegem/templates/c_extension_gem/ext/#{name}/extconf.rb.tt
124
125
  - lib/bundlegem/templates/c_extension_gem/gitignore.tt
125
126
  - lib/bundlegem/templates/c_extension_gem/lib/#{name}.rb.tt
@@ -138,8 +139,8 @@ files:
138
139
  - lib/bundlegem/templates/cli_gem/bin/console.tt
139
140
  - lib/bundlegem/templates/cli_gem/changelog.tt
140
141
  - lib/bundlegem/templates/cli_gem/exe/#{name}.tt
141
- - lib/bundlegem/templates/cli_gem/ext/#{name}/#{newgem}.c.tt
142
- - lib/bundlegem/templates/cli_gem/ext/#{name}/#{newgem}.h.tt
142
+ - lib/bundlegem/templates/cli_gem/ext/#{name}/#{name}.c.tt
143
+ - lib/bundlegem/templates/cli_gem/ext/#{name}/#{name}.h.tt
143
144
  - lib/bundlegem/templates/cli_gem/ext/#{name}/extconf.rb.tt
144
145
  - lib/bundlegem/templates/cli_gem/gitignore.tt
145
146
  - lib/bundlegem/templates/cli_gem/lib/#{name}.rb.tt
@@ -201,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  version: '0'
202
203
  requirements: []
203
204
  rubyforge_project:
204
- rubygems_version: 2.4.4
205
+ rubygems_version: 2.5.1
205
206
  signing_key:
206
207
  specification_version: 4
207
208
  summary: this gem makes more gems!