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

Commit 3cee84e

Browse files
committed
Merge pull request #7 from petems/cardboardify_to_ruby
Cardboardify to ruby
2 parents 53ad767 + 35f1bed commit 3cee84e

File tree

1 file changed

+60
-43
lines changed

1 file changed

+60
-43
lines changed

bin/cardboardify

Lines changed: 60 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,60 @@
1-
#!/usr/bin/env bash
2-
3-
set -e
4-
[ -n "$DEBUG" ] && set -x
5-
6-
usage() {
7-
echo "Usage: cardboardify <path>"
8-
echo ""
9-
echo "Fresh Boxen modules!"
10-
exit 1
11-
}
12-
13-
install_template() {
14-
curl -s -L https://github.com/boxen/puppet-template/archive/master.tar.gz | tar zx --strip-components 1
15-
16-
bundle install --binstubs .bundle/binstubs --path .bundle --quiet
17-
.bundle/binstubs/rspec-puppet-init 2>&1 > /dev/null
18-
19-
rm Rakefile
20-
21-
rm -rf .git
22-
git init .
23-
}
24-
25-
if [ $# -ne 1 ]; then
26-
usage
27-
fi
28-
29-
path="$(pwd -P $1)/$1"
30-
31-
if [ ! -d "$path" ]; then
32-
echo "$path does not exist!" >&2
33-
exit 1
34-
fi
35-
36-
pwd=$(pwd)
37-
38-
cd "$path"
39-
install_template 2>&1 > /dev/null
40-
41-
echo "Cardboardified $path!"
42-
43-
cd "$pwd"
1+
#!/usr/bin/env ruby
2+
3+
require 'fileutils'
4+
5+
def run(args)
6+
if args[0].nil?
7+
abort "cardboardify: Please specify the name of the module you wish to make"
8+
elsif args.length > 1
9+
abort "cardboardify: Too many arguments, one at a time please."
10+
end
11+
12+
application_name = args[0]
13+
module_name = "puppet-#{args[0]}"
14+
if File.exists?(module_name)
15+
warn "cardboardify: #{module_name}/ already exists"
16+
return 1
17+
elsif File.exists?(module_name.downcase)
18+
warn "cardboardify: '#{module_name.downcase}' exists, which could conflict with `#{module_name}'"
19+
return 1
20+
else
21+
puts "cardboardify: Creating '#{module_name}', this may take a few minutes"
22+
FileUtils.mkdir_p(module_name)
23+
get_boxen_template(module_name)
24+
modify_template_files(module_name, application_name)
25+
puts "cardboardify complete!"
26+
return 0
27+
end
28+
end
29+
30+
def modify_template_files(module_name, application_name)
31+
Dir.chdir(module_name) do
32+
FileUtils.mv "spec/fixtures/modules/template/", "spec/fixtures/modules/#{application_name}/"
33+
FileUtils.mv "spec/classes/template_spec.rb", "spec/classes/#{application_name}_spec.rb"
34+
remove_template_references(application_name)
35+
end
36+
end
37+
38+
def get_boxen_template(target_dir)
39+
Dir.chdir(target_dir) do
40+
download = `curl -s -L https://github.com/boxen/puppet-template/archive/master.tar.gz | tar zx --strip-components 1`
41+
setup_bundle = `bundle install --binstubs .bundle/binstubs --path .bundle --quiet`
42+
remove_git = `rm -rf .git`
43+
git_init = `git init .`
44+
end
45+
end
46+
47+
def remove_template_references(application_name)
48+
files_to_fix = ["manifests/init.pp", "spec/classes/#{application_name}_spec.rb"]
49+
files_to_fix.each do | file_to_fix |
50+
replace = ""
51+
File.open(file_to_fix) do |file|
52+
file.lines.each do |line|
53+
replace << line.gsub(/template/,"#{application_name}")
54+
end
55+
end
56+
File.open(file_to_fix, "w") {|file| file.puts replace}
57+
end
58+
end
59+
60+
run(ARGV)

0 commit comments

Comments
 (0)