Class: MapTool::Tag
- Defined in:
- lib/maptool/tag/tag.rb
Overview
Usage
Constant Summary collapse
- TAG_FILE =
".tagfile"
Constants inherited from Command
Instance Attribute Summary collapse
-
#name ⇒ Object
名称.
-
#stage ⇒ Object
阶段.
-
#suffix ⇒ Object
后缀.
-
#version ⇒ Object
版本号.
Class Method Summary collapse
Instance Method Summary collapse
- #commit_file ⇒ Object
- #commit_tag ⇒ Object
-
#initialize(argv) ⇒ Tag
constructor
初始化.
- #read_file ⇒ Object
- #run ⇒ Object
-
#validate! ⇒ Object
businrss.
- #write_file ⇒ Object
Constructor Details
#initialize(argv) ⇒ Tag
初始化
39 40 41 42 43 44 |
# File 'lib/maptool/tag/tag.rb', line 39 def initialize(argv) super self.version = argv.option('version') self.stage = argv.option('stage') self.suffix = argv.option('suffix') end |
Instance Attribute Details
#name ⇒ Object
名称
33 34 35 |
# File 'lib/maptool/tag/tag.rb', line 33 def name @name end |
#stage ⇒ Object
阶段
35 36 37 |
# File 'lib/maptool/tag/tag.rb', line 35 def stage @stage end |
#suffix ⇒ Object
后缀
36 37 38 |
# File 'lib/maptool/tag/tag.rb', line 36 def suffix @suffix end |
#version ⇒ Object
版本号
34 35 36 |
# File 'lib/maptool/tag/tag.rb', line 34 def version @version end |
Class Method Details
.options ⇒ Object
25 26 27 28 29 |
# File 'lib/maptool/tag/tag.rb', line 25 def self. [['--version', '版本号:x.xx.xxx,默认 1.00.000'], ['--stage', '用于区分是否正式: 开发阶段/提测后 (dev/release),默认 release'], ['--suffix', '可扩展的后缀']] + super end |
Instance Method Details
#commit_file ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/maptool/tag/tag.rb', line 81 def commit_file puts "update #{TAG_FILE}".green localChanges = !(`git stash` =~ /No local changes to save/) self.write_file `git add .` `git commit -m "update #{TAG_FILE}"` `git push` `git stash pop` if localChanges end |
#commit_tag ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/maptool/tag/tag.rb', line 100 def commit_tag tag = "#{self.name}-#{self.version}-" tag << "#{self.stage}-" if self.stage && self.stage.size > 0 tag << Time.now.strftime("%Y%m%d%H%M") tag << "-#{self.suffix}" if self.suffix && self.suffix.size > 0 puts "build tag #{tag}".green system("yjcocoa git tag --add=#{tag}") end |
#read_file ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/maptool/tag/tag.rb', line 73 def read_file hash = JSON.parse(File.read(TAG_FILE)) self.name = hash["name"] self.version = hash["version"] unless self.version self.stage = hash["stage"] unless self.stage self.suffix = hash["suffix"] unless self.suffix end |
#run ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/maptool/tag/tag.rb', line 59 def run if File.exist?(TAG_FILE) # 文件存在 save = self.version || self.stage || self.suffix self.read_file self.commit_file if save else self.name = File.basename(Dir.pwd) self.version = "1.00.000" unless self.version self.stage = "release" unless self.stage self.commit_file end self.commit_tag end |
#validate! ⇒ Object
businrss
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/maptool/tag/tag.rb', line 47 def validate! super unless File.exist?('.git') puts "需在项目根目录执行".red self. end if self.version && self.version.size < 8 #x.xx.xxx puts "版本号 #{self.version} 不符合规范 x.xx.xxx".red self. end end |
#write_file ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/maptool/tag/tag.rb', line 91 def write_file params = {} params["name"] = self.name params["version"] = self.version params["stage"] = self.stage params["suffix"] = self.suffix File.write(TAG_FILE, JSON.pretty_generate(params)) end |