gemplate 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4de43aa47366852ef272bcc39cce69f23cc135b
4
- data.tar.gz: dcfd0a0d2ea73448f69eb75f95825c462762414a
3
+ metadata.gz: 7c1a5de2d6e820fe80b652a31cc81d09275306a6
4
+ data.tar.gz: 6dc06d40f47832e111ed86929fd3d846106a10d3
5
5
  SHA512:
6
- metadata.gz: 387f5725fd412f3335e5ff3d83d56c20d98ab243d765ab63b178250713db5b37aa63a7768640458ee059983190d1a0c3ac5194a63714d3377bdcd880f1413651
7
- data.tar.gz: 54ba37b53ace3a2d730db654526ec6f464681a3b8b100501422784223f3807aede69df6474568fde576eeced8ec7d778225436a169ceaf6952163869efd46d6a
6
+ metadata.gz: f16ab872920cf3febb76fce2a36bbb658ce171938254203ab9db8bcc3a9da9361f633be396ab99a785e54be48e0934a86a2e0f129cd9b535da84df80a4f5d660
7
+ data.tar.gz: 655a543cb4c4514ead7839ef0f2304dc4be323b735288bc1329a47707df942287a57166bf31e1d2cbceca9cd5e5fad1284586fbb5c27ed5827d8596a634f3c6d
data/.test/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
data/gemplate.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'gemplate'
3
- s.version = '0.0.1'
3
+ s.version = '0.1.0'
4
4
  s.date = Time.now.strftime("%Y-%m-%d")
5
5
 
6
6
  s.summary = 'Bootstrap tool for making gems'
data/lib/gemplate.rb CHANGED
@@ -33,11 +33,13 @@ module Gemplate
33
33
 
34
34
  def create
35
35
  create_directory
36
+ Dir.chdir @name
37
+ add_license
36
38
  process_templates
37
39
  adjust_files
38
- add_license
39
40
  make_repo
40
41
  configure_travis
42
+ Dir.chdir '..'
41
43
  end
42
44
 
43
45
  private
@@ -45,16 +47,35 @@ module Gemplate
45
47
  def create_directory
46
48
  fail "#{@name} already exists" if File.exist? @name
47
49
  FileUtils.cp_r TEMPLATE, @name
48
- Dir.chdir @name
50
+ end
51
+
52
+ def add_license
53
+ url = "#{LICENSE_URL}/#{@license}.txt"
54
+ File.open('LICENSE', 'w') do |fh|
55
+ license = Curl::Easy.perform(url)
56
+ if license.response_code == 404
57
+ fail ArgumentError, 'Invalid license name provided'
58
+ end
59
+ fh.write license.body_str
60
+ end
61
+ end
62
+
63
+ def replacements
64
+ [
65
+ [/AUTHOR_NAME/, @user],
66
+ [/LICENSE_NAME/, @license],
67
+ [/FULL_NAME/, @full_name],
68
+ [/REPO_NAME/, @name],
69
+ [/EMAIL_ADDRESS/, @email],
70
+ [/CURRENT_YEAR/, Time.now.strftime('%Y')]
71
+ ]
49
72
  end
50
73
 
51
74
  def process_templates
52
75
  Dir.glob('**/*').each do |path|
53
76
  next unless File.file? path
54
77
  text = File.read path
55
- [[/AUTHOR_NAME/, @user], [/LICENSE_NAME/, @license],
56
- [/FULL_NAME/, @full_name], [/REPO_NAME/, @name],
57
- [/EMAIL_ADDRESS/, @email]].each { |regex, new| text.gsub! regex, new }
78
+ replacements.each { |regex, new| text.gsub! regex, new }
58
79
  File.open(path, 'w') { |fh| fh.write text }
59
80
  end
60
81
  end
@@ -66,24 +87,33 @@ module Gemplate
66
87
  moves.each { |original, new| FileUtils.move original, new }
67
88
  end
68
89
 
69
- def add_license
70
- url = "#{LICENSE_URL}/#{@license}.txt"
71
- File.open('LICENSE', 'w') do |fh|
72
- text = Curl::Easy.perform(url).body_str
73
- fh.write text
74
- end
75
- end
76
-
77
90
  def make_repo
78
91
  Rugged::Repository.init_at '.'
79
92
  `git remote add origin "git@github.com:#{@user}/#{@name}"`
80
93
  end
81
94
 
82
95
  def configure_travis
