rubygems-new 0.1.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: 7f86b2d1fccb4b1de70ff4e739c303ae9c2e133c4bcab6a9500d508cb7a165c6
4
+ data.tar.gz: 6930b7a99ef0380a15198a15325ac5fa4a21972bf46d0a8332aca8ed3911332b
5
+ SHA512:
6
+ metadata.gz: b2e7f5cb7d12b8b6d6efa264971be3d51c5a11dae9a0da6d8f7f0e987657d90e672781da1c2a6aef27af67eef3484470e0bd86419b94c4050c97511a203e0846
7
+ data.tar.gz: d0310191c40f7c35758ba8152222d4e4fe487f32cca21362845b1fdc1f9fb626aa78e62b1bc975cba5fc3b9fce0b8a6aec873a1c90743893df2f9bff42fb0f6b
@@ -0,0 +1,197 @@
1
+ require "date"
2
+ require "fileutils"
3
+
4
+ class Gem::Commands::NewCommand < Gem::Command
5
+
6
+ def initialize
7
+ super("new", "Creates an empty project",
8
+ {version_control: "git",
9
+ author: `git config user.name`.chomp,
10
+ dynamic_gemspec: true,
11
+ summary: "",
12
+ extra_files: [],
13
+ readme: true})
14
+ add_option("--author=NAME", "-a NAME", "Set author's name") do |name|
15
+ options[:author] = name
16
+ end
17
+ add_option("--license=LICENSE", "-l LICENSE", "Specify the license used") do |license|
18
+ options[:license] = license
19
+ end
20
+ add_option("--summary=MESSAGE", "-s MESSAGE",
21
+ "List MESSAGE as the gemspec's summary") do |summary|
22
+ options[:summary] = summary
23
+ end
24
+ add_option("--add-file=FILENAME", "-f FILENAME",
25
+ "Add a file to be created in lib/") do |filename|
26
+ options[:extra_files] << filename
27
+ end
28
+ add_option("--min[imum]", "",
29
+ "Generate only the minimum files without version control") do
30
+ optiosn[:readme] = false
31
+ options[:version_control] = nil
32
+ options[:minimum] = true
33
+ end
34
+ add_option("--static-gemspec", "Generate a static gemspec file") do
35
+ options[:dynamic_gemspec] = false
36
+ end
37
+ add_option("--no-readme", "Prevent README.md from being generated") do
38
+ options[:readme] = false
39
+ end
40
+ add_option("--version-control EXECUTABLE", "-c EXECUTABLE",
41
+ "Set version control system used (options: git, mercurial)") do |control|
42
+ options[:version_control] = control unless options[:version_control].nil?
43
+ end
44
+ add_option("--no-version-control", "Prevent setting up version control") do
45
+ options[:version_control] = nil
46
+ end
47
+ end
48
+
49
+ def usage
50
+ "#{program_name} NAME"
51
+ end
52
+
53
+ def arguments
54
+ "NAME The name of the gem generated"
55
+ end
56
+
57
+ def defaults_str
58
+ <<-DEFAULTS
59
+ --version-control git
60
+ --author `git config user.name`
61
+ DEFAULTS
62
+ end
63
+
64
+ def execute
65
+ @project_name = options[:args][0]
66
+ if @project_name.nil?
67
+ puts "Project name not specified"
68
+ return -1
69
+ end
70
+ if File.directory?(@project_name) && !Dir["#{@project_name}/*"].empty?
71
+ puts "Directory #{@project_name} exists and is non-empty."
72
+ return -1
73
+ end
74
+ write_skeleton
75
+ write_gemspec
76
+ write_readme if options[:readme]
77
+ write_license unless options[:license].nil?
78
+ add_version_control unless options[:version_control].nil?
79
+ end
80
+
81
+ private
82
+
83
+ def write_gemspec
84
+ # write required, then optionals
85
+ # dynamic is set by option
86
+ verbose "Creating #{options[:dynamic_gemspec] ? "dynamic" : "static"} gemspec at #{@project_name}/#{@project_name}.gemspec"
87
+ gemspec_text = if options[:dynamic_gemspec]
88
+ <<-GEMSPEC
89
+ require "date"
90
+ Gem::Specification.new do |s|
91
+ # Required
92
+ s.name = "#{@project_name}"
93
+ s.version = "0.0.1"
94
+ s.summary = "#{options[:summary]}"
95
+ s.author = "#{options[:author]}"
96
+ s.files = Dir["lib/**/*"]
97
+
98
+ # Recommended
99
+ s.license = "#{options[:license]}"
100
+ s.description = ""
101
+ s.date = Date.today.strftime("%Y-%m-%d")
102
+ s.email = ""
103
+ s.homepage = ""
104
+ s.metadata = {}
105
+
106
+
107
+ # Optional and situational - delete or keep, as necessary
108
+ # s.bindir = "bin"
109
+ # s.executables = []
110
+ # s.required_ruby_version = ">= 2.5" # Sensible default
111
+ end
112
+ GEMSPEC
113
+ else
114
+ <<-GEMSPEC
115
+ Gem::Specification.new do |s|
116
+ # Required
117
+ s.name = "#{@project_name}"
118
+ s.version = "0.0.1"
119
+ s.summary = "#{options[:summary]}"
120
+ s.author = "#{options[:author]}"
121
+ s.files = [
122
+ "lib/#{@project_name}.rb",
123
+ #{options[extra_files].map{|f| "\"lib/#{f}\""}.join(", \n")}
124
+ ]
125
+
126
+ # Recommended
127
+ s.license = "#{options[:license]}"
128
+ s.description = "" #TODO
129
+ s.date = #{Date.today.strftime("%Y-%m-%d")}
130
+ s.email = ""
131
+ s.homepage = ""
132
+ s.metadata = {}
133
+
134
+
135
+ # Optional and situational - delete or keep, as necessary
136
+ # s.bindir = "bin"
137
+ # s.executables = []
138
+ # s.required_ruby_version = ">= 2.5" # Sensible default
139
+ end
140
+ GEMSPEC
141
+ end
142
+ File.open("#{@project_name}/#{@project_name}.gemspec", "w") do |file|
143
+ file.write gemspec_text
144
+ end
145
+ end
146
+
147
+ def write_readme
148
+ # write project name and summary
149
+ verbose "Creating #{@project_name}/README.md"
150
+ File.open("#{@project_name}/README.md", "w") do |readme|
151
+ readme.write "# #{@project_name}\n#{options[:summary]}"
152
+ end
153
+ end
154
+
155
+ def write_license
156
+ # does nothing at present. Figure this out later
157
+ # will be specified by option
158
+ end
159
+
160
+ def write_skeleton
161
+ # generate lib/<name>.rb and lib/<name> dir
162
+ # Can generate other files if directed by options
163
+ verbose "Creating directory #{@project_name}"
164
+ Dir.mkdir(@project_name)
165
+ Dir.chdir(@project_name) do
166
+ verbose "Creating directory #{@project_name}/lib"
167
+ Dir.mkdir("lib")
168
+ Dir.chdir("lib") do
169
+ verbose "Creating directory #{@project_name}/lib/#{@project_name}"
170
+ Dir.mkdir(@project_name)
171
+ files = [@project_name + ".rb"]
172
+ files += options[:extra_files] unless options[:minimum]
173
+ files.each do |file|
174
+ verbose "Creating file #{@project_name}/lib/#{file}"
175
+ directory = file.split("/")[...-1].join("/")
176
+ FileUtils.mkdir_p(directory) unless directory.empty?
177
+ FileUtils.touch(file)
178
+ end
179
+ end
180
+ end
181
+ end
182
+
183
+ def add_version_control
184
+ # set up git unless other option listed
185
+ verbose "Initializing version control with #{options[:version_control]}"
186
+ case options[:version_control]
187
+ when "git"
188
+ `git init`
189
+ when "mercurial"
190
+ `hg init`
191
+ end
192
+ end
193
+
194
+ def verbose(message)
195
+ puts message if Gem.configuration.verbose == 1
196
+ end
197
+ end
@@ -0,0 +1,3 @@
1
+ require "rubygems/command_manager"
2
+
3
+ Gem::CommandManager.instance.register_command(:new)
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-new
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kellen Watt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Rubygems plugin that generates new, empty, Rubygems projects, including
14
+ a README, version control (e.g. git), and basic project structure.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/rubygems/commands/new_command.rb
21
+ - lib/rubygems_plugin.rb
22
+ homepage: https://github.com/KellenWatt/rubygems-new
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.1.4
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Rubygems plugin to generate new rubygems projects.
45
+ test_files: []