skele 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/VERSION +1 -1
  2. data/bin/skele +74 -70
  3. data/lib/skele.rb +150 -1
  4. data/skele.gemspec +1 -1
  5. metadata +10 -10
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/skele CHANGED
@@ -1,7 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "find"
4
- require "fileutils"
3
+ require 'skele'
4
+
5
+ skeleton = Skele::Runner.new(ARGV[0], Dir.getwd)
6
+ skeleton.summon
7
+
5
8
 
6
9
  def colorize(text, color_code)
7
10
  "\e[#{color_code}m#{text}\e[0m"
@@ -19,73 +22,74 @@ def blue(text)
19
22
  colorize text, 34
20
23
  end
21
24
 
22
- def relative_path(abspath,relativeto)
23
- path = abspath.split(File::SEPARATOR)
24
- rel = relativeto.split(File::SEPARATOR)
25
+ # def relative_path(abspath,relativeto)
26
+ # path = abspath.split(File::SEPARATOR)
27
+ # rel = relativeto.split(File::SEPARATOR)
25
28
 
26
- while (path.length > 0) && (path.first == rel.first)
27
- path.shift
28
- rel.shift
29
- end
30
-
31
- path.join(File::SEPARATOR)
32
- end
33
-
34
- SKELETON = ARGV[0]
35
-
36
- if SKELETON.nil?
37
- STDOUT.puts "Usage: skele <name>"
38
- else
39
-
40
- SKELETON_ROOT = ENV['HOME'] + File::SEPARATOR + ".skele" + File::SEPARATOR
41
- SKELETON_DIR = SKELETON_ROOT + SKELETON
42
- SKELETON_TARGET = Dir.getwd + File::SEPARATOR
43
-
44
- if File.directory? SKELETON_DIR
45
- STDOUT.puts "\nSummoning skeleton '#{SKELETON}' from '#{SKELETON_DIR}', copying files:\n\n"
46
-
47
- Find.find(SKELETON_DIR) do |file|
48
- relative_path = relative_path file, SKELETON_DIR
49
-
50
- # skip the containing directory
51
- next if relative_path.empty?
52
-
53
- # skip .git directory
54
- next if relative_path.split(File::SEPARATOR)[0] == ".git"
55
-
56
- # copy files
57
- if(File.directory? file)
58
- if File.exists?(SKELETON_TARGET + relative_path)
59
- STDOUT.puts " #{red("exists")} #{SKELETON_TARGET + relative_path}"
60
- else
61
- Dir::mkdir(SKELETON_TARGET + relative_path)
62
- STDOUT.puts " #{green("mkdir")} #{SKELETON_TARGET + relative_path}"
63
- end
64
- else
65
- if File.exists?(SKELETON_TARGET + relative_path)
66
- STDOUT.puts " #{red("exists")} #{SKELETON_TARGET + relative_path}"
67
- else
68
- FileUtils::copy(file, SKELETON_TARGET + relative_path)
69
- STDOUT.puts " #{green("create")} #{SKELETON_TARGET + relative_path}"
70
- end
71
- end
72
- end
73
-
74
- # if there is a gemfile, run bundle install just to be nice
75
- if File.exists? SKELETON_TARGET + "Gemfile"
76
- STDOUT.puts "\nInstalling bundle from gemfile\n\n"
77
- bundle_results = `bundle install --path vendor/bundle`
78
-
79
- # STDOUT.puts bundleresults.dump
80
- bundle_lines = bundle_results.split("\n")
81
-
82
- bundle_lines.each do |line|
83
- STDOUT.puts " " + line
84
- end
85
- end
29
+ # while (path.length > 0) && (path.first == rel.first)
30
+ # path.shift
31
+ # rel.shift
32
+ # end
33
+
34
+ # path.join(File::SEPARATOR)
35
+ # end
36
+
37
+ # def indent(string)
38
+ # string.split("\n").each do |line|
39
+ # indented += INDENTATION + line + "\n"
40
+ # end
41
+
42
+ # return indented
43
+ # end
44
+
45
+ # SKELETON = ARGV[0]
46
+
47
+ # if SKELETON.nil?
48
+ # STDOUT.puts "Usage: skele <name>"
49
+ # else
50
+
51
+ # SKELETON_ROOT = ENV['HOME'] + File::SEPARATOR + ".skele" + File::SEPARATOR
52
+ # SKELETON_DIR = SKELETON_ROOT + SKELETON
53
+ # SKELETON_TARGET = Dir.getwd + File::SEPARATOR
54
+
55
+ # if File.directory? SKELETON_DIR
56
+ # STDOUT.puts "\nSummoning skeleton '#{SKELETON}' from '#{SKELETON_DIR}', copying files:\n\n"
57
+
58
+ # Find.find(SKELETON_DIR) do |file|
59
+ # relative_path = relative_path file, SKELETON_DIR
60
+
61
+ # # skip the containing directory
62
+ # next if relative_path.empty?
63
+
64
+ # # skip .git directory
65
+ # next if relative_path.split(File::SEPARATOR)[0] == ".git"
66
+
67
+ # # copy files
68
+ # if(File.directory? file)
69
+ # if File.exists?(SKELETON_TARGET + relative_path)
70
+ # STDOUT.puts indent "#{red("exists")} #{SKELETON_TARGET + relative_path}"
71
+ # else
72
+ # Dir::mkdir(SKELETON_TARGET + relative_path)
73
+ # STDOUT.puts indent " #{green("mkdir")} #{SKELETON_TARGET + relative_path}"
74
+ # end
75
+ # else
76
+ # if File.exists?(SKELETON_TARGET + relative_path)
77
+ # STDOUT.puts indent "#{red("exists")} #{SKELETON_TARGET + relative_path}"
78
+ # else
79
+ # FileUtils::copy(file, SKELETON_TARGET + relative_path)
80
+ # STDOUT.puts indent "#{green("create")} #{SKELETON_TARGET + relative_path}"
81
+ # end
82
+ # end
83
+ # end
84
+
85
+ # # if there is a gemfile, run bundle install just to be nice
86
+ # if File.exists? SKELETON_TARGET + "Gemfile"
87
+ # STDOUT.puts "\nInstalling bundle from gemfile\n\n"
88
+ # STDOUT.puts indent `bundle instal --path=vendor/bundle`
89
+ # end
86
90
 
