crystallize 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -0
- data/lib/crystallize/creator.rb +48 -19
- data/lib/crystallize/gem_name/MIT-LICENSE +1 -1
- data/lib/crystallize/gem_name/README.md +2 -2
- data/lib/crystallize/gem_name/gem_name.gemspec +6 -6
- data/lib/crystallize/gem_name/lib/gem_name.rb +2 -2
- data/lib/crystallize/gem_name/lib/gem_name/version.rb +1 -1
- data/lib/crystallize/gem_name/spec/spec_helper.rb +1 -1
- data/lib/crystallize/settings_manager.rb +53 -0
- data/lib/crystallize/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 751fb81bc9177eddd2d35f2f0bafbd3fdc7aece6
|
4
|
+
data.tar.gz: dfe57778e7fbc984d6b9c9fd1e4926c1dc21c3c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbd67601d98e64150015d0c2a3b124c2bbe2d5a4f1178abd84f8578c750b7554dc658ca2641d6b07363427cf7e9f49be0d2ec2e63b5555653fb856dfab20652d
|
7
|
+
data.tar.gz: 9a2cb5c11f8408f51383e51396f138b1bf28a98be729d1d38d4a08cc616fc4b9c465a0868e581602dc554cc2a09f3688491e51084bd89475c2d8cb397a8adf8b
|
data/README.md
CHANGED
@@ -17,8 +17,25 @@ gem install crystallize
|
|
17
17
|
Usage
|
18
18
|
-----
|
19
19
|
|
20
|
+
#### Typical usage
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ crystallize my_gem
|
24
|
+
Created gem in ./my_gem
|
25
|
+
```
|
26
|
+
|
27
|
+
#### Settings
|
28
|
+
|
29
|
+
The first time you run `crystallize`, it'll prompt you for settings that'll be used in all of your gems:
|
30
|
+
|
20
31
|
```bash
|
21
32
|
$ crystallize my_gem
|
33
|
+
Welcome to Crystallize!
|
34
|
+
Please enter some settings for your gems:
|
35
|
+
Your name: Tom Benner
|
36
|
+
Your email: tombenner@gmail.com
|
37
|
+
Your GitHub username: tombenner
|
38
|
+
Thanks! Saved your settings in ~/.crystallize.yml
|
22
39
|
Created gem in ./my_gem
|
23
40
|
```
|
24
41
|
|
data/lib/crystallize/creator.rb
CHANGED
@@ -3,37 +3,66 @@ require 'fileutils'
|
|
3
3
|
module Crystallize
|
4
4
|
class Creator
|
5
5
|
def initialize
|
6
|
-
|
7
|
-
@gem_name =
|
8
|
-
|
9
|
-
puts "Please specify a gem name:\ncrystallize my_gem" and return
|
10
|
-
end
|
6
|
+
@settings_manager = SettingsManager.new
|
7
|
+
@gem_name = ARGV.shift
|
8
|
+
@gem_dir = "#{Dir.pwd}/#{@gem_name}"
|
11
9
|
end
|
12
10
|
|
13
11
|
def run
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
@settings = @settings_manager.get
|
13
|
+
if @gem_name.nil? || @gem_name.empty?
|
14
|
+
puts "Please specify a gem name:\ncrystallize my_gem"
|
15
|
+
return
|
16
|
+
end
|
17
|
+
if @gem_name == 'settings'
|
18
|
+
@settings_manager.write
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
FileUtils.rm_rf(@gem_dir)
|
23
|
+
FileUtils.cp_r("#{Crystallize.dir}/gem_name", @gem_dir)
|
24
|
+
|
25
|
+
Dir.chdir(@gem_dir) do
|
19
26
|
rename_files
|
20
|
-
|
21
|
-
next unless File.file?(name)
|
22
|
-
content = File.read(name)
|
23
|
-
content.gsub!('gem_name', @gem_name)
|
24
|
-
content.gsub!('GemName', gem_name_camelized)
|
25
|
-
File.write(name, content)
|
26
|
-
end
|
27
|
+
replace_tokens
|
27
28
|
end
|
28
|
-
|
29
|
+
|
30
|
+
Dir.chdir("#{@gem_dir}/lib") do
|
29
31
|
rename_files
|
30
32
|
end
|
31
|
-
Dir.chdir(gem_dir) do
|
33
|
+
Dir.chdir(@gem_dir) do
|
32
34
|
`git init && git add . && git commit -m 'Initial commit'`
|
33
35
|
end
|
36
|
+
|
34
37
|
puts "Created gem in ./#{@gem_name}"
|
35
38
|
end
|
36
39
|
|
40
|
+
private
|
41
|
+
|
42
|
+
def replace_tokens
|
43
|
+
token_values = get_token_values
|
44
|
+
Dir.glob('**/*').each do |name|
|
45
|
+
next unless File.file?(name)
|
46
|
+
content = File.read(name)
|
47
|
+
token_values.each do |token, value|
|
48
|
+
content.gsub!("{{#{token}}}", value)
|
49
|
+
end
|
50
|
+
File.write(name, content)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_token_values
|
55
|
+
gem_name_camelized = @gem_name.split('_').map { |word| word.capitalize }.join
|
56
|
+
{
|
57
|
+
:gem_name => @gem_name,
|
58
|
+
:gem_name_camelized => gem_name_camelized,
|
59
|
+
:settings_name => @settings['name'],
|
60
|
+
:settings_email => @settings['email'],
|
61
|
+
:settings_github_username => @settings['github_username'],
|
62
|
+
:year => Time.now.year.to_s
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
37
66
|
def rename_files
|
38
67
|
%x[for f in *gem_name*; do mv "$f" "`echo $f | sed s/gem_name/#{@gem_name}/`"; done]
|
39
68
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
{{gem_name_camelized}}
|
2
2
|
=====
|
3
3
|
|
4
4
|
Overview
|
@@ -7,4 +7,4 @@ Overview
|
|
7
7
|
License
|
8
8
|
-------
|
9
9
|
|
10
|
-
|
10
|
+
{{gem_name_camelized}} is released under the MIT License. Please see the MIT-LICENSE file for details.
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require File.expand_path('../lib/gem_name/version', __FILE__)
|
1
|
+
require File.expand_path('../lib/{{gem_name}}/version', __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.authors = ['
|
5
|
-
s.email = ['
|
4
|
+
s.authors = ['{{settings_name}}']
|
5
|
+
s.email = ['{{settings_email}}']
|
6
6
|
s.description = s.summary = %q{TODO}
|
7
|
-
s.homepage = 'https://github.com/
|
7
|
+
s.homepage = 'https://github.com/{{settings_github_username}}/{{gem_name}}'
|
8
8
|
|
9
9
|
s.files = `git ls-files`.split($\)
|
10
|
-
s.name = 'gem_name'
|
10
|
+
s.name = '{{gem_name}}'
|
11
11
|
s.require_paths = ['lib']
|
12
|
-
s.version =
|
12
|
+
s.version = {{gem_name_camelized}}::VERSION
|
13
13
|
s.license = 'MIT'
|
14
14
|
|
15
15
|
s.add_development_dependency 'rspec'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Crystallize
|
5
|
+
class SettingsManager
|
6
|
+
def get
|
7
|
+
read || write
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
puts "Welcome to Crystallize!\nPlease enter some settings for your gems:"
|
12
|
+
settings = prompt_settings
|
13
|
+
settings['version'] = Crystallize::VERSION
|
14
|
+
File.open(path, 'w') do |file|
|
15
|
+
YAML.dump(settings, file)
|
16
|
+
end
|
17
|
+
puts "Thanks! Saved your settings in ~/.crystallize.yml"
|
18
|
+
settings
|
19
|
+
end
|
20
|
+
|
21
|
+
def read
|
22
|
+
return nil unless File.exist?(path)
|
23
|
+
settings = YAML.load_file(path)
|
24
|
+
return nil unless settings && settings['name'] && settings['email'] && settings['github_username']
|
25
|
+
settings
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def prompt_settings
|
31
|
+
settings = {}
|
32
|
+
settings['name'] = prompt_setting('name')
|
33
|
+
settings['email'] = prompt_setting('email')
|
34
|
+
settings['github_username'] = prompt_setting('GitHub username')
|
35
|
+
settings
|
36
|
+
end
|
37
|
+
|
38
|
+
def prompt_setting(name)
|
39
|
+
print "Your #{name}: "
|
40
|
+
value = nil
|
41
|
+
loop do
|
42
|
+
value = gets.chomp
|
43
|
+
break if !value.empty?
|
44
|
+
puts "Please enter your #{name}!"
|
45
|
+
end
|
46
|
+
value
|
47
|
+
end
|
48
|
+
|
49
|
+
def path
|
50
|
+
@path ||= Pathname.new(`echo ~`.strip).join('.crystallize.yml')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/crystallize/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crystallize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Benner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/crystallize/gem_name/lib/gem_name.rb
|
51
51
|
- lib/crystallize/gem_name/lib/gem_name/version.rb
|
52
52
|
- lib/crystallize/gem_name/spec/spec_helper.rb
|
53
|
+
- lib/crystallize/settings_manager.rb
|
53
54
|
- lib/crystallize/version.rb
|
54
55
|
- spec/spec_helper.rb
|
55
56
|
homepage: https://github.com/tombenner/crystallize
|