submodule 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/lib/submodule.rb +158 -0
- data/lib/submodule/version.rb +3 -0
- data/submodule.gemspec +21 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# submodule
|
2
|
+
|
3
|
+
Small gem to simplify building process of gems with git submodules. Tended to be used for ruby gems which wrap js libraries or another assets
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Install gem or add it to `Gemfile` then put in your `Rakefile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'submodule'
|
11
|
+
class SomeSubmodule < Submodule::Task
|
12
|
+
def test
|
13
|
+
# run tests of submodule
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_pull
|
17
|
+
# do something
|
18
|
+
end
|
19
|
+
end
|
20
|
+
SomeSubmodule.new
|
21
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/submodule.rb
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require "submodule/version"
|
2
|
+
|
3
|
+
require "rake/tasklib"
|
4
|
+
require "inifile"
|
5
|
+
|
6
|
+
module Submodule
|
7
|
+
class Task < ::Rake::TaskLib
|
8
|
+
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@cwd = Dir.pwd
|
13
|
+
|
14
|
+
base = File.basename Dir["*.gemspec"][0], ".gemspec"
|
15
|
+
if base[0]
|
16
|
+
base = File.basename Dir["*.gemspec"][0], ".gemspec"
|
17
|
+
@version_file = "lib/#{base}/version.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
gitmodules = IniFile.new('./.gitmodules').to_h
|
21
|
+
@path = gitmodules[gitmodules.keys.first]["path"]
|
22
|
+
@submodule_name = gitmodules.keys.first
|
23
|
+
.gsub('submodule ', '')
|
24
|
+
.gsub('"', '')
|
25
|
+
.gsub('vendor/', '')
|
26
|
+
@github = gitmodules[gitmodules.keys.first]["url"]
|
27
|
+
.gsub('https://github.com/', '')
|
28
|
+
.gsub('.git', '')
|
29
|
+
define
|
30
|
+
end
|
31
|
+
|
32
|
+
def test
|
33
|
+
p "define tests in test function"
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_pull
|
37
|
+
p "after pull"
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def define
|
43
|
+
desc "Update, test and commit submodule #{@submodule_name}"
|
44
|
+
task "submodule:update" do
|
45
|
+
git_update
|
46
|
+
cd path
|
47
|
+
hash_before = git_hash
|
48
|
+
git_pull
|
49
|
+
hash_after = git_hash
|
50
|
+
if hash_before == hash_after
|
51
|
+
abort "submodule #{@submodule_name} already up-to-date"
|
52
|
+
end
|
53
|
+
test
|
54
|
+
update_version hash_after
|
55
|
+
cd @cwd
|
56
|
+
git_add
|
57
|
+
after_pull
|
58
|
+
git_commit hash_after
|
59
|
+
end
|
60
|
+
desc "Test submodule #{@submodule_name}"
|
61
|
+
task "submodule:test" do
|
62
|
+
git_update
|
63
|
+
cd path
|
64
|
+
test
|
65
|
+
cd @cwd
|
66
|
+
end
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def git_update
|
71
|
+
sh "git submodule update --init --recursive"
|
72
|
+
end
|
73
|
+
|
74
|
+
# def my_sh cmd
|
75
|
+
# puts cmd
|
76
|
+
# res = `#{cmd}`
|
77
|
+
# if $? != 0
|
78
|
+
# abort "Running `#{cmd}' failed. Run this command directly for more detailed output"
|
79
|
+
# end
|
80
|
+
# res
|
81
|
+
# end
|
82
|
+
|
83
|
+
def git_pull
|
84
|
+
sh "git clean -f"
|
85
|
+
sh "git checkout master"
|
86
|
+
sh "git pull"
|
87
|
+
# res = my_sh "git pull"
|
88
|
+
# if res =~ /Already up-to-date/
|
89
|
+
# p res
|
90
|
+
# abort "submodule #{@submodule_name} already up-to-date"
|
91
|
+
# end
|
92
|
+
end
|
93
|
+
|
94
|
+
def git_hash
|
95
|
+
`git rev-parse --verify HEAD`.strip
|
96
|
+
# http://git-scm.com/book/en/ch2-3.html Table 2-1
|
97
|
+
# {
|
98
|
+
# hash: `git rev-parse --verify HEAD`.strip,
|
99
|
+
# short_hash: ` git log -1 --pretty=format:"%h"`,
|
100
|
+
# commit_date: ` git log -1 --pretty=format:"%cd"`,
|
101
|
+
# comment: ` git log -1 --pretty=format:"%s"`
|
102
|
+
# }
|
103
|
+
end
|
104
|
+
|
105
|
+
def git_add
|
106
|
+
sh "git add " + path
|
107
|
+
sh "git add " + @version_file
|
108
|
+
end
|
109
|
+
|
110
|
+
def version_path
|
111
|
+
File.expand_path(@version_file, @cwd)
|
112
|
+
end
|
113
|
+
|
114
|
+
def version_regexp val = "(.*)", re = true
|
115
|
+
str = "VERSION = \"#{val}\""
|
116
|
+
if re
|
117
|
+
Regexp.new str.gsub(" ", "\s*")
|
118
|
+
else
|
119
|
+
str
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def submodule_regexp val = "(.*)", re = true
|
124
|
+
str = "SUBMODULE = \"#{val}\""
|
125
|
+
if re
|
126
|
+
Regexp.new str.gsub(" ", "\s*")
|
127
|
+
else
|
128
|
+
str
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def update_version hash
|
133
|
+
if File.file? version_path
|
134
|
+
version_info = File.read version_path
|
135
|
+
version_number = version_regexp.match(version_info)[1]
|
136
|
+
version_number = version_number.split('.')
|
137
|
+
# TODO not update if current version not commited yet
|
138
|
+
version_number[2] = version_number[2].to_i + 1
|
139
|
+
version_number = version_number.join('.')
|
140
|
+
|
141
|
+
version_info.gsub! version_regexp, version_regexp(version_number, false)
|
142
|
+
version_info.gsub! submodule_regexp, submodule_regexp(hash, false)
|
143
|
+
|
144
|
+
File.open version_path, "w" do |f|
|
145
|
+
f.write version_info
|
146
|
+
end
|
147
|
+
else
|
148
|
+
p "no version file"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def git_commit hash
|
153
|
+
message = "update #{@submodule_name} to #{@github}@#{hash}"
|
154
|
+
sh "git commit -m \"#{message}\""
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
data/submodule.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "submodule/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "submodule"
|
7
|
+
s.version = Submodule::VERSION
|
8
|
+
s.authors = ["stereobooster"]
|
9
|
+
s.email = ["stereobooster@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Small gem to simplify building process of gems with git submodules}
|
12
|
+
s.description = %q{Small gem to simplify building process of gems with git submodules. Tended to be used for ruby gems which wrap js libraries or another assets}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency "rake"
|
20
|
+
s.add_dependency "inifile"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: submodule
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- stereobooster
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-05-07 00:00:00 +03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: inifile
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: Small gem to simplify building process of gems with git submodules. Tended to be used for ruby gems which wrap js libraries or another assets
|
47
|
+
email:
|
48
|
+
- stereobooster@gmail.com
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
extra_rdoc_files: []
|
54
|
+
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- lib/submodule.rb
|
61
|
+
- lib/submodule/version.rb
|
62
|
+
- submodule.gemspec
|
63
|
+
has_rdoc: true
|
64
|
+
homepage: ""
|
65
|
+
licenses: []
|
66
|
+
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.3.7
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: Small gem to simplify building process of gems with git submodules
|
95
|
+
test_files: []
|
96
|
+
|