From c35efda394d40222342ace45a1e10ae2c07b1e6a Mon Sep 17 00:00:00 2001 From: Andy Cohen Date: Wed, 13 Aug 2025 11:59:02 -0500 Subject: [PATCH 1/2] [SPIKE] New Generator generator --- bin/new_generator | 27 +++++++++++++++++++ .../generator/%name%_generator.rb.tt | 9 +++++++ .../templates/generator/README.md.tt | 11 ++++++++ lib/generators/templates/generator/USAGE.tt | 5 ++++ 4 files changed, 52 insertions(+) create mode 100755 bin/new_generator create mode 100644 lib/generators/templates/generator/%name%_generator.rb.tt create mode 100644 lib/generators/templates/generator/README.md.tt create mode 100644 lib/generators/templates/generator/USAGE.tt diff --git a/bin/new_generator b/bin/new_generator new file mode 100755 index 00000000..e60fa547 --- /dev/null +++ b/bin/new_generator @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +require 'thor' + +class NewGenerator < Thor::Group + include Thor::Actions + + argument :name, type: :string + argument :description, type: :string, default: 'A new generator for RoleModel' + + def self.source_root + File.expand_path('lib/generators/templates') + end + + def self.destination_root + File.expand_path('lib/generators/rolemodel') + end + + def generate_generator_files + directory 'generator', "#{name}" + end + + def generate_generator_spec + # TODO: stub out spec file in proper location + end +end + +NewGenerator.start diff --git a/lib/generators/templates/generator/%name%_generator.rb.tt b/lib/generators/templates/generator/%name%_generator.rb.tt new file mode 100644 index 00000000..22c393f5 --- /dev/null +++ b/lib/generators/templates/generator/%name%_generator.rb.tt @@ -0,0 +1,9 @@ +module Rolemodel + class <%= name %>Generator < Rails::Generators::Base + source_root File.expand_path('templates', __dir__) + + def generate_stuff + say 'generating stuff', :green + end + end +end diff --git a/lib/generators/templates/generator/README.md.tt b/lib/generators/templates/generator/README.md.tt new file mode 100644 index 00000000..0918ef88 --- /dev/null +++ b/lib/generators/templates/generator/README.md.tt @@ -0,0 +1,11 @@ +# <%= name %> Generator + +<%= description %> + +## Prerequisites + + - ... + +## What you get + + - ... diff --git a/lib/generators/templates/generator/USAGE.tt b/lib/generators/templates/generator/USAGE.tt new file mode 100644 index 00000000..5bd22b38 --- /dev/null +++ b/lib/generators/templates/generator/USAGE.tt @@ -0,0 +1,5 @@ +Description: + <%= description %> + +Example: + rails generate rolemodel:<%= name %> From 1809a61cfa5d51296c4d230152c821ef617631c5 Mon Sep 17 00:00:00 2001 From: Andy Cohen Date: Wed, 13 Aug 2025 12:02:28 -0500 Subject: [PATCH 2/2] fix destination path --- bin/new_generator | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/new_generator b/bin/new_generator index e60fa547..864509d3 100755 --- a/bin/new_generator +++ b/bin/new_generator @@ -11,12 +11,8 @@ class NewGenerator < Thor::Group File.expand_path('lib/generators/templates') end - def self.destination_root - File.expand_path('lib/generators/rolemodel') - end - def generate_generator_files - directory 'generator', "#{name}" + directory 'generator', "lib/generators/rolemodel/#{name}" end def generate_generator_spec