gem_generator 0.3.1 → 0.3.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fe2385e7d9a9cfb6f5fcb76d8274bf16167fad4c735c1e0a54b6aec6fd591bd
|
4
|
+
data.tar.gz: d6a9bcf7df03caa8e69b5a7c339a48757453599f31fd6fa300814fa8c7f39c72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd0aea83cf29f769c8447412aea0ebbd67a27a810cf147eda78ea1256a3634f0f024b5f8eeb4717ee00ff4e7bcf6b0f7e88035676caac4a13ada024df5be628f
|
7
|
+
data.tar.gz: bb8e82a95a63a8262dca93576e299f4e78f79ba1e2f76813ae06db194981806c55d4eb209031a969f196e7f6654ef7bc5f4d4cee6a9eba41db90ad2d3cf71436
|
data/CHANGELOG.md
CHANGED
@@ -1,42 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'yaml'
|
4
|
-
require 'memery'
|
5
3
|
require 'gorilla_patch/blank'
|
6
|
-
require 'gorilla_patch/inflections'
|
7
4
|
|
8
5
|
module GemGenerator
|
9
6
|
## Main CLI command for Gem Generator
|
10
|
-
class Command <
|
7
|
+
class Command < ProjectGenerator::Command
|
11
8
|
## Private instance methods for processing template files (copying, renaming, rendering)
|
12
9
|
module ProcessFiles
|
13
10
|
## Class for a single object which should be a scope in render
|
14
|
-
class RenderVariables
|
15
|
-
include Memery
|
16
|
-
|
11
|
+
class RenderVariables < ProjectGenerator::Command::ProcessFiles::RenderVariables
|
17
12
|
using GorillaPatch::Blank
|
18
|
-
using GorillaPatch::Inflections
|
19
13
|
|
20
|
-
attr_reader :
|
14
|
+
attr_reader :summary
|
21
15
|
|
22
16
|
def initialize(name, namespace_option, indentation, summary)
|
23
|
-
|
17
|
+
super name, indentation
|
18
|
+
|
24
19
|
@namespace_option = namespace_option
|
25
|
-
@indentation = indentation
|
26
20
|
@summary = summary
|
27
21
|
|
28
22
|
## Call to be sure that this is checked before author fields
|
29
23
|
github_namespace
|
30
24
|
end
|
31
25
|
|
32
|
-
## `public :binding` and `send :binding` return caller binding
|
33
|
-
## This is from ERB documentation: https://ruby-doc.org/core-2.7.2/Binding.html
|
34
|
-
# rubocop:disable Naming/AccessorMethodName
|
35
|
-
def get_binding
|
36
|
-
binding
|
37
|
-
end
|
38
|
-
# rubocop:enable Naming/AccessorMethodName
|
39
|
-
|
40
26
|
memoize def summary_string
|
41
27
|
quote = summary.include?("'") ? '"' : "'"
|
42
28
|
"#{quote}#{summary}#{quote}"
|
@@ -46,22 +32,6 @@ module GemGenerator
|
|
46
32
|
summary.match?(/[.?!]$/) ? summary : "#{summary}."
|
47
33
|
end
|
48
34
|
|
49
|
-
memoize def path
|
50
|
-
name.tr('-', '/')
|
51
|
-
end
|
52
|
-
|
53
|
-
memoize def title
|
54
|
-
name.split(/[-_]/).map(&:camelize).join(' ')
|
55
|
-
end
|
56
|
-
|
57
|
-
memoize def module_name
|
58
|
-
path.camelize
|
59
|
-
end
|
60
|
-
|
61
|
-
memoize def modules
|
62
|
-
module_name.split('::')
|
63
|
-
end
|
64
|
-
|
65
35
|
memoize def version_constant
|
66
36
|
"#{module_name}::VERSION"
|
67
37
|
end
|
@@ -142,8 +112,6 @@ module GemGenerator
|
|
142
112
|
config_file
|
143
113
|
end
|
144
114
|
end
|
145
|
-
|
146
|
-
private_constant :RenderVariables
|
147
115
|
end
|
148
116
|
end
|
149
117
|
end
|
@@ -4,73 +4,19 @@ require_relative 'process_files/render_variables'
|
|
4
4
|
|
5
5
|
module GemGenerator
|
6
6
|
## Main CLI command for Gem Generator
|
7
|
-
class Command <
|
7
|
+
class Command < ProjectGenerator::Command
|
8
8
|
## Private instance methods for processing template files (copying, renaming, rendering)
|
9
9
|
module ProcessFiles
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
begin
|
16
|
-
@render_variables = RenderVariables.new name, namespace, indentation, @summary
|
17
|
-
|
18
|
-
rename_files
|
19
|
-
|
20
|
-
render_files
|
21
|
-
rescue SystemExit => e
|
22
|
-
FileUtils.rm_r @directory
|
23
|
-
raise e
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def copy_files
|
28
|
-
puts 'Copying files...'
|
29
|
-
|
30
|
-
FileUtils.cp_r template, @directory
|
31
|
-
|
32
|
-
FileUtils.rm_rf "#{@directory}/.git"
|
33
|
-
end
|
34
|
-
|
35
|
-
def rename_files
|
36
|
-
puts 'Renaming files...'
|
10
|
+
RENAME_FILES_PLACEHOLDERS = {
|
11
|
+
name: 'gem_name',
|
12
|
+
path: 'gem_path'
|
13
|
+
}.freeze
|
37
14
|
|
38
|
-
|
39
|
-
.each do |template_name, real_name|
|
40
|
-
Dir["#{@directory}/**/*#{template_name}*"].each do |file_name|
|
41
|
-
new_file_name =
|
42
|
-
@directory + file_name.delete_prefix(@directory).gsub(template_name, real_name)
|
43
|
-
|
44
|
-
FileUtils.mkdir_p File.dirname new_file_name
|
45
|
-
|
46
|
-
File.rename file_name, new_file_name
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def render_files
|
52
|
-
puts 'Rendering files...'
|
53
|
-
|
54
|
-
Dir.glob("#{@directory}/**/*.erb", File::FNM_DOTMATCH).each do |template_file|
|
55
|
-
## Read a template file content and render it
|
56
|
-
content =
|
57
|
-
ERB.new(File.read(template_file), trim_mode: '-').result(@render_variables.get_binding)
|
58
|
-
|
59
|
-
## Replace tabs with spaces if necessary
|
60
|
-
content.gsub!(/^\t+/) { |tabs| ' ' * tabs.count("\t") } if indentation == 'spaces'
|
61
|
-
|
62
|
-
## Render variables in file name
|
63
|
-
real_pathname = Pathname.new(template_file).sub_ext('')
|
64
|
-
|
65
|
-
## Rename template file
|
66
|
-
File.rename template_file, real_pathname
|
15
|
+
private
|
67
16
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
17
|
+
def initialize_render_variables
|
18
|
+
self.class::RenderVariables.new name, namespace, indentation, @summary
|
71
19
|
end
|
72
20
|
end
|
73
|
-
|
74
|
-
private_constant :ProcessFiles
|
75
21
|
end
|
76
22
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler'
|
4
|
-
require '
|
5
|
-
require 'erb'
|
6
|
-
require 'fileutils'
|
7
|
-
require 'pathname'
|
8
|
-
require 'tmpdir'
|
4
|
+
require 'project_generator'
|
9
5
|
|
10
6
|
require_relative 'command/process_files'
|
11
7
|
|
@@ -14,35 +10,16 @@ Clamp.allow_options_after_parameters = true
|
|
14
10
|
|
15
11
|
module GemGenerator
|
16
12
|
## Main CLI command for Gem Generator
|
17
|
-
class Command <
|
13
|
+
class Command < ProjectGenerator::Command
|
18
14
|
include ProcessFiles
|
19
15
|
|
20
16
|
parameter 'NAME', 'name of a new gem'
|
21
17
|
parameter 'TEMPLATE', 'template path of a new gem'
|
22
18
|
|
23
19
|
option ['-n', '--namespace'], 'NAME', 'use NAME as repository namespace'
|
24
|
-
option ['-i', '--indentation'], 'TYPE', 'type of indentation (tabs or spaces)',
|
25
|
-
default: 'tabs' do |value|
|
26
|
-
## TODO: Add something like `:variants` to Clamp
|
27
|
-
unless %w[tabs spaces].include? value
|
28
|
-
raise ArgumentError, 'Only `tabs` or `spaces` values acceptable'
|
29
|
-
end
|
30
|
-
|
31
|
-
value
|
32
|
-
end
|
33
|
-
|
34
|
-
option '--git', :flag, 'use TEMPLATE as GitHub path (clone and generate from it)',
|
35
|
-
default: false
|
36
|
-
|
37
|
-
attr_reader(
|
38
|
-
:path, :title, :modules, :version_constant, :github_path, :github_uri,
|
39
|
-
:author_name, :author_email
|
40
|
-
)
|
41
20
|
|
42
21
|
def execute
|
43
|
-
|
44
|
-
|
45
|
-
signal_usage_error 'the target directory already exists' if Dir.exist? @directory
|
22
|
+
check_target_directory
|
46
23
|
|
47
24
|
## Prevent error like '"FIXME" or "TODO" is not a description' for `bundle install`
|
48
25
|
@summary = ask_for_summary
|
@@ -53,18 +30,11 @@ module GemGenerator
|
|
53
30
|
|
54
31
|
install_dependencies
|
55
32
|
|
56
|
-
## If there is no `gem_generator` config — `render` asks `git config`
|
57
|
-
## Also do `git add .` after all renders
|
58
33
|
initialize_git
|
59
34
|
|
60
35
|
FileUtils.rm_r @git_tmp_dir if git?
|
61
36
|
|
62
|
-
|
63
|
-
|
64
|
-
puts <<~HELP
|
65
|
-
To checkout into a new directory:
|
66
|
-
cd #{name}
|
67
|
-
HELP
|
37
|
+
done
|
68
38
|
end
|
69
39
|
|
70
40
|
private
|
@@ -88,21 +58,6 @@ module GemGenerator
|
|
88
58
|
result
|
89
59
|
end
|
90
60
|
|
91
|
-
def refine_template_parameter
|
92
|
-
@git_tmp_dir = Dir.mktmpdir
|
93
|
-
`git clone -q https://github.com/#{template}.git #{@git_tmp_dir}`
|
94
|
-
self.template = File.join @git_tmp_dir, 'template'
|
95
|
-
end
|
96
|
-
|
97
|
-
def initialize_git
|
98
|
-
puts 'Initializing git...'
|
99
|
-
|
100
|
-
Dir.chdir name do
|
101
|
-
system 'git init'
|
102
|
-
system 'git add .'
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
61
|
def install_dependencies
|
107
62
|
puts 'Installing dependencies...'
|
108
63
|
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: alt_memery
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '2.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '2.0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,33 +25,33 @@ dependencies:
|
|
39
25
|
- !ruby/object:Gem::Version
|
40
26
|
version: '2.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
28
|
+
name: gorilla_patch
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '4.0'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
40
|
+
version: '4.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: project_generator
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
45
|
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 0.2.0
|
62
48
|
type: :runtime
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
52
|
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 0.2.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: pry-byebug
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -257,7 +243,7 @@ licenses:
|
|
257
243
|
- MIT
|
258
244
|
metadata:
|
259
245
|
bug_tracker_uri: https://github.com/AlexWayfer/gem_generator/issues
|
260
|
-
changelog_uri: https://github.com/AlexWayfer/gem_generator/blob/v0.3.
|
246
|
+
changelog_uri: https://github.com/AlexWayfer/gem_generator/blob/v0.3.2/CHANGELOG.md
|
261
247
|
homepage_uri: https://github.com/AlexWayfer/gem_generator
|
262
248
|
source_code_uri: https://github.com/AlexWayfer/gem_generator
|
263
249
|
post_install_message:
|