bundle gem mytest
Creating gem 'mytest'...
MIT License enabled in config
Code of conduct enabled in config
create mytest/Gemfile
create mytest/lib/mytest.rb
create mytest/lib/mytest/version.rb
create mytest/mytest.gemspec
create mytest/Rakefile
create mytest/README.md
create mytest/bin/console
create mytest/bin/setup
create mytest/.gitignore
create mytest/LICENSE.txt
create mytest/CODE_OF_CONDUCT.md
Initializing git repo in /Users/steve/Desktop/mytest
複製代碼
mytest.gemspec
(1)origin:git
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "mytest/version"
Gem::Specification.new do |spec|
spec.name = "mytest"
spec.version = Mytest::VERSION
spec.authors = ["steve"]
spec.email = ["chengquan.wang@ele.me"]
spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
end
複製代碼
其中包含 TODO
|| FIXME
標記的必須改成你我的的工程信息 (2)modified:github
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "mytest/version"
Gem::Specification.new do |spec|
spec.name = "mytest"
spec.version = Mytest::VERSION
spec.authors = ["CNKCQ"]
spec.email = ["chengquan.personal@gmail.com"]
spec.summary = %q{happy setting}
spec.description = %q{effective command for boot setting}
spec.homepage = "https://github.com/CNKCQ/mytest.git"
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "https://rubygems.org"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
# Mac os bindir = "bin" Windows bindir = "exe"
spec.bindir = "bin"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_runtime_dependency "colorize"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "colorize"
spec.add_development_dependency "rspec", "~> 3.2"
end
複製代碼
其中在不一樣的系統中執行文件的目錄(bindir
)是不一樣的,我用的 macOS
, 因此使用 bin
目錄web
VERSION
) 編輯 mytest/lib/mytest/version.rb
能夠更改版本號module MyGem
VERSION = '0.0.1'
end
複製代碼
mytest/lib/mytest/mytest.rb
, 能夠在裏面添加執行代碼require "mytest/version"
module Mytest
# Your code goes here...
put 'hello my first gem'
end
複製代碼
Gemfile
編輯 mytest/Gemfile
, 能夠在這裏進行依賴管理source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in mytest.gemspec
gemspec
複製代碼
$ bundle install
複製代碼
RubyGems
帳戶RubyGems
帳戶RubyGems
帳戶的訪問令牌$ curl -u your-rubygems-username https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
複製代碼
若是 「獲取 RubyGems
帳戶」 沒有作,下面發佈的過程當中會報錯:shell
$ rake release
mytest 0.0.1 built to pkg/mytest-0.0.1.gem.
Tag v0.0.1 has been created.
rake aborted!
Your rubygems.org credentials aren't set. Run `gem push` to set them.
Tasks: TOP => release
(See full trace by running task with --trace)
複製代碼
rake build
複製代碼
build
結束後提交到 git
倉庫後執行:api
rake release
複製代碼
發佈成功, 恭喜你生成了一個本身的 gem
ruby