gitplate 0.0.1
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/LICENSE +20 -0
- data/bin/gitplate +70 -0
- data/lib/gitplate/gitplate.rb +63 -0
- data/lib/gitplate/plate.rb +81 -0
- metadata +128 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Luke Smith
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/gitplate
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
|
3
|
+
# have this method, so we add it so we get resolved symlinks
|
4
|
+
# and compatibility
|
5
|
+
unless File.respond_to? :realpath
|
6
|
+
class File #:nodoc:
|
7
|
+
def self.realpath path
|
8
|
+
return realpath(File.readlink(path)) if symlink?(path)
|
9
|
+
path
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'rainbow'
|
18
|
+
require 'gli'
|
19
|
+
require 'gli_version'
|
20
|
+
require 'gitplate/gitplate'
|
21
|
+
require 'gitplate/plate'
|
22
|
+
|
23
|
+
include GLI
|
24
|
+
|
25
|
+
program_desc 'Generates a directory structure from a git repository'
|
26
|
+
|
27
|
+
version Gitplate::VERSION
|
28
|
+
|
29
|
+
desc 'Install the gitplate'
|
30
|
+
long_desc <<EOS
|
31
|
+
This will create a new git repository based on a copy of the repository specified. If a plate file exists in the
|
32
|
+
repository then this will be ran against the new project
|
33
|
+
EOS
|
34
|
+
arg_name 'project_name plate_repository'
|
35
|
+
command :install do |c|
|
36
|
+
c.action do |g, options, args|
|
37
|
+
if args.length < 2
|
38
|
+
raise 'You must specify the name of the new project and the url of the git repository'
|
39
|
+
end
|
40
|
+
|
41
|
+
Gitplate.install args[0], args[1]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
pre do |global,command,options,args|
|
46
|
+
if (global[:v])
|
47
|
+
puts Gitplate::VERSION
|
48
|
+
false
|
49
|
+
end
|
50
|
+
# Pre logic here
|
51
|
+
# Return true to proceed; false to abort and not call the
|
52
|
+
# chosen command
|
53
|
+
# Use skips_pre before a command to skip this block
|
54
|
+
# on that command only
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
post do |global,command,options,args|
|
59
|
+
# Post logic here
|
60
|
+
# Use skips_post before a command to skip this
|
61
|
+
# block on that command only
|
62
|
+
end
|
63
|
+
|
64
|
+
on_error do |exception|
|
65
|
+
# Error logic here
|
66
|
+
# return false to skip default error handling
|
67
|
+
true
|
68
|
+
end
|
69
|
+
|
70
|
+
exit GLI.run(ARGV)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'Git'
|
2
|
+
|
3
|
+
module Gitplate
|
4
|
+
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
|
7
|
+
def self.install(name, repository)
|
8
|
+
if (File.directory? name)
|
9
|
+
fatal_msg_and_fail "Directory already exists"
|
10
|
+
end
|
11
|
+
|
12
|
+
puts "creating #{name} based on #{repository}"
|
13
|
+
|
14
|
+
out_path = File.expand_path(File.join(name, 'tmp', 'checkout'))
|
15
|
+
FileUtils.mkdir_p out_path
|
16
|
+
|
17
|
+
Git.clone(repository, name, :path => out_path)
|
18
|
+
|
19
|
+
# move the repository files to the main directory
|
20
|
+
files = Dir.glob("#{out_path}/#{name}/*") - [name]
|
21
|
+
FileUtils.mkdir name unless File.directory? name
|
22
|
+
FileUtils.cp_r files, name
|
23
|
+
|
24
|
+
# get rid of the temporary checkout directory
|
25
|
+
clear_directory File.expand_path(File.join(name, 'tmp'))
|
26
|
+
|
27
|
+
Dir.chdir name do
|
28
|
+
Git.init
|
29
|
+
end
|
30
|
+
|
31
|
+
# pull in the plate file from the cloned repository
|
32
|
+
plate = File.expand_path(File.join(name, 'plate'))
|
33
|
+
if (File.exists?(plate))
|
34
|
+
Gitplate::Plate.instance.run(
|
35
|
+
plate,
|
36
|
+
:project_name => name,
|
37
|
+
:project_dir => File.expand_path(name))
|
38
|
+
else
|
39
|
+
debug_msg "no plate file found in repository"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.debug_msg(msg)
|
44
|
+
puts msg.color(:cyan).bright
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.fatal_msg(msg)
|
48
|
+
puts msg.color(:red).bright
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.fatal_msg_and_fail(msg)
|
52
|
+
fatal_msg msg
|
53
|
+
raise msg
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.clear_directory(dir)
|
57
|
+
if (File.directory?(dir))
|
58
|
+
full_path = File.expand_path(dir)
|
59
|
+
FileUtils.rm_rf full_path
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Gitplate
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
class Plate
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@actions = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.actions
|
12
|
+
@actions
|
13
|
+
end
|
14
|
+
|
15
|
+
def output(type, msg)
|
16
|
+
instance = Gitplate::Outputs.const_get(to_class_name(type)).new
|
17
|
+
instance.execute msg
|
18
|
+
end
|
19
|
+
|
20
|
+
def custom(&block)
|
21
|
+
block.call
|
22
|
+
end
|
23
|
+
|
24
|
+
def rename(from = nil, to = nil)
|
25
|
+
Gitplate.debug_msg " renaming #{from} to #{to}"
|
26
|
+
File.rename(expand_path(from), expand_path(to))
|
27
|
+
end
|
28
|
+
|
29
|
+
def project_name
|
30
|
+
@project_name
|
31
|
+
end
|
32
|
+
|
33
|
+
def run(file, args)
|
34
|
+
@project_name = args[:project_name]
|
35
|
+
@project_dir = args[:project_dir]
|
36
|
+
|
37
|
+
Gitplate.debug_msg "running plate - start"
|
38
|
+
load file
|
39
|
+
Gitplate.debug_msg "running plate - completed"
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_class_name(type)
|
43
|
+
type.to_s.split('_').map{|word| word.capitalize}.join
|
44
|
+
end
|
45
|
+
|
46
|
+
def expand_path(path)
|
47
|
+
File.expand_path(File.join(@project_dir, path))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Outputs
|
52
|
+
class Debug
|
53
|
+
def execute(msg)
|
54
|
+
puts msg.color(:cyan).bright
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Fatal
|
59
|
+
def execute(msg)
|
60
|
+
puts msg.color(:red).bright
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def project_name
|
68
|
+
Gitplate::Plate.instance.project_name
|
69
|
+
end
|
70
|
+
|
71
|
+
def output(type, msg)
|
72
|
+
Gitplate::Plate.instance.output type, " #{msg}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def custom(&block)
|
76
|
+
Gitplate::Plate.instance.custom &block
|
77
|
+
end
|
78
|
+
|
79
|
+
def rename(from, to)
|
80
|
+
Gitplate::Plate.instance.rename from, to
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitplate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Luke Smith
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-12-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: gli
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rainbow
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rdoc
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Project templates from a git repository
|
77
|
+
email:
|
78
|
+
- stuff@lukesmith.net
|
79
|
+
executables:
|
80
|
+
- gitplate
|
81
|
+
extensions: []
|
82
|
+
|
83
|
+
extra_rdoc_files: []
|
84
|
+
|
85
|
+
files:
|
86
|
+
- lib/gitplate/gitplate.rb
|
87
|
+
- lib/gitplate/plate.rb
|
88
|
+
- bin/gitplate
|
89
|
+
- LICENSE
|
90
|
+
homepage: http://www.gitplate.com/
|
91
|
+
licenses: []
|
92
|
+
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options:
|
95
|
+
- --title
|
96
|
+
- gitplate
|
97
|
+
- --main
|
98
|
+
- README.rdoc
|
99
|
+
- -ri
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project: gitplate
|
123
|
+
rubygems_version: 1.8.8
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: Project templates from a git repository
|
127
|
+
test_files: []
|
128
|
+
|