Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Add automatic bootstrapping script makenew.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Jan 20, 2016
1 parent 60a0d86 commit f09d23b
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 83 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in replace_gemname.gemspec.
# Specify your gem's dependencies in makenew-ruby_gem.gemspec.
gemspec
2 changes: 1 addition & 1 deletion Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ end
group :unit do
guard :rspec, cmd: 'bundle exec rspec --color --format Fuubar' do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/replace_gemname/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/makenew/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^spec/.+_spec\.rb$})
watch('spec/spec_helper.rb') { 'spec' }
end
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) replace_yyyy replace_name_of_copyright_owner
Copyright (c) 2016 Evan Sosenko

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
84 changes: 37 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Ruby Gem Skeleton

<!--
[![Gem](https://img.shields.io/gem/v/replace_gemname.svg)](https://rubygems.org/gems/replace_gemname)
-->
[![Gem](https://img.shields.io/gem/v/makenew-ruby_gem.svg)](https://rubygems.org/gems/makenew-ruby_gem)
[![GitHub license](https://img.shields.io/github/license/makenew/ruby-gem.svg)](./LICENSE.txt)
[![Gemnasium](https://img.shields.io/gemnasium/makenew/ruby-gem.svg)](https://gemnasium.com/makenew/ruby-gem)
[![Travis](https://img.shields.io/travis/makenew/ruby-gem.svg)](https://travis-ci.org/makenew/ruby-gem)
[![Codecov](https://img.shields.io/codecov/c/github/makenew/ruby-gem.svg)](https://codecov.io/github/makenew/ruby-gem)
[![Code Climate](https://img.shields.io/codeclimate/github/makenew/ruby-gem.svg)](https://codeclimate.com/github/makenew/ruby-gem)

Use this project freely as a base for your testable Ruby gems.

## Description

Bootstrap a new [Ruby] gem in less than a minute.

[Ruby]: https://www.ruby-lang.org/

### Features

* [Rake] and [Guard] tasks for included tools.
Expand All @@ -35,43 +35,23 @@ Use this project freely as a base for your testable Ruby gems.
[Travis CI]: https://travis-ci.org/
[YARD]: http://yardoc.org/index.html

### Usage

This software can be used freely, see [The Unlicense].
The MIT License text appearing in this software is for
demonstration purposes only and does not apply to this software.
### Bootstrapping a New Project

1. Clone this repository or download a [release][Releases].

2. Customize this README.
- Set the title and summary text.
- Replace the Description section.
- Update the Contributing section.
- Remove or update the badges.
2. Run `./makenew.sh` and follow the prompts.
This will replace the boilerplate, delete itself,
and stage changes for commit.
This script assumes the project repository will be hosted on GitHub.
For an alternative location, you must update the URLs manually.

3. Everything else that should be filled in before using this skeleton
has been marked with the terms `replace` or `Replace`.
You can replace the placeholder gem name with your own using
3. Fill in the README Description section.

```
$ git mv replace_gemname.gemspec your_gemname.gemspec
$ git mv lib/replace_gemname.rb lib/your_gemname.rb
$ git mv lib/replace_gemname lib/your_gemname
$ git ls-files -z | xargs -0 sed -i 's/replace_gemname/your_gemname/g'
$ git ls-files -z | xargs -0 sed -i 's/ReplaceGemname/YourGemname/g'
```

To see a list of what else still needs to be replaced, run

```
$ grep -Ri replace
$ find . -name "*replace*"
```

Note that `CHANGELOG.md` is just a template for this skeleton.
The actual changes for this project are documented in the commit history
and summarized under [Releases].
4. If [choosing a license][Choose a license] other than the one provided:
update `LICENSE.txt`, the README License section, and the gemspec file
with your chosen license.

[Choose a license]: http://choosealicense.com/
[Releases]: https://github.com/makenew/ruby-gem/releases
[The Unlicense]: http://unlicense.org/UNLICENSE

Expand Down Expand Up @@ -102,12 +82,18 @@ $ git fetch upstream
$ git merge upstream/master
```

#### Changelog

Note that `CHANGELOG.md` is just a template for this skeleton.
The actual changes for this project are documented in the commit history
and summarized under [Releases].

## Installation

Add this line to your application's [Gemfile][Bundler]

```ruby
gem 'replace_gemname'
gem 'makenew-ruby_gem'
```

and update your bundle with
Expand All @@ -119,7 +105,7 @@ $ bundle
Or install it yourself with

```
$ gem install replace_gemname
$ gem install makenew-ruby_gem
```

[Bundler]: http://bundler.io/
Expand All @@ -129,28 +115,28 @@ $ gem install replace_gemname
- [YARD documentation][RubyDoc] is hosted by RubyDoc.info.
- [Interactive documentation][Omniref] is hosted by Omniref.

[RubyDoc]: http://www.rubydoc.info/gems/replace_gemname
[Omniref]: https://www.omniref.com/ruby/gems/replace_gemname
[RubyDoc]: http://www.rubydoc.info/gems/makenew-ruby_gem
[Omniref]: https://www.omniref.com/ruby/gems/makenew-ruby_gem

## Development and Testing

### Source Code

The [replace_gemname source] is hosted on GitHub.
The [makenew-ruby_gem source] is hosted on GitHub.
Clone the project with

```
$ git clone https://github.com/replace_username/replace_gemname.git
$ git clone https://github.com/makenew/ruby-gem.git
```

[replace_gemname source]: https://github.com/replace_username/replace_gemname
[makenew-ruby_gem source]: https://github.com/makenew/ruby-gem

### Rake

Run `$ rake -T` to see all Rake tasks.

```
rake build # Build replace_gemname-0.0.0.gem into the pkg directory
rake build # Build makenew-ruby_gem-2.0.0.gem into the pkg directory
rake bump:current[tag] # Show current gem version
rake bump:major[tag] # Bump major part of gem version
rake bump:minor[tag] # Bump minor part of gem version
Expand All @@ -159,9 +145,9 @@ rake bump:pre[tag] # Bump pre part of gem version
rake bump:set # Sets the version number using the VERSION environment variable
rake clean # Remove any temporary products
rake clobber # Remove any generated files
rake install # Build and install replace_gemname-0.0.0.gem into system gems
rake install:local # Build and install replace_gemname-0.0.0.gem into system gems without network access
rake release[remote] # Create tag v0.0.0 and build and push replace_gemname-0.0.0.gem to Rubygems
rake install # Build and install makenew-ruby_gem-2.0.0.gem into system gems
rake install:local # Build and install makenew-ruby_gem-2.0.0.gem into system gems without network access
rake release[remote] # Create tag v2.0.0 and build and push makenew-ruby_gem-2.0.0.gem to Rubygems
rake rubocop # Run RuboCop
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rake spec # Run RSpec code examples
Expand Down Expand Up @@ -190,6 +176,10 @@ To submit a patch:

## License

This software can be used freely, see [The Unlicense].
The copyright text appearing below and elsewhere in this repository
is for demonstration purposes only and does not apply to this software.

This Ruby gem is licensed under the MIT license.

## Warranty
Expand Down
2 changes: 2 additions & 0 deletions lib/makenew.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'makenew/version'
require 'makenew/ruby_gem'
5 changes: 5 additions & 0 deletions lib/makenew/ruby_gem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Makenew
# Primary class for this module.
class RubyGem
end
end
6 changes: 6 additions & 0 deletions lib/makenew/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
# Primary module for this gem.
module Makenew
# Current Makenew version.
VERSION = '2.0.0'.freeze
end
2 changes: 0 additions & 2 deletions lib/replace_gemname.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/replace_gemname/replace_cls.rb

This file was deleted.

6 changes: 0 additions & 6 deletions lib/replace_gemname/version.rb

This file was deleted.

16 changes: 8 additions & 8 deletions replace_gemname.gemspec → makenew-ruby_gem.gemspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'replace_gemname/version'
require 'makenew/version'

Gem::Specification.new do |spec|
spec.name = 'replace_gemname'
spec.version = ReplaceGemname::VERSION
spec.authors = ['replace_author']
spec.email = ['replace@example.com']
spec.description = %q{ReplaceDescription.}
spec.summary = %q{ReplaceSummary.}
spec.homepage = 'https://github.com/replace_user/replace_gemname'
spec.name = 'makenew-ruby_gem'
spec.version = Makenew::VERSION
spec.authors = ['Evan Sosenko']
spec.email = ['razorx@evansosenko.com']
spec.description = %q{Ruby gem skeleton.}
spec.summary = %q{Ruby gem skeleton from makenew.}
spec.homepage = 'https://github.com/makenew/ruby-gem'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
Expand Down
80 changes: 80 additions & 0 deletions makenew.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env sh

set -e
set -u

find_replace () {
git ls-files -z | xargs -0 sed -i "$1"
}

check_env () {
test -d .git || (echo 'This is not a Git repository. Exiting.' && exit 1)
for cmd in ${1}; do
command -v ${cmd} >/dev/null 2>&1 || \
(echo "Could not find '$cmd' which is required to continue." && exit 2)
done
echo
echo 'Ready to bootstrap your new project!'
echo
}

stage_env () {
echo
git rm -f makenew.sh
echo
echo 'Staging changes.'
git add --all
echo
echo 'Done!'
echo
}

makenew () {
read -p '> Package title: ' mk_title
read -p '> Gem name (slug): ' mk_slug
read -p '> Gem description: ' mk_description
read -p '> Gem summary: ' mk_summary
read -p '> Version number: ' mk_version
read -p '> Module name: ' mk_module
read -p '> Module directory name: ' mk_module_dir
read -p '> Class name: ' mk_class
read -p '> Class file name (without .rb extension): ' mk_class_file
read -p '> Author name: ' mk_author
read -p '> Author email: ' mk_email
read -p '> Copyright owner: ' mk_owner
read -p '> Copyright year: ' mk_year
read -p '> GitHub user or organization name: ' mk_user
read -p '> GitHub repository name: ' mk_project

sed -i -e '12,89d;178,181d' README.md
sed -i -e "12i ${mk_description}" README.md

find_replace "s/VERSION =.*/VERSION = '${mk_version}'.freeze/g"
find_replace "s/0\.0\.0\.\.\./${mk_version}.../g"
find_replace "s/Ruby Gem Skeleton/${mk_title}/g"
find_replace "s/Ruby gem skeleton\./${mk_description}/g"
find_replace "s/Ruby gem skeleton from makenew\./${mk_summary}/g"
find_replace "s/2016 Evan Sosenko/${mk_year} ${mk_owner}/g"
find_replace "s/Evan Sosenko/${mk_author}/g"
find_replace "s/razorx@evansosenko\.com/${mk_email}/g"
find_replace "s/makenew\/ruby-gem/${mk_user}\/${mk_project}/g"
find_replace "s/makenew-ruby_gem/${mk_slug}/g"
find_replace "s/Makenew/${mk_module}/g"
find_replace "s/RubyGem/${mk_class}/g"
find_replace "s/'makenew\/ruby_gem/'${mk_module_dir}\/${mk_class_file}/g"
find_replace "s/'makenew/'${mk_module_dir}/g"
find_replace "s/lib\/makenew/lib\/${mk_module_dir}/g"

git mv makenew-ruby_gem.gemspec ${mk_slug}.gemspec
git mv lib/makenew/ruby_gem.rb lib/makenew/${mk_class_file}.rb
git mv lib/makenew.rb lib/${mk_module_dir}.rb
git mv lib/makenew lib/${mk_module_dir}

echo
echo 'Replacing boilerplate.'
}

check_env 'git read sed xargs'
makenew
stage_env
exit
11 changes: 0 additions & 11 deletions spec/replace_cls_spec.rb

This file was deleted.

11 changes: 11 additions & 0 deletions spec/ruby_gem_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe Makenew::RubyGem do
subject(:ruby_gem) { Makenew::RubyGem.new }

describe ".new" do
it "makes a new instance" do
expect(ruby_gem).to be_a Makenew::RubyGem
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
end

require 'replace_gemname'
require 'makenew'

RSpec.configure do |c|
c.expect_with(:rspec) { |e| e.syntax = :expect }
Expand Down

0 comments on commit f09d23b

Please sign in to comment.