gitplate 0.0.1 → 0.0.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.
- data/CHANGELOG.md +9 -0
- data/README.md +31 -0
- data/bin/gitplate +14 -0
- data/lib/gitplate/gitplate.rb +144 -24
- data/lib/gitplate/plate.rb +58 -6
- metadata +22 -6
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
v0.0.2
|
2
|
+
======
|
3
|
+
* Captures the plate repository url/sha in .gitplate/config.yml
|
4
|
+
* Define tasks in plate file that can be called from the gitplate command line
|
5
|
+
* gitplate init to setup an existing repository with gitplate
|
6
|
+
|
7
|
+
v0.0.1
|
8
|
+
======
|
9
|
+
* install a new project from a git repository
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Gitplate is a templating solution using git repositories.
|
2
|
+
|
3
|
+
Do you often create new projects and have a common repository structure you like to use, with a set of basic build
|
4
|
+
scripts? Gitplate aims to make it quick and simple to get a new project up and running. Point gitplate at any git
|
5
|
+
repository to have a new project created in its image. Gitplate will also run a 'plate' file on the new
|
6
|
+
repository. This plate file can contain tasks to rename files as well as any extra actions you require.
|
7
|
+
|
8
|
+
#### Installation:
|
9
|
+
gem install gitplate
|
10
|
+
|
11
|
+
|
12
|
+
#### Example
|
13
|
+
Initialize an existing git repository for gitplate. Creates a .gitplate directory with a sample plate file
|
14
|
+
|
15
|
+
gitplate init
|
16
|
+
|
17
|
+
Install an existing repository to setup a new project
|
18
|
+
|
19
|
+
gitplate install myproject git://github.com/lukesmith/RepositoryTemplate
|
20
|
+
|
21
|
+
|
22
|
+
#### Example plate file:
|
23
|
+
init do
|
24
|
+
rename 'SampleSolution.sln', "#{project_name}.sln"
|
25
|
+
rename 'SampleSolution.build.bat', "#{project_name}.build.bat"
|
26
|
+
rename 'SampleSolution.package.bat', "#{project_name}.package.bat"
|
27
|
+
end
|
28
|
+
|
29
|
+
task :dosomething do
|
30
|
+
# call via 'gitplate task dosomething'
|
31
|
+
end
|
data/bin/gitplate
CHANGED
@@ -42,6 +42,20 @@ command :install do |c|
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
desc 'Initialize the current directory as a gitplate repository'
|
46
|
+
command :init do |c|
|
47
|
+
c.action do |g, options, args|
|
48
|
+
Gitplate.init
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Run task'
|
53
|
+
command :task do |c|
|
54
|
+
c.action do |g, options, args|
|
55
|
+
Gitplate.task args[0], args[1..-1]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
pre do |global,command,options,args|
|
46
60
|
if (global[:v])
|
47
61
|
puts Gitplate::VERSION
|
data/lib/gitplate/gitplate.rb
CHANGED
@@ -1,43 +1,139 @@
|
|
1
1
|
require 'Git'
|
2
|
+
require 'zip/zip'
|
2
3
|
|
3
4
|
module Gitplate
|
4
5
|
|
5
|
-
VERSION = "0.0.
|
6
|
+
VERSION = "0.0.2"
|
6
7
|
|
7
|
-
def self.
|
8
|
-
|
8
|
+
def self.config_file
|
9
|
+
'.gitplate/config.yml'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.plate_file
|
13
|
+
'.gitplate/plate'
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.init
|
17
|
+
init_directory_for_gitplate
|
18
|
+
|
19
|
+
if (!File.exists?(plate_file))
|
20
|
+
debug_msg "Creating sample plate file"
|
21
|
+
|
22
|
+
# create the sample plate file
|
23
|
+
File.open(plate_file, "w") { |f|
|
24
|
+
f.write("init do\n")
|
25
|
+
f.write(" # add code to run when installing a new project\n")
|
26
|
+
f.write("end\n")
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_plate_repository(project_name, repository)
|
32
|
+
source_repository_sha = ""
|
33
|
+
|
34
|
+
Dir.chdir project_name do
|
35
|
+
# create a gitplate directory structure for checking out the repository to
|
36
|
+
out_path = File.expand_path(File.join('.gitplate', 'tmp', 'checkout'))
|
37
|
+
FileUtils.mkdir_p out_path
|
38
|
+
|
39
|
+
archive_file = File.expand_path(File.join('.gitplate', 'tmp', "#{project_name}.zip"))
|
40
|
+
|
41
|
+
Dir.chdir out_path do
|
42
|
+
source_repository = Git.clone(repository, project_name)
|
43
|
+
source_repository_sha = source_repository.object('HEAD').sha
|
44
|
+
|
45
|
+
source_repository.archive(source_repository_sha, archive_file, :format => "zip")
|
46
|
+
end
|
47
|
+
|
48
|
+
unzip_file archive_file, Dir.pwd
|
49
|
+
|
50
|
+
# get rid of the temporary directory
|
51
|
+
clear_directory File.expand_path(File.join('.gitplate', 'tmp'))
|
52
|
+
end
|
53
|
+
|
54
|
+
source_repository_sha
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.install(project_name, repository)
|
58
|
+
if (File.directory? project_name)
|
9
59
|
fatal_msg_and_fail "Directory already exists"
|
10
60
|
end
|
11
61
|
|
12
|
-
|
62
|
+
info_msg "creating #{project_name} based on #{repository}"
|
13
63
|
|
14
|
-
|
15
|
-
FileUtils.mkdir_p out_path
|
64
|
+
FileUtils.mkdir_p project_name
|
16
65
|
|
17
|
-
|
66
|
+
source_repository_sha = get_plate_repository(project_name, repository)
|
67
|
+
|
68
|
+
# we've got the repository cloned and cleaned up of existing git history
|
69
|
+
Dir.chdir project_name do
|
70
|
+
# Ensure the directory has been initialized with gitplate
|
71
|
+
init_directory_for_gitplate
|
72
|
+
|
73
|
+
update_config_with({
|
74
|
+
:project => { :name => project_name },
|
75
|
+
:repository => { :url => repository, :sha => source_repository_sha },
|
76
|
+
:gitplate_version => Gitplate::VERSION
|
77
|
+
})
|
18
78
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
79
|
+
# pull in the plate file from the cloned repository
|
80
|
+
if (File.exists?(plate_file))
|
81
|
+
Gitplate::Plate.instance.run(
|
82
|
+
plate_file,
|
83
|
+
{
|
84
|
+
:project_name => project_name,
|
85
|
+
:project_dir => Dir.pwd
|
86
|
+
})
|
87
|
+
else
|
88
|
+
debug_msg "no plate file found in repository"
|
89
|
+
end
|
23
90
|
|
24
|
-
|
25
|
-
|
91
|
+
g = Git.init
|
92
|
+
g.add
|
93
|
+
g.commit "Initial commit"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.task(task, args)
|
98
|
+
config = load_gitplate_file
|
99
|
+
|
100
|
+
Gitplate::Plate.instance.run_task(
|
101
|
+
plate_file,
|
102
|
+
task,
|
103
|
+
{
|
104
|
+
:project_name => config["project"]["name"],
|
105
|
+
:project_dir => Dir.pwd
|
106
|
+
})
|
107
|
+
end
|
26
108
|
|
27
|
-
|
28
|
-
|
109
|
+
def self.init_directory_for_gitplate()
|
110
|
+
if (!File.directory? name)
|
111
|
+
FileUtils.mkdir_p '.gitplate'
|
29
112
|
end
|
30
113
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
114
|
+
if (!File.exists?(config_file))
|
115
|
+
debug_msg "Creating config file"
|
116
|
+
File.open(config_file, 'w') { |f| YAML.dump({}, f) }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.load_gitplate_file
|
121
|
+
YAML.load(File.open(config_file))
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.update_config_with(values)
|
125
|
+
config = load_gitplate_file
|
126
|
+
|
127
|
+
formatted = format_hash_for_yaml values
|
128
|
+
formatted.each do |name, value|
|
129
|
+
config[name.to_s] = value
|
40
130
|
end
|
131
|
+
|
132
|
+
File.open(config_file, 'w') { |f| YAML.dump(config, f) }
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.info_msg(msg)
|
136
|
+
puts msg.color(:green).bright
|
41
137
|
end
|
42
138
|
|
43
139
|
def self.debug_msg(msg)
|
@@ -59,5 +155,29 @@ module Gitplate
|
|
59
155
|
FileUtils.rm_rf full_path
|
60
156
|
end
|
61
157
|
end
|
158
|
+
|
159
|
+
def self.format_hash_for_yaml(hash)
|
160
|
+
result = Hash.new
|
161
|
+
|
162
|
+
hash.each do |name, value|
|
163
|
+
if (value.kind_of? Hash)
|
164
|
+
result[name.to_s] = format_hash_for_yaml value
|
165
|
+
else
|
166
|
+
result[name.to_s] = value
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
result
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.unzip_file(file, destination)
|
174
|
+
Zip::ZipFile.open(file) { |zip_file|
|
175
|
+
zip_file.each { |f|
|
176
|
+
f_path=File.join(destination, f.name)
|
177
|
+
FileUtils.mkdir_p(File.dirname(f_path))
|
178
|
+
zip_file.extract(f, f_path) unless File.exist?(f_path)
|
179
|
+
}
|
180
|
+
}
|
181
|
+
end
|
62
182
|
|
63
183
|
end
|
data/lib/gitplate/plate.rb
CHANGED
@@ -3,13 +3,23 @@ module Gitplate
|
|
3
3
|
|
4
4
|
class Plate
|
5
5
|
include Singleton
|
6
|
-
|
6
|
+
|
7
7
|
def initialize
|
8
|
-
@
|
8
|
+
@tasks = Hash.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_init(&block)
|
12
|
+
if (@init != nil)
|
13
|
+
Gitplate.fatal_msg_and_fail "Init can only be defined once"
|
14
|
+
end
|
15
|
+
|
16
|
+
Gitplate.debug_msg " found init"
|
17
|
+
@init = block
|
9
18
|
end
|
10
19
|
|
11
|
-
def
|
12
|
-
|
20
|
+
def add_task(task_name, &block)
|
21
|
+
Gitplate.debug_msg " found task '#{task_name}'"
|
22
|
+
@tasks[task_name.to_s] = block
|
13
23
|
end
|
14
24
|
|
15
25
|
def output(type, msg)
|
@@ -30,13 +40,43 @@ module Gitplate
|
|
30
40
|
@project_name
|
31
41
|
end
|
32
42
|
|
43
|
+
def project_dir
|
44
|
+
@project_dir
|
45
|
+
end
|
46
|
+
|
33
47
|
def run(file, args)
|
48
|
+
load_plate file, args
|
49
|
+
|
50
|
+
if (@init != nil)
|
51
|
+
Gitplate.debug_msg "running plate - start"
|
52
|
+
@init.call
|
53
|
+
Gitplate.debug_msg "running plate - completed"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def run_task(file, task_name, args)
|
58
|
+
load_plate file, args
|
59
|
+
|
60
|
+
task = @tasks[task_name]
|
61
|
+
|
62
|
+
if (task == nil)
|
63
|
+
Gitplate.fatal_msg_and_fail "Unable to find custom task '#{task_name}'"
|
64
|
+
end
|
65
|
+
|
66
|
+
Gitplate.debug_msg "running task '#{task_name}' - start"
|
67
|
+
task.call
|
68
|
+
Gitplate.debug_msg "running task '#{task_name}' - completed"
|
69
|
+
end
|
70
|
+
|
71
|
+
def load_plate(file, args)
|
34
72
|
@project_name = args[:project_name]
|
35
73
|
@project_dir = args[:project_dir]
|
74
|
+
|
75
|
+
#file = "/Users/lukesmith/Projects/gitplate/tmp/plate"
|
36
76
|
|
37
|
-
Gitplate.debug_msg "
|
77
|
+
Gitplate.debug_msg "loading plate from '#{file}'"
|
38
78
|
load file
|
39
|
-
Gitplate.debug_msg "
|
79
|
+
Gitplate.debug_msg "loaded plate"
|
40
80
|
end
|
41
81
|
|
42
82
|
def to_class_name(type)
|
@@ -64,10 +104,18 @@ module Gitplate
|
|
64
104
|
|
65
105
|
end
|
66
106
|
|
107
|
+
def init(&block)
|
108
|
+
Gitplate::Plate.instance.add_init &block
|
109
|
+
end
|
110
|
+
|
67
111
|
def project_name
|
68
112
|
Gitplate::Plate.instance.project_name
|
69
113
|
end
|
70
114
|
|
115
|
+
def project_dir
|
116
|
+
Gitplate::Plate.instance.project_dir
|
117
|
+
end
|
118
|
+
|
71
119
|
def output(type, msg)
|
72
120
|
Gitplate::Plate.instance.output type, " #{msg}"
|
73
121
|
end
|
@@ -78,4 +126,8 @@ end
|
|
78
126
|
|
79
127
|
def rename(from, to)
|
80
128
|
Gitplate::Plate.instance.rename from, to
|
129
|
+
end
|
130
|
+
|
131
|
+
def task(task_name, &block)
|
132
|
+
Gitplate::Plate.instance.add_task task_name, &block
|
81
133
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luke Smith
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
type: :runtime
|
47
47
|
version_requirements: *id002
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: rubyzip
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -57,10 +57,10 @@ dependencies:
|
|
57
57
|
segments:
|
58
58
|
- 0
|
59
59
|
version: "0"
|
60
|
-
type: :
|
60
|
+
type: :runtime
|
61
61
|
version_requirements: *id003
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: rake
|
64
64
|
prerelease: false
|
65
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
66
66
|
none: false
|
@@ -73,6 +73,20 @@ dependencies:
|
|
73
73
|
version: "0"
|
74
74
|
type: :development
|
75
75
|
version_requirements: *id004
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: rdoc
|
78
|
+
prerelease: false
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
type: :development
|
89
|
+
version_requirements: *id005
|
76
90
|
description: Project templates from a git repository
|
77
91
|
email:
|
78
92
|
- stuff@lukesmith.net
|
@@ -87,6 +101,8 @@ files:
|
|
87
101
|
- lib/gitplate/plate.rb
|
88
102
|
- bin/gitplate
|
89
103
|
- LICENSE
|
104
|
+
- CHANGELOG.md
|
105
|
+
- README.md
|
90
106
|
homepage: http://www.gitplate.com/
|
91
107
|
licenses: []
|
92
108
|
|