beadme 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.markdown +61 -0
- data/bin/beadme +4 -0
- data/lib/beadme/runner.rb +63 -0
- data/lib/beadme/template.rb +84 -0
- data/lib/beadme.rb +55 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 505ccb5bfa83400fe2cd60e5382c99f52fae242ef34f0400396b58324982112f
|
4
|
+
data.tar.gz: 14b5fceb1c0733093c56fa486b757f63ff441ee0516d2563db7d29af39f7d4e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36d3abfa211d9e778b9d44106697b2f3452581621bd3df520bfe89b8e2252e1baa85b405c49d06719aa6109b2fd932bf35f4018e91337793634ba2b6da43950d
|
7
|
+
data.tar.gz: 4a33a0df630f7dab64c456fe58418b23f7effb9c72a1d5a5dc8d5af7399a0423b4176524d5dbcabe2b510399df4e37a67d82369f0da97e1a55297dcc0fb4f733
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Wai Yan Phyo
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
|
2
|
+
|
3
|
+
# Beadme - Build Readme 😂
|
4
|
+
|
5
|
+
This is a simple CLI tool to create a README.md for your project.
|
6
|
+
Don't take is seriously, I just wanted to try out some Ruby stuff.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
```sh
|
10
|
+
gem install beadme`
|
11
|
+
```
|
12
|
+
|
13
|
+
## Install from source code
|
14
|
+
|
15
|
+
Install via Bundler:
|
16
|
+
|
17
|
+
|
18
|
+
```sh
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Using ruby:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
ruby bin/beadme
|
28
|
+
```
|
29
|
+
|
30
|
+
or using the executable:
|
31
|
+
|
32
|
+
### Make it executable
|
33
|
+
|
34
|
+
```sh
|
35
|
+
chmod +x bin/beadme
|
36
|
+
```
|
37
|
+
|
38
|
+
### Run it
|
39
|
+
|
40
|
+
```sh
|
41
|
+
bin/beadme
|
42
|
+
```
|
43
|
+
|
44
|
+
## Help
|
45
|
+
|
46
|
+
Run `beadme -h` to see the help message:
|
47
|
+
|
48
|
+
```sh
|
49
|
+
beadme - A CLI tool to create a README.md for your project
|
50
|
+
|
51
|
+
Version: 0.0.1
|
52
|
+
|
53
|
+
Commands:
|
54
|
+
beadme -h, --help # Display this help message
|
55
|
+
beadme -v, --version # Show version
|
56
|
+
|
57
|
+
Options:
|
58
|
+
-o, [--output=OUTPUT] # Output directory
|
59
|
+
# Default: Current directory
|
60
|
+
```
|
61
|
+
|
data/bin/beadme
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require_relative './template'
|
4
|
+
require_relative '../beadme'
|
5
|
+
|
6
|
+
module Beadme
|
7
|
+
class Runner < Thor
|
8
|
+
class_option :output, aliases: '-o', type: :string, desc: 'Output directory (default: current directory)'
|
9
|
+
|
10
|
+
desc 'create', 'Create a new Readme file', hide: true
|
11
|
+
def create
|
12
|
+
say "#{Beadme.configuration.messages[:welcome]}\n"
|
13
|
+
puts options[:output]
|
14
|
+
|
15
|
+
Template.new(
|
16
|
+
# update this line to use the new configuration
|
17
|
+
# template: custom_template,
|
18
|
+
# questions: custom_questions,
|
19
|
+
dir: options[:output] || Dir.pwd
|
20
|
+
).create
|
21
|
+
end
|
22
|
+
|
23
|
+
default_task :create
|
24
|
+
|
25
|
+
desc '-v, --version', 'Show version'
|
26
|
+
map %w[-v --version] => :version
|
27
|
+
def version
|
28
|
+
puts VERSION
|
29
|
+
end
|
30
|
+
|
31
|
+
desc '-h, --help', 'Display this help message'
|
32
|
+
def help(*)
|
33
|
+
say Beadme.configuration.messages[:about]
|
34
|
+
say "\nVersion: #{VERSION}\n\n"
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.banner(command, _namespace = nil, _subcommand = false)
|
39
|
+
"#{basename} #{command.usage}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.start(args = ARGV, config = {})
|
43
|
+
# I don't want to use commands like `beadme help` or `beadme version`
|
44
|
+
# I want to use `beadme -h` or `beadme -v` instead
|
45
|
+
# So I need to filter out the commands
|
46
|
+
filter_commands = public_instance_methods(false).map(&:to_s)
|
47
|
+
invalids = filter_commands & args
|
48
|
+
raise UndefinedCommandError.new(invalids.first, [], nil) if invalids.any?
|
49
|
+
|
50
|
+
super
|
51
|
+
rescue Thor::Error => e
|
52
|
+
warn e.message
|
53
|
+
exit 1
|
54
|
+
rescue Interrupt
|
55
|
+
warn "\nAborted!"
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.exit_on_failure?
|
60
|
+
true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'thor/shell'
|
3
|
+
|
4
|
+
class ::String
|
5
|
+
def to_list
|
6
|
+
split(',').map(&:strip).reject(&:empty?).map(&:capitalize)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Beadme
|
11
|
+
# This class is responsible for generating the README.md file
|
12
|
+
class Template
|
13
|
+
include Thor::Shell
|
14
|
+
|
15
|
+
attr_reader :template, :questions, :dir, :save_path
|
16
|
+
|
17
|
+
def ask(question, color = nil)
|
18
|
+
say question, color
|
19
|
+
print '> '
|
20
|
+
super ''
|
21
|
+
ensure
|
22
|
+
puts ''
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(
|
26
|
+
template: Beadme.configuration.default_template,
|
27
|
+
questions: Beadme.configuration.default_questions,
|
28
|
+
dir: Dir.pwd
|
29
|
+
)
|
30
|
+
@template = template
|
31
|
+
@questions = questions
|
32
|
+
@dir = dir
|
33
|
+
@save_path = File.join(dir, 'README.md')
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create the README.md file
|
37
|
+
def create
|
38
|
+
check_dir
|
39
|
+
check_file
|
40
|
+
|
41
|
+
erb = ERB.new(template)
|
42
|
+
|
43
|
+
# ERB template will use this variable to populate the content
|
44
|
+
data = ask_questions
|
45
|
+
File.write(save_path, erb.result(binding))
|
46
|
+
|
47
|
+
print 'Successfully generate Readme.md in '
|
48
|
+
say save_path, :green
|
49
|
+
rescue ArgumentError => e
|
50
|
+
say e.message
|
51
|
+
exit 1
|
52
|
+
rescue StandardError => e
|
53
|
+
say "An error occurred while generating the README.md \n file: #{e.message}"
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def check_dir
|
60
|
+
raise ArgumentError, "#{dir} does not exist" unless File.exist?(dir)
|
61
|
+
raise ArgumentError, "#{dir} is not a directory" unless File.directory?(dir)
|
62
|
+
raise ArgumentError, "#{dir} is not writable" unless File.writable?(dir)
|
63
|
+
end
|
64
|
+
|
65
|
+
def check_file
|
66
|
+
return unless File.exist?(save_path)
|
67
|
+
|
68
|
+
say 'README.md already exists in this directory'
|
69
|
+
exit(1) unless yes?('Do you want to overwrite it? (y/N)', :red)
|
70
|
+
end
|
71
|
+
|
72
|
+
def ask_questions
|
73
|
+
data = {}
|
74
|
+
questions.each_with_index do |value, i|
|
75
|
+
key, question = value
|
76
|
+
answer = ask "#{i + 1}. #{question}", :blue
|
77
|
+
answer = answer.to_list if key.to_s.include?('stack') or key.to_s.include?('features')
|
78
|
+
|
79
|
+
data[key] = answer
|
80
|
+
end
|
81
|
+
data
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/beadme.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Beadme
|
4
|
+
module Utils
|
5
|
+
# Find a file or directory in the project
|
6
|
+
# Raises an error if the file or directory does not exist
|
7
|
+
def self.get_path(*path_parts, root: File.join(__dir__, '..'))
|
8
|
+
path = File.join(root, *path_parts)
|
9
|
+
unless File.exist?(path)
|
10
|
+
raise ArgumentError,
|
11
|
+
"File or directory does not exist: #{path}"
|
12
|
+
end
|
13
|
+
path
|
14
|
+
end
|
15
|
+
|
16
|
+
# Load a YAML file and convert all keys to symbols
|
17
|
+
def self.load_yaml(file)
|
18
|
+
YAML.load_file(file).transform_keys(&:to_sym)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Defaults
|
23
|
+
TEMPLATE_FILE = Utils.get_path('templates', 'microverse.md.erb')
|
24
|
+
QUESTIONS_FILE = Utils.get_path('config', 'questions.yml')
|
25
|
+
MESSAGES_FILE = Utils.get_path('config', 'messages.yml')
|
26
|
+
end
|
27
|
+
|
28
|
+
class Configuration
|
29
|
+
def default_template
|
30
|
+
File.read(Defaults::TEMPLATE_FILE)
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_questions
|
34
|
+
Utils.load_yaml(Defaults::QUESTIONS_FILE)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Get messages like welcome, help, etc.
|
38
|
+
# To display them in the terminal
|
39
|
+
def messages
|
40
|
+
Utils.load_yaml(Defaults::MESSAGES_FILE)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self
|
45
|
+
def configuration
|
46
|
+
@configuration ||= Configuration.new
|
47
|
+
end
|
48
|
+
|
49
|
+
def configure
|
50
|
+
yield(configuration)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
VERSION = '0.0.1'.freeze
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beadme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wai Yan Phyo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-04-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: README generator for projects
|
14
|
+
email: oyhpnayiaw@gmail.com
|
15
|
+
executables:
|
16
|
+
- beadme
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.markdown
|
22
|
+
- bin/beadme
|
23
|
+
- lib/beadme.rb
|
24
|
+
- lib/beadme/runner.rb
|
25
|
+
- lib/beadme/template.rb
|
26
|
+
homepage: https://rubygems.org/gems/beadme
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata:
|
30
|
+
source_code_uri: https://github.com/oyhpnayiaw/beadme
|
31
|
+
rubygems_mfa_required: 'true'
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.6.0
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubygems_version: 3.4.10
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: README.md generator
|
51
|
+
test_files: []
|