Skip to content

Commit

Permalink
adding support for node and bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
wbailey committed Jun 28, 2014
1 parent a615793 commit 1a55241
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
4 changes: 3 additions & 1 deletion bin/kata
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PRIMARY COMMANDS
--no-repo - Add the directory tree and files to the current repo if possible
--language=option - Define the programming language for the directory tree that is built
VALID OPTIONS [ruby,node,php]
file - Path to the code kata source file for the practice session
kata take file
Expand Down Expand Up @@ -48,7 +49,7 @@ OptionParser.new do |opts|
options.repo = false
end

opts.on('-l[OPTIONAL]', '--language[=OPTIONAL]', 'Setup the kata file tree using the specified language') do |lang|
opts.on('-l', '--language [LANG]', 'Setup the kata file tree using the specified language') do |lang|
options.language = lang
end
end.parse!
Expand All @@ -64,6 +65,7 @@ options.file = ARGV.shift
case options.action
when :setup
raise(ArgumentError, 'No kata source file specified') unless options.file && File.exists?(options.file)
raise(ArgumentError, 'Invalid language option') unless %w{ruby node php}.include?(options.language)

name = nil

Expand Down
32 changes: 20 additions & 12 deletions lib/kata/setup/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ def class_name
kata_name.split(/ |-|_/).map(&:capitalize).join
end

def write_repo_file(use_file, use_contents)
File.open(File.join(repo_name, use_file), 'w') {|f| f.write(use_contents)}
def write_repo_file(use_file, use_contents, permissions = 0644)
File.open(File.join(repo_name, use_file), 'w') do |f|
f.write(use_contents)
f.chmod(permissions) rescue Exception
end
end

def readme
Expand Down Expand Up @@ -113,27 +116,32 @@ def get_token
def create_remote_repo
client_factory

puts "Creating remote repo..."
client.create_repo "#{repo_name}"
puts "end"
begin
print "Creating remote repo..."
client.create_repo "#{repo_name}"
rescue Exception
puts "\nError: unable to create the git repo."
print 'Proceeding...'
ensure
puts "done"
end
end

def push_local_repo(new_repo)
print "creating files for repo and initializing..."

cmd = "cd #{repo_name} &&"

if new_repo
cmd << "git init >/dev/null 2>&1 &&"
cmd << "git add README .rspec lib/ spec/ >/dev/null 2>&1 &&"
cmd << "git init &&"
#cmd << "git add README .rspec lib/ spec/ &&"
cmd << "git add . &&"
else
cmd << "git add #{ENV['PWD']}/#{repo_name} >/dev/null 2>&1;"
cmd << "git add #{ENV['PWD']}/#{repo_name};"
end

cmd << "git commit -m 'starting kata' > /dev/null 2>&1;"
cmd << "git commit -m 'starting kata';"

if new_repo
cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git >/dev/null 2>&1 &&"
cmd << "git remote add origin git@github.com:#{github.user}/#{repo_name}.git &&"
end

cmd << 'git push origin master'
Expand Down
5 changes: 5 additions & 0 deletions lib/kata/setup/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def build_tree
%w{lib spec}.each { |path| tree(path) }
readme
package_json
autotest
kata_file
kata_spec
end
Expand Down Expand Up @@ -38,6 +39,10 @@ def package_json
EOF
end

def autotest
write_repo_file('autotest',"./node_modules/jasmine-node/bin/jasmine-node --autotest --color spec/", 0755)
end

def kata_file
# create the base class file
write_repo_file(File.join('lib', "#{use_kata_name}.js"),<<EOF)
Expand Down
18 changes: 13 additions & 5 deletions lib/kata/setup/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ def build_tree
%w{lib spec}.each { |path| tree(path) }
readme
bootstrap
gemfile
base_class
dot_rspec
dot_files
kata_spec
end

Expand Down Expand Up @@ -37,9 +38,13 @@ def gemfile
write_repo_file('Gemfile',<<EOF)
source 'http://rubygems.org'
gem 'kata'
group :test do
gem 'rspec'
gem 'autotest'
gem 'autotest-growl'
gem 'rspec-autotest'
end
group :development do
Expand All @@ -58,15 +63,18 @@ class #{class_name}
EOF
end

def dot_rspec
File.open(File.join(repo_name, '.rspec'), 'w') {|f| f.write <<EOF}
--color --format d
def dot_files
write_repo_file('.rspec', '--color --format d')
write_repo_file('.ruby-version', 'ruby-2.0.0-p481')
write_repo_file('.ruby-gemset', "kata-#{use_kata_name}")
write_repo_file('.autotest', <<EOF)
require 'autotest'
require 'autotest-growl'
EOF
end

def kata_spec
File.open(File.join(repo_name, 'spec', "#{use_kata_name}_spec.rb"), 'w') {|f| f.write <<EOF}
require 'spec_helper'
require '#{use_kata_name}'
describe #{class_name} do
Expand Down
2 changes: 1 addition & 1 deletion lib/kata/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Kata
VERSION = '1.5.1'
VERSION = '1.6.0'
end

0 comments on commit 1a55241

Please sign in to comment.