87
- STDOUT.puts "\n#{green("Skeleton summoned! Have fun!")}\n\n"
88
- else
89
- STDOUT.puts "#{red("Error")} skeleton: '#{SKELETON}' not found, expected in: #{SKELETON_DIR}"
90
- end
91
- end
91
+ # STDOUT.puts "\n#{green("Skeleton summoned! Have fun!")}\n\n"
92
+ # else
93
+ # STDOUT.puts "#{red("Error")} skeleton: '#{SKELETON}' not found, expected in: #{SKELETON_DIR}"
94
+ # end
95
+ # end
data/lib/skele.rb CHANGED
@@ -1 +1,150 @@
1
- # Skele is just a command line tool right now
1
+ require "find"
2
+ require "fileutils"
3
+
4
+ module Skele
5
+ SKELETON_ROOT = ENV['HOME'] + File::SEPARATOR + ".skele" + File::SEPARATOR
6
+ INDENTATION = " "
7
+
8
+ class Skeleton
9
+ attr_reader :skeleton, :skeleton_dir, :destination
10
+
11
+ def initialize(skeleton, destination, root=SKELETON_ROOT)
12
+ @skeleton = skeleton
13
+ @skeleton_dir = root + @skeleton
14
+ @destination = destination + File::SEPARATOR
15
+ @ignore = [".git", ".hg"]
16
+ end
17
+
18
+ def relative_path(abspath,relativeto)
19
+ path = abspath.split(File::SEPARATOR)
20
+ rel = relativeto.split(File::SEPARATOR)
21
+
22
+ while (path.length > 0) && (path.first == rel.first)
23
+ path.shift
24
+ rel.shift
25
+ end
26
+
27
+ path.join(File::SEPARATOR)
28
+ end
29
+
30
+ def summon
31
+ copy_files
32
+ bundle_install
33
+ end
34
+
35
+ def copy_files
36
+ if File.directory? @skeleton_dir
37
+ result = Array.new
38
+
39
+ Find.find(@skeleton_dir) do |file|
40
+ relative_path = relative_path file, @skeleton_dir
41
+
42
+ # skip the containing directory
43
+ next if relative_path.empty?
44
+
45
+ # skip .git directory
46
+ next if @ignore.include? relative_path.split(File::SEPARATOR)[0]
47
+
48
+ # copy files
49
+ if(File.directory? file)
50
+ if File.exists?(@destination + relative_path)
51
+ result.push({:action => "exists", :file => relative_path})
52
+ else
53
+ Dir::mkdir(@destination + relative_path)
54
+ result.push({:action => "mkdir", :file => relative_path})
55
+ end
56
+ else
57
+ if File.exists?(@destination + relative_path)
58
+ result.push({:action => "exists", :file => relative_path})
59
+ else
60
+ FileUtils::copy(file, @destination + relative_path)
61
+ result.push({:action => "create", :file => relative_path})
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ return result
68
+ end
69
+
70
+ def bundle_install
71
+ if File.exists? @destination + "Gemfile"
72
+ return `bundle install --path=vendor/bundle`
73
+ end
74
+
75
+ return nil
76
+ end
77
+ end
78
+
79
+ class Runner
80
+ def initialize(skeleton, destination, root=SKELETON_ROOT)
81
+ @skeleton = Skeleton.new(skeleton, destination, root)
82
+ end
83
+
84
+ def summon
85
+ STDOUT.puts "\nSummoning skeleton '#{@skeleton.skeleton}' from '#{@skeleton.destination}'"
86
+
87
+ copy_files
88
+ bundle_install
89
+
90
+ STDOUT.puts "\nSkeleton complete. Enjoy!\n\n"
91
+ end
92
+
93
+ def bundle_install
94
+ STDOUT.puts "\nRunning bundle install\n\n"
95
+
96
+ bundle = @skeleton.bundle_install
97
+
98
+ unless bundle.nil?
99
+ STDOUT.puts indent bundle
100
+ end
101
+ end
102
+
103
+ def copy_files
104
+ STDOUT.puts "\nCopying files\n\n"
105
+ file_result = @skeleton.copy_files
106
+
107
+ if file_result.nil?
108
+ STDOUT.puts indent(red("Error:") + "Skeleton '#{@skeleton.skeleton}' does not exist or is not a directory")
109
+ else
110
+
111
+ file_result.each do |result|
112
+ case result[:action]
113
+ when "mkdir"
114
+ STDOUT.puts indent(" " + green(result[:action]) + " " + result[:file])
115
+ when "create"
116
+ STDOUT.puts indent(green(result[:action]) + " " + result[:file])
117
+ when "exists"
118
+ STDOUT.puts indent(red(result[:action]) + " " + result[:file])
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def indent(string)
125
+ indented = ""
126
+
127
+ string.split("\n").each do |line|
128
+ indented += INDENTATION + line + "\n"
129
+ end
130
+
131
+ return indented
132
+ end
133
+
134
+ def colorize(text, color_code)
135
+ "\e[#{color_code}m#{text}\e[0m"
136
+ end
137
+
138
+ def red(text)
139
+ colorize text, 31
140
+ end
141
+
142
+ def green(text)
143
+ colorize text, 32
144
+ end
145
+
146
+ def blue(text)
147
+ colorize text, 34
148
+ end
149
+ end
150
+ end
data/skele.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "skele"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Rehberg"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skele
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
16
- requirement: &2153871520 !ruby/object:Gem::Requirement
16
+ requirement: &2163123900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153871520
24
+ version_requirements: *2163123900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2153871040 !ruby/object:Gem::Requirement
27
+ requirement: &2163123420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153871040
35
+ version_requirements: *2163123420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &2153870560 !ruby/object:Gem::Requirement
38
+ requirement: &2163122940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.6.4
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2153870560
46
+ version_requirements: *2163122940
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rcov
49
- requirement: &2153870080 !ruby/object:Gem::Requirement
49
+ requirement: &2163122460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153870080
57
+ version_requirements: *2163122460
58
58
  description: Skele is a simple command line too to build directory structures based
59
59
  on template directories
60
60
  email: hi@alexrehberg.com
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  segments:
94
94
  - 0
95
- hash: 526161455790606130
95
+ hash: -126893824170063689
96
96
  required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements: