Skip to content
This repository has been archived by the owner on May 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #7 from petems/cardboardify_to_ruby
Browse files Browse the repository at this point in the history
Cardboardify to ruby
  • Loading branch information
fromonesrc committed Nov 5, 2013
2 parents 53ad767 + 35f1bed commit 3cee84e
Showing 1 changed file with 60 additions and 43 deletions.
103 changes: 60 additions & 43 deletions bin/cardboardify
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
#!/usr/bin/env bash

set -e
[ -n "$DEBUG" ] && set -x

usage() {
echo "Usage: cardboardify <path>"
echo ""
echo "Fresh Boxen modules!"
exit 1
}

install_template() {
curl -s -L https://github.com/boxen/puppet-template/archive/master.tar.gz | tar zx --strip-components 1

bundle install --binstubs .bundle/binstubs --path .bundle --quiet
.bundle/binstubs/rspec-puppet-init 2>&1 > /dev/null

rm Rakefile

rm -rf .git
git init .
}

if [ $# -ne 1 ]; then
usage
fi

path="$(pwd -P $1)/$1"

if [ ! -d "$path" ]; then
echo "$path does not exist!" >&2
exit 1
fi

pwd=$(pwd)

cd "$path"
install_template 2>&1 > /dev/null

echo "Cardboardified $path!"

cd "$pwd"
#!/usr/bin/env ruby

require 'fileutils'

def run(args)
if args[0].nil?
abort "cardboardify: Please specify the name of the module you wish to make"
elsif args.length > 1
abort "cardboardify: Too many arguments, one at a time please."
end

application_name = args[0]
module_name = "puppet-#{args[0]}"
if File.exists?(module_name)
warn "cardboardify: #{module_name}/ already exists"
return 1
elsif File.exists?(module_name.downcase)
warn "cardboardify: '#{module_name.downcase}' exists, which could conflict with `#{module_name}'"
return 1
else
puts "cardboardify: Creating '#{module_name}', this may take a few minutes"
FileUtils.mkdir_p(module_name)
get_boxen_template(module_name)
modify_template_files(module_name, application_name)
puts "cardboardify complete!"
return 0
end
end

def modify_template_files(module_name, application_name)
Dir.chdir(module_name) do
FileUtils.mv "spec/fixtures/modules/template/", "spec/fixtures/modules/#{application_name}/"
FileUtils.mv "spec/classes/template_spec.rb", "spec/classes/#{application_name}_spec.rb"
remove_template_references(application_name)
end
end

def get_boxen_template(target_dir)
Dir.chdir(target_dir) do
download = `curl -s -L https://github.com/boxen/puppet-template/archive/master.tar.gz | tar zx --strip-components 1`
setup_bundle = `bundle install --binstubs .bundle/binstubs --path .bundle --quiet`
remove_git = `rm -rf .git`
git_init = `git init .`
end
end

def remove_template_references(application_name)
files_to_fix = ["manifests/init.pp", "spec/classes/#{application_name}_spec.rb"]
files_to_fix.each do | file_to_fix |
replace = ""
File.open(file_to_fix) do |file|
file.lines.each do |line|
replace << line.gsub(/template/,"#{application_name}")
end
end
File.open(file_to_fix, "w") {|file| file.puts replace}
end
end

run(ARGV)

0 comments on commit 3cee84e

Please sign in to comment.