Skip to content

Instantly share code, notes, and snippets.

@NxSoftware
Last active January 2, 2017 16:16
Show Gist options
  • Save NxSoftware/cde202c5125ec875985f54f77458e7b1 to your computer and use it in GitHub Desktop.
Save NxSoftware/cde202c5125ec875985f54f77458e7b1 to your computer and use it in GitHub Desktop.
Generates a Swift package for writing katas and guard for running tests
#!/usr/bin/ruby
kata_name = ARGV[0]
if kata_name == nil then
puts "You must provide a Kata name."
exit
end
LICENSEFILE = %Q{MIT License
Copyright (c) 2016 NxSoftware
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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.
}
GEMFILE = %Q{source "https://rubygems.org"
gem "colored"
gem "guard-shell"
}
GUARDFILE = %Q{require 'colored'
clearing :on
guard :shell do
watch(/(.*).swift$/) do |m|
puts "Modified \#{m[0]}"
output = ""
errors = ""
exit_status = Open3.popen3("swift test") do |stdin, stdout, strerr, wait_thr|
stdin.close
output << stdout.read
errors << strerr.read
wait_thr.value
end
puts output.yellow
if exit_status.success? then
puts errors.cyan
puts "Passed".green
else
puts errors.red
puts "Failed".white_on_red.to_eol
end
end
end
}
`mkdir #{kata_name}`
`swift package init -C #{kata_name}`
`git init #{kata_name}`
def write(content, file)
File.open(file, 'w') do |f|
f.write(content)
end
end
write(GEMFILE, "#{kata_name}/Gemfile")
write(GUARDFILE, "#{kata_name}/Guardfile")
write(LICENSEFILE, "#{kata_name}/LICENSE")
@NxSoftware
Copy link
Author

NSScreencast episode 246 inspired this script.

http://nsscreencast.com/episodes/246-improved-guard-setup-for-swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment