From 556e8f7921ad806ab6003a41678fe1e73563bc90 Mon Sep 17 00:00:00 2001 From: Ashley Willard Date: Thu, 12 Dec 2024 15:49:13 -0800 Subject: [PATCH 1/3] Make README template customizable Allows users to specify a README template other than the default template currently defined in `packs`. --- README.md | 5 +++++ lib/packs/configuration.rb | 15 +++++++++++++++ lib/packs/user_event_logger.rb | 5 +++++ spec/packs_spec.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/README.md b/README.md index 63725a7..7bfb2d1 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ pack_paths: - gems/* # gems can be packs too! ``` +To customize the README template, include a `README_TEMPLATE.md` file in the root of your project. If you want to use a custom path for your README template, you can specify it in the `packs.yml` file in the root of your project: +```yml +readme_template_path: my_folder/README_STUFF.md +``` + # Ecosystem The rest of the [rubyatscale](https://github.com/rubyatscale) ecosystem is intended to help make using packs and improving the boundaries between them more clear. diff --git a/lib/packs/configuration.rb b/lib/packs/configuration.rb index a185e47..226e5d8 100644 --- a/lib/packs/configuration.rb +++ b/lib/packs/configuration.rb @@ -7,6 +7,9 @@ module Packs class Configuration extend T::Sig + CONFIGURATION_PATHNAME = T.let(Pathname.new('packs.yml'), Pathname) + DEFAULT_README_TEMPLATE_PATHNAME = T.let(Pathname.new('README_TEMPLATE.md'), Pathname) + sig { params(enforce_dependencies: T::Boolean).void } attr_writer :enforce_dependencies @@ -45,6 +48,18 @@ def bust_cache! def default_enforce_dependencies true end + + sig { returns(Pathname) } + def readme_template_pathname + config_hash = CONFIGURATION_PATHNAME.exist? ? YAML.load_file(CONFIGURATION_PATHNAME) : {} + + specified_readme_template_path = config_hash['readme_template_path'] + if specified_readme_template_path.nil? + DEFAULT_README_TEMPLATE_PATHNAME + else + Pathname.new(specified_readme_template_path) + end + end end class << self diff --git a/lib/packs/user_event_logger.rb b/lib/packs/user_event_logger.rb index a252405..9950e14 100644 --- a/lib/packs/user_event_logger.rb +++ b/lib/packs/user_event_logger.rb @@ -148,6 +148,11 @@ def on_create_public_directory_todo(pack_name) sig { params(pack_name: String).returns(String) } def on_create_readme_todo(pack_name) + readme_template_pathname = Packs.config.readme_template_pathname + readme_template = readme_template_pathname.read if readme_template_pathname.exist? + + return readme_template unless readme_template.nil? + <<~MSG Welcome to `#{pack_name}`! diff --git a/spec/packs_spec.rb b/spec/packs_spec.rb index 568be16..6fa188f 100644 --- a/spec/packs_spec.rb +++ b/spec/packs_spec.rb @@ -333,6 +333,32 @@ def write_codeownership_config expect(actual_readme_todo.exist?).to eq false end end + + context 'when the app has a README template' do + it 'uses the template to create the README_TODO.md' do + write_file('README_TEMPLATE.md', 'This is the template') + Packs.create_pack!(pack_name: 'packs/organisms') + ParsePackwerk.bust_cache! + actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md') + expect(actual_readme_todo.read).to eq 'This is the template' + end + + context 'and a custom path is specified for the README template' do + before do + write_file('packs.yml', <<~YML) + readme_template_path: my_folder/README_STUFF.md + YML + end + + it 'uses the template to create the README_TODO.md' do + write_file('my_folder/README_STUFF.md', 'This is the template') + Packs.create_pack!(pack_name: 'packs/organisms') + ParsePackwerk.bust_cache! + actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md') + expect(actual_readme_todo.read).to eq 'This is the template' + end + end + end end end From 68847d7026658074ad3aa275ee37424d3f8d61f5 Mon Sep 17 00:00:00 2001 From: Ashley Willard Date: Mon, 16 Dec 2024 14:42:15 -0800 Subject: [PATCH 2/3] bump version --- Gemfile.lock | 2 +- packs.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7621719..c2a9423 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,7 +17,7 @@ GIT PATH remote: . specs: - packs (0.0.45) + packs (0.1.0) bigdecimal code_ownership (>= 1.33.0) packs-specification diff --git a/packs.gemspec b/packs.gemspec index f009b6e..0e909b5 100644 --- a/packs.gemspec +++ b/packs.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'packs' - spec.version = '0.0.45' + spec.version = '0.1.0' spec.authors = ['Gusto Engineers'] spec.email = ['dev@gusto.com'] From 92328dffa0f3d4acbe6bb2ab5d5b432a28ed1b12 Mon Sep 17 00:00:00 2001 From: Ashley Willard Date: Tue, 17 Dec 2024 11:46:36 -0800 Subject: [PATCH 3/3] update text in spec --- spec/packs_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/packs_spec.rb b/spec/packs_spec.rb index 6fa188f..91424b0 100644 --- a/spec/packs_spec.rb +++ b/spec/packs_spec.rb @@ -351,11 +351,11 @@ def write_codeownership_config end it 'uses the template to create the README_TODO.md' do - write_file('my_folder/README_STUFF.md', 'This is the template') + write_file('my_folder/README_STUFF.md', 'This is the custom template') Packs.create_pack!(pack_name: 'packs/organisms') ParsePackwerk.bust_cache! actual_readme_todo = ParsePackwerk.find('packs/organisms').directory.join('README_TODO.md') - expect(actual_readme_todo.read).to eq 'This is the template' + expect(actual_readme_todo.read).to eq 'This is the custom template' end end end