starter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +17 -0
- data/Rakefile +0 -2
- data/lib/starter/string.rb +16 -0
- data/lib/starter/tasks/bootstrap.rb +27 -0
- data/lib/starter/tasks/gems.rb +70 -9
- data/lib/starter/tasks/git.rb +5 -3
- data/lib/starter/tasks/helpers.rb +40 -0
- data/lib/starter/tasks/markdown.rb +20 -0
- data/lib/starter/tasks/npm.rb +15 -0
- metadata +6 -2
data/README.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Starter
|
2
|
+
|
3
|
+
Starter is the place where I collect all the code that should be reusable, but which I've been copying and pasting here, there, and behind you.
|
4
|
+
|
5
|
+
Rake tasks:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require "starter/tasks/gems"
|
9
|
+
require "starter/tasks/git"
|
10
|
+
|
11
|
+
desc "Build everything that needs building"
|
12
|
+
task "build" => %w[ gem:build ]
|
13
|
+
|
14
|
+
desc "Build and push the gem, tag the git"
|
15
|
+
task "release" => %w[ build gem:push tag ]
|
16
|
+
|
17
|
+
```
|
data/Rakefile
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
module Starter
|
3
|
+
module String
|
4
|
+
extend self
|
5
|
+
def camel_case( string )
|
6
|
+
string.split('_').map do |word|
|
7
|
+
"#{word.slice(/^\w/).upcase}#{word.slice(/^\w(\w+)/, 1)}"
|
8
|
+
end.join
|
9
|
+
end
|
10
|
+
|
11
|
+
def snake_case( string )
|
12
|
+
string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "starter/tasks/helpers"
|
2
|
+
|
3
|
+
$STARTER[:directory] = File.basename(Dir.pwd)
|
4
|
+
$STARTER[:gemspec_file] = "#{$STARTER[:directory]}.gemspec"
|
5
|
+
|
6
|
+
task "bootstrap" => %w[ LICENSE ]
|
7
|
+
|
8
|
+
file "LICENSE" => %w[ determine_author ] do
|
9
|
+
File.open("LICENSE", "w") do |file|
|
10
|
+
file.puts mit_license(:author => $STARTER[:author])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def mit_license(options)
|
15
|
+
author = options[:author]
|
16
|
+
license = <<-TXT
|
17
|
+
Copyright (c) #{Time.now.year} #{author}
|
18
|
+
|
19
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
20
|
+
|
21
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
TXT
|
25
|
+
end
|
26
|
+
|
27
|
+
|
data/lib/starter/tasks/gems.rb
CHANGED
@@ -1,14 +1,39 @@
|
|
1
1
|
require "starter/tasks/helpers"
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
gemspec_path = FileList["*.gemspec"].first || "#{$STARTER[:directory]}.gemspec"
|
4
|
+
project_name = gemspec_path.chomp(".gemspec")
|
5
|
+
|
6
|
+
task "bootstrap" => [ gemspec_path, "lib", "lib/#{project_name}.rb" ]
|
7
|
+
|
8
|
+
task "release" => %w[ gem:push ]
|
9
|
+
|
10
|
+
|
11
|
+
directory "lib"
|
12
|
+
|
13
|
+
file "lib/#{project_name}.rb" do |target|
|
14
|
+
File.open(target.name, "w") do |file|
|
15
|
+
file.puts <<-TXT
|
16
|
+
module #{Starter::String.camel_case(project_name)}
|
17
|
+
|
18
|
+
end
|
19
|
+
TXT
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
file gemspec_path => %w[ determine_author ] do |target|
|
24
|
+
File.open(target.name, "w") do |file|
|
25
|
+
file.puts gemspec_template(
|
26
|
+
:author => $STARTER[:author],
|
27
|
+
:project_name => $STARTER[:directory]
|
28
|
+
)
|
29
|
+
end
|
5
30
|
end
|
6
31
|
|
7
|
-
|
32
|
+
task "build" => %w[ gem:build ]
|
8
33
|
|
9
|
-
desc "build a gem using #{
|
34
|
+
desc "build a gem using #{gemspec_path}"
|
10
35
|
task "gem:build" do
|
11
|
-
sh "gem build #{
|
36
|
+
sh "gem build #{gemspec_path}"
|
12
37
|
end
|
13
38
|
|
14
39
|
task "gem:push" do
|
@@ -21,10 +46,19 @@ task "gem:push" do
|
|
21
46
|
end
|
22
47
|
end
|
23
48
|
|
24
|
-
task "
|
25
|
-
|
26
|
-
|
27
|
-
|
49
|
+
task "gem:dependencies" => "gemspec" do
|
50
|
+
gemspec = $STARTER[:gemspec]
|
51
|
+
require "pp"
|
52
|
+
pp gemspec.dependencies.first
|
53
|
+
# install dependencies from gemspec
|
54
|
+
end
|
55
|
+
|
56
|
+
task "version" => "read_gemspec" do
|
57
|
+
$STARTER[:version] = $STARTER[:gemspec].version.version
|
58
|
+
end
|
59
|
+
|
60
|
+
task "read_gemspec" do
|
61
|
+
$STARTER[:gemspec] = read_gemspec(gemspec_path)
|
28
62
|
end
|
29
63
|
|
30
64
|
task "clean" do
|
@@ -33,3 +67,30 @@ task "clean" do
|
|
33
67
|
end
|
34
68
|
end
|
35
69
|
|
70
|
+
def read_gemspec(file)
|
71
|
+
str = File.read(file)
|
72
|
+
eval(str)
|
73
|
+
end
|
74
|
+
|
75
|
+
def gemspec_template(options={})
|
76
|
+
project_name, author = options.values_at(:project_name, :author)
|
77
|
+
gemspec = <<-TXT
|
78
|
+
Gem::Specification.new do |s|
|
79
|
+
s.name = "#{project_name}"
|
80
|
+
s.version = "0.1.0"
|
81
|
+
s.authors = ["#{author}"]
|
82
|
+
#s.homepage = ""
|
83
|
+
s.summary = "A new project, a nascent bundle of win, whose author hasn't described it yet."
|
84
|
+
|
85
|
+
s.files = %w[
|
86
|
+
LICENSE
|
87
|
+
README.md
|
88
|
+
] + Dir["lib/**/*.rb"]
|
89
|
+
s.require_path = "lib"
|
90
|
+
|
91
|
+
s.add_development_dependency("starter", ">=0.1.0")
|
92
|
+
end
|
93
|
+
TXT
|
94
|
+
end
|
95
|
+
|
96
|
+
|
data/lib/starter/tasks/git.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require "starter/tasks/helpers"
|
2
2
|
|
3
|
+
task "release" => %w[ git:tag ]
|
4
|
+
|
3
5
|
desc "Create a git tag using the project version"
|
4
6
|
# Note that the user of this library must ensure that a task named
|
5
7
|
# "version" is defined before invocation time.
|
6
|
-
task "tag" => "version" do
|
7
|
-
version =
|
8
|
+
task "git:tag" => "version" do
|
9
|
+
version = $STARTER[:version]
|
8
10
|
git_tag = `git tag -l #{version}`.chomp
|
9
11
|
if git_tag == version
|
10
|
-
puts "Tag #{version} already exists. Bump
|
12
|
+
puts "Tag #{version} already exists. Bump your version."
|
11
13
|
else
|
12
14
|
message = ENV["message"] || version
|
13
15
|
command = "git tag -am #{message} #{version}"
|
@@ -1,3 +1,32 @@
|
|
1
|
+
require "pp"
|
2
|
+
require "starter/string"
|
3
|
+
require "git"
|
4
|
+
|
5
|
+
$STARTER ||= {}
|
6
|
+
|
7
|
+
$STARTER[:directory] = File.basename(Dir.pwd)
|
8
|
+
|
9
|
+
desc "Bootstrap your project"
|
10
|
+
task "bootstrap"
|
11
|
+
|
12
|
+
desc "Build everything that needs building"
|
13
|
+
task "build"
|
14
|
+
|
15
|
+
desc "Release the dogs that shoot bees from their mouths"
|
16
|
+
task "release" => %w[ build ]
|
17
|
+
|
18
|
+
task "determine_author" => %w[ read_git_config ] do
|
19
|
+
if author = $STARTER[:git].config["user.name"]
|
20
|
+
$STARTER[:author] = author
|
21
|
+
else
|
22
|
+
$STARTER[:author] = prompt("Project author?")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
task "read_git_config" do
|
27
|
+
g = Git.open(Dir.pwd)
|
28
|
+
$STARTER[:git] = g
|
29
|
+
end
|
1
30
|
|
2
31
|
def confirm_command(command)
|
3
32
|
print "Issue command '#{command}' [y/N] "
|
@@ -10,3 +39,14 @@ def confirm_command(command)
|
|
10
39
|
end
|
11
40
|
end
|
12
41
|
|
42
|
+
def prompt(string)
|
43
|
+
print "#{string} "
|
44
|
+
value = STDIN.gets.chomp
|
45
|
+
if value.size > 1
|
46
|
+
return value
|
47
|
+
else
|
48
|
+
puts "No, I really need a value. Try again."
|
49
|
+
prompt(string)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
task "bootstrap" => %w[ README.md ]
|
3
|
+
|
4
|
+
file "README.md" do |target|
|
5
|
+
File.open(target.name, "w") do |file|
|
6
|
+
file.puts readme(
|
7
|
+
:project_name => $STARTER[:directory]
|
8
|
+
)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def readme(options)
|
14
|
+
project_name = options[:project_name]
|
15
|
+
text = <<-TXT
|
16
|
+
# #{Starter::String.camel_case(project_name)}
|
17
|
+
|
18
|
+
TXT
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
task "bootstrap" => %w[ package.json ]
|
4
|
+
|
5
|
+
file "package.json" => %w[ determine_author ] do |target|
|
6
|
+
string = package_template(options)
|
7
|
+
File.open(target.name, "w") do |file|
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def package_template(options={})
|
12
|
+
package = <<-TXT
|
13
|
+
TXT
|
14
|
+
end
|
15
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: starter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08
|
12
|
+
date: 2012-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -20,9 +20,13 @@ files:
|
|
20
20
|
- LICENSE
|
21
21
|
- Rakefile
|
22
22
|
- README.md
|
23
|
+
- lib/starter/string.rb
|
24
|
+
- lib/starter/tasks/bootstrap.rb
|
23
25
|
- lib/starter/tasks/gems.rb
|
24
26
|
- lib/starter/tasks/git.rb
|
25
27
|
- lib/starter/tasks/helpers.rb
|
28
|
+
- lib/starter/tasks/markdown.rb
|
29
|
+
- lib/starter/tasks/npm.rb
|
26
30
|
homepage: https://github.com/automatthew/starter
|
27
31
|
licenses: []
|
28
32
|
post_install_message:
|