83
- args = [
84
- 'encrypt', '-p', '--add', 'notifications.irc.channels', @irc_stanza
85
- ]
86
- Travis::CLI.run(args)
96
+ crypter = Travis::CLI::Encrypt.new
97
+ args = ['encrypt', '--skip-completion-check', '--explode', '-p',
98
+ '--add', 'notifications.irc.channels', @irc_stanza]
99
+ crypter.parse args
100
+ crypter.execute
101
+ rescue Travis::Client::NotLoggedIn
102
+ puts 'Travis IRC configuration failed; ' + \
103
+ 'make sure the repo exists on GitHub and Travis, then run:' + \
104
+ "\n travis #{args.join ' '}"
105
+ end
106
+ end
107
+ end
108
+
109
+ module Travis
110
+ module CLI
111
+ ##
112
+ # Adjust Travis to raise instead of shouting
113
+ class ApiCommand
114
+ def authenticate
115
+ fail Travis::Client::NotLoggedIn if access_token.nil?
116
+ end
87
117
  end
88
118
  end
89
119
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'fileutils'
2
3
 
3
4
  describe Gemplate do
4
5
  describe '#new' do
@@ -6,4 +7,87 @@ describe Gemplate do
6
7
  expect(Gemplate.new).to be_an_instance_of Gemplate::Gem
7
8
  end
8
9
  end
10
+
11
+ describe Gem do
12
+ let(:subject) do
13
+ Gemplate::Gem.new(
14
+ name: 'gemplate',
15
+ user: 'akerl',
16
+ full_name: 'my_full_name',
17
+ email: 'my_email@example.org',
18
+ irc_stanza: 'irc://irc.example.org:6697#channel,password',
19
+ license: 'MIT'
20
+ )
21
+ end
22
+
23
+ before(:all) do
24
+ Dir.chdir '.test'
25
+ FileUtils.rm_rf 'gemplate'
26
+ end
27
+ after(:each) { FileUtils.rm_rf 'gemplate' }
28
+
29
+ describe '#create' do
30
+ it 'makes a directory from the template' do
31
+ subject.create
32
+ expect(Dir.exist? 'gemplate').to be_true
33
+ end
34
+
35
+ it 'raises an error if the directory already exists' do
36
+ subject.create
37
+ expect { subject.create }.to raise_error RuntimeError
38
+ end
39
+
40
+ it 'adds a license file' do
41
+ subject.create
42
+ expect(File.exist? 'gemplate/LICENSE').to be_true
43
+ end
44
+
45
+ it 'fails if you try to pull a non-existent license' do
46
+ gem = Gemplate::Gem.new(
47
+ name: 'gemplate',
48
+ user: 'akerl',
49
+ full_name: 'my_full_name',
50
+ email: 'my_email@example.org',
51
+ irc_stanza: 'irc://irc.example.org:6697#channel,password',
52
+ license: 'MIT-3'
53
+ )
54
+ expect { gem.create }.to raise_error ArgumentError
55
+ end
56
+
57
+ it 'replaces placeholders in files' do
58
+ subject.create
59
+ expect(File.read 'gemplate/README.md').to_not match(/^REPO_NAME/)
60
+ end
61
+
62
+ it 'adjusts file names' do
63
+ subject.create
64
+ expect(File.exist? 'gemplate/gemplate.gemspec').to be_true
65
+ expect(File.exist? 'gemplate/REPO_NAME.gemspec').to be_false
66
+ end
67
+
68
+ it 'makes the git repo' do
69
+ subject.create
70
+ expect(Dir.exist? 'gemplate/.git').to be_true
71
+ expect(File.read 'gemplate/.git/config').to match(/remote "origin"/)
72
+ end
73
+
74
+ it 'configures the IRC key for Travis' do
75
+ subject.create
76
+ expect(File.read 'gemplate/.travis.yml').to match(/channels:/)
77
+ end
78
+
79
+ it 'warns if the Travis configuration fails' do
80
+ gem = Gemplate::Gem.new(
81
+ name: 'other_gem',
82
+ user: 'akerl',
83
+ full_name: 'my_full_name',
84
+ email: 'my_email@example.org',
85
+ irc_stanza: 'irc://irc.example.org:6697#channel,password',
86
+ license: 'MIT'
87
+ )
88
+ expect(gem).to receive(:puts).with(/Travis IRC configuration failed/)
89
+ gem.create
90
+ end
91
+ end
92
+ end
9
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemplate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: travis
@@ -146,6 +146,7 @@ files:
146
146
  - .gitignore
147
147
  - .rspec
148
148
  - .rubocop.yml
149
+ - .test/.gitignore
149
150
  - .travis.yml
150
151
  - Gemfile
151
152
  - LICENSE
@@ -161,7 +162,6 @@ files:
161
162
  - template/.rubocop.yml
162
163
  - template/.travis.yml
163
164
  - template/Gemfile
164
- - template/LICENSE
165
165
  - template/README.md
166
166
  - template/REPO_NAME.gemspec
167
167
  - template/Rakefile
data/template/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014 FULL_NAME
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
22
-