mk.rb 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23dd64ef436e3a4d9dc32072fc4584bd62573ebe8a73c096f25b01340fe7d441
4
+ data.tar.gz: a32bf87baf298c11590c504f2780b8468bc68d3c44eb5f18b26851f0d8902593
5
+ SHA512:
6
+ metadata.gz: 1fbad341e01332ca7756624cd272b7de016a4a13b4869837f11a3df6726434a4b330fd799da9c6c4ad104d8c9429003768b1dd76aa5a024e7c64495ddc989206
7
+ data.tar.gz: c7fc9482ab8e648aca71114d9f3aadfad91aad7c0e45878386773be0d1cf83d30cb5ac51b06f3683529cfc8ba2c4924d16a320ea12fcd66bb955f2858a6e965b
@@ -0,0 +1,47 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: "3.3"
24
+
25
+ - name: Build gem
26
+ run: gem build *.gemspec
27
+
28
+ - name: Publish to GPR
29
+ if: github.event_name == 'push'
30
+ run: |
31
+ mkdir -p $HOME/.gem
32
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
33
+ chmod 0600 $HOME/.gem/credentials
34
+ gem push --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem
35
+ env:
36
+ GEM_HOST_API_KEY: "Bearer ${{ secrets.GITHUB_TOKEN }}"
37
+ OWNER: ${{ github.repository_owner }}
38
+
39
+ - name: Publish to RubyGems
40
+ if: github.event_name == 'push'
41
+ run: |
42
+ mkdir -p $HOME/.gem
43
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
44
+ chmod 0600 $HOME/.gem/credentials
45
+ gem push *.gem
46
+ env:
47
+ GEM_HOST_API_KEY: "${{ secrets.RUBYGEMS_AUTH_TOKEN }}"
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ #gem "minitest", "~> 5.0"
9
+ #gem "rake", "~> 13.0"
10
+ #gem "rubocop", "~> 1.21"
11
+ #gem "yard", "~> 0.9"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mirrorfile (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.3)
10
+ json (2.18.0)
11
+ language_server-protocol (3.17.0.5)
12
+ lint_roller (1.1.0)
13
+ minitest (5.27.0)
14
+ parallel (1.27.0)
15
+ parser (3.3.10.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ prism (1.7.0)
19
+ racc (1.8.1)
20
+ rainbow (3.1.1)
21
+ rake (13.3.1)
22
+ regexp_parser (2.11.3)
23
+ rubocop (1.82.1)
24
+ json (~> 2.3)
25
+ language_server-protocol (~> 3.17.0.2)
26
+ lint_roller (~> 1.1.0)
27
+ parallel (~> 1.10)
28
+ parser (>= 3.3.0.2)
29
+ rainbow (>= 2.2.2, < 4.0)
30
+ regexp_parser (>= 2.9.3, < 3.0)
31
+ rubocop-ast (>= 1.48.0, < 2.0)
32
+ ruby-progressbar (~> 1.7)
33
+ unicode-display_width (>= 2.4.0, < 4.0)
34
+ rubocop-ast (1.49.0)
35
+ parser (>= 3.3.7.2)
36
+ prism (~> 1.7)
37
+ ruby-progressbar (1.13.0)
38
+ unicode-display_width (3.2.0)
39
+ unicode-emoji (~> 4.1)
40
+ unicode-emoji (4.2.0)
41
+ yard (0.9.38)
42
+
43
+ PLATFORMS
44
+ ruby
45
+ x86_64-linux
46
+
47
+ DEPENDENCIES
48
+ minitest (~> 5.0)
49
+ mirrorfile!
50
+ rake (~> 13.0)
51
+ rubocop (~> 1.21)
52
+ yard (~> 0.9)
53
+
54
+ BUNDLED WITH
55
+ 2.7.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # mk
2
+
3
+ A CLI tool to create new projects from templates.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ gem install mk
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ mk <template_name> <project_name>
15
+ ```
16
+
17
+ This will:
18
+ 1. Copy the template to `./<project_name>`
19
+ 2. Replace `ExampleGem` with your project's constant name (e.g., `MyProject`)
20
+ 3. Replace `examplegem` with your project name (e.g., `my_project`)
21
+ 4. Rename any files containing these placeholders
22
+
23
+ ### Example
24
+
25
+ ```bash
26
+ mk ruby my_awesome_gem
27
+ ```
28
+
29
+ Creates a new directory `my_awesome_gem` from the `ruby` template with all placeholders replaced.
30
+
31
+ ## Templates
32
+
33
+ Templates are searched in this order:
34
+
35
+ 1. `~/templates/<template_name>` - Your local templates (takes priority)
36
+ 2. Bundled templates included with the gem
37
+
38
+ To override a bundled template, create one with the same name in `~/templates/`.
39
+
40
+ ### Creating Templates
41
+
42
+ Templates are regular directories containing your project boilerplate. Use these placeholders:
43
+
44
+ - `ExampleGem` - Replaced with the constant name (e.g., `MyAwesomeGem`)
45
+ - `examplegem` - Replaced with the project name (e.g., `my_awesome_gem`)
46
+
47
+ Placeholders work in both file contents and file/directory names.
48
+
49
+ #### Example
50
+
51
+ ```bash
52
+ mk ruby my_gem
53
+ ```
54
+
55
+ Template file `~/templates/ruby/lib/examplegem.rb`:
56
+
57
+ ```ruby
58
+ class ExampleGem
59
+ VERSION = "0.1.0"
60
+ end
61
+ ```
62
+
63
+ Output file `my_gem/lib/my_gem.rb`:
64
+
65
+ ```ruby
66
+ class MyGem
67
+ VERSION = "0.1.0"
68
+ end
69
+ ```
70
+
71
+ ## Contributing
72
+
73
+ Bug reports and pull requests are welcome on GitHub.
74
+
75
+ ## Development
76
+
77
+ After checking out the repo:
78
+
79
+ ```bash
80
+ bin/setup
81
+ bundle exec rake test
82
+ ```
83
+
84
+ Generate documentation:
85
+
86
+ ```bash
87
+ bundle exec yard doc
88
+ bundle exec yard server # Browse at http://localhost:8808
89
+ ```
90
+
91
+ ## License
92
+
93
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ #require "bundler/gem_tasks"
4
+ #require "rake/testtask"
5
+ #require "yard"
6
+ #
7
+ #Rake::TestTask.new(:test) do |t|
8
+ # t.libs << "test"
9
+ # t.libs << "lib"
10
+ # t.test_files = FileList["test/**/*_test.rb"]
11
+ #end
12
+ #
13
+ #YARD::Rake::YardocTask.new do |t|
14
+ # t.files = ["lib/**/*.rb"]
15
+ # t.options = ["--markup", "markdown"]
16
+ #end
17
+ #
18
+ #task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "mk"
6
+ require "irb"
7
+
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
data/exe/mk ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/mk"
5
+
6
+ exit Mk::CLI.new.call(ARGV)
data/lib/mk/cli.rb ADDED
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mk
4
+ class CLI
5
+ def call(args)
6
+ if args.length < 2
7
+ puts "Usage: mk <template_name> <project_name>"
8
+ return 1
9
+ end
10
+
11
+ template_name = args[0]
12
+ folder_name = args[1]
13
+ project_name = folder_name.sub(/\..*\z/, "")
14
+ constant_name = project_name.downcase.split(/[-_]/).map(&:capitalize).join
15
+
16
+ template_path = find_template(template_name)
17
+ unless template_path
18
+ puts "Template not found: #{template_name}"
19
+ return 1
20
+ end
21
+
22
+ system("cp", "-r", template_path, "./#{folder_name}")
23
+
24
+ replace_in_files(folder_name, project_name, constant_name)
25
+ rename_files(folder_name, project_name, constant_name)
26
+
27
+ puts "Created #{folder_name} from #{template_name} template"
28
+ 0
29
+ end
30
+
31
+ private
32
+
33
+ def find_template(template_name)
34
+ user_path = File.expand_path("~/templates/#{template_name}")
35
+ return user_path if Dir.exist?(user_path)
36
+
37
+ gem_path = File.expand_path("../../templates/#{template_name}", __dir__)
38
+ return gem_path if Dir.exist?(gem_path)
39
+
40
+ nil
41
+ end
42
+
43
+ def replace_in_files(folder_name, project_name, constant_name)
44
+ Dir.glob("#{folder_name}/**/*", File::FNM_DOTMATCH).lazy
45
+ .reject { |path| File.directory?(path) }
46
+ .each do |file_path|
47
+ content = File.read(file_path)
48
+ updated_content = content
49
+ .gsub("ExampleGem", constant_name)
50
+ .gsub("examplegem", project_name)
51
+
52
+ File.write(file_path, updated_content)
53
+ end
54
+ end
55
+
56
+ def rename_files(folder_name, project_name, constant_name)
57
+ loop do
58
+ found_file = Dir.glob("#{folder_name}/**/*", File::FNM_DOTMATCH)
59
+ .lazy
60
+ .select { |path| path.match?(/examplegem|ExampleGem/) }
61
+ .first
62
+
63
+ if found_file
64
+ new_path = found_file
65
+ .gsub("ExampleGem", constant_name)
66
+ .gsub("examplegem", project_name)
67
+
68
+ File.rename(found_file, new_path)
69
+ else
70
+ break
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
data/lib/mk/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mk
4
+ VERSION = "1.0.0"
5
+ end
data/lib/mk.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mk/version"
4
+ require_relative "mk/cli"
5
+
6
+ module Mk
7
+ end
data/mk.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mk/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mk.rb"
7
+ spec.version = Mk::VERSION
8
+ spec.authors = ["Nathan Kidd"]
9
+ spec.email = ["nathankidd@hey.com"]
10
+
11
+ spec.summary = "Create new projects from templates"
12
+
13
+ spec.description = <<~DESC
14
+ A CLI tool to create new projects from templates stored in ~/templates.
15
+ DESC
16
+
17
+ spec.homepage = "https://github.com/n-at-han-k/mk.rb"
18
+ spec.license = "MIT"
19
+ spec.required_ruby_version = ">= 3.2.0"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["documentation_uri"] = spec.homepage
24
+ spec.metadata["rubygems_mfa_required"] = "true"
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|data)/}) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ spec.add_development_dependency "rake", "~> 13.0"
33
+ spec.add_development_dependency "rubocop", "~> 1.21"
34
+ spec.add_development_dependency "yard", "~> 0.9"
35
+ end
File without changes
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mk.rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Kidd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.21'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.21'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ description: 'A CLI tool to create new projects from templates stored in ~/templates.
70
+
71
+ '
72
+ email:
73
+ - nathankidd@hey.com
74
+ executables:
75
+ - mk
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".github/workflows/gem-push.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/mk
88
+ - lib/mk.rb
89
+ - lib/mk/cli.rb
90
+ - lib/mk/version.rb
91
+ - mk.gemspec
92
+ - templates/.gitkeep
93
+ homepage: https://github.com/n-at-han-k/mk.rb
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/n-at-han-k/mk.rb
98
+ source_code_uri: https://github.com/n-at-han-k/mk.rb
99
+ documentation_uri: https://github.com/n-at-han-k/mk.rb
100
+ rubygems_mfa_required: 'true'
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 3.2.0
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.5.22
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Create new projects from templates
120
+ test_files: []