minecraft-crafter 0.0.1.pre.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +41 -0
- data/Gemfile +6 -0
- data/LICENSE +674 -0
- data/README.md +27 -0
- data/Rakefile +10 -0
- data/bin/craft +87 -0
- data/lib/crafter.rb +7 -0
- data/lib/crafter/cli_helpers.rb +82 -0
- data/lib/crafter/dsl.rb +81 -0
- data/lib/crafter/version.rb +3 -0
- data/minecraft-crafter.gemspec +29 -0
- data/spec/cli_helpers_spec.rb +22 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/support/.keep +0 -0
- metadata +152 -0
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Crafter
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/minecraft-crafter)
|
4
|
+
[](https://rubygems.org/gems/minecraft-crafter)
|
5
|
+
[](https://rubygems.org/gems/minecraft-crafter)
|
6
|
+
[](https://rubygems.org/gems/minecraft-crafter)
|
7
|
+
|
8
|
+
[](https://travis-ci.org/HeisenBugDev/Crafter)
|
9
|
+
[](http://inch-ci.org/github/HeisenBugDev/Crafter)
|
10
|
+
[](https://codeclimate.com/github/HeisenBugDev/Crafter)
|
11
|
+
[](https://codeclimate.com/github/HeisenBugDev/Crafter)
|
12
|
+
[](https://www.pullreview.com/github/HeisenBugDev/Crafter/reviews/master)
|
13
|
+
|
14
|
+
|
15
|
+
Bundler and homebrew inspired Minecraft launcher.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
No installation yet. It's not ready.
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it ( https://github.com/HeisenBugDev/Crafter/fork )
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/craft
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
require 'colorize'
|
5
|
+
require 'crafter'
|
6
|
+
|
7
|
+
def message(meth, message, color: [], arrow_color: nil)
|
8
|
+
message = [message].flatten.join("\n ")
|
9
|
+
message << "\n >" if meth == :ask
|
10
|
+
say('==> ', arrow_color || :blue)
|
11
|
+
send(meth, message, *([color].flatten + [:bold]))
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_message(message)
|
15
|
+
message(:say, message, arrow_color: :red, color: :red)
|
16
|
+
end
|
17
|
+
|
18
|
+
# TFOSS v1
|
19
|
+
# GITHUB Homebrew/Homebrew
|
20
|
+
# SHA 4ab83434b6776056dc2a063b6c48ce499000f4f8
|
21
|
+
# PATH /Library/Homebrew/utils.rb
|
22
|
+
# LINES 162-181
|
23
|
+
def puts_columns(items, star_items=[], indent=4)
|
24
|
+
return if items.empty?
|
25
|
+
|
26
|
+
if star_items && star_items.any?
|
27
|
+
items = items.map{|item| star_items.include?(item) ? "#{item}*" : item}
|
28
|
+
end
|
29
|
+
|
30
|
+
if $stdout.tty?
|
31
|
+
# determine the best width to display for different console sizes
|
32
|
+
console_width = `/bin/stty size`.chomp.split(" ").last.to_i - indent
|
33
|
+
console_width = 80 - indent if console_width <= 0
|
34
|
+
longest = items.sort_by { |item| item.length }.last
|
35
|
+
optimal_col_width = (console_width.to_f / (longest.length + 2).to_f).floor
|
36
|
+
cols = optimal_col_width > 1 ? optimal_col_width : 1
|
37
|
+
|
38
|
+
IO.popen("/usr/bin/pr -#{cols} -t -w#{console_width} -o#{indent}", "w"){|io| io.puts(items) }
|
39
|
+
else
|
40
|
+
puts items
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Craft < Thor
|
45
|
+
prepend Crafter::CLIHelpers
|
46
|
+
|
47
|
+
desc 'create NAME', 'Creates a new Crafter instance.'
|
48
|
+
def create(name)
|
49
|
+
@type = ask('Client or Server?', valid: ['client', 'server'])
|
50
|
+
@minecraft = ask('Please specify Minecraft version')
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'clone', 'Clones a Crafter instance.'
|
54
|
+
def clone(*options)
|
55
|
+
if options[0] && options[1]
|
56
|
+
# 0 is source name. 1 is clone name
|
57
|
+
# from_to_message = "(§#{options[0].underline}§ -> §#{options[1].underline}§)"
|
58
|
+
from_to = from_to_message(options[0], options[1])
|
59
|
+
say("Clone instance #{from_to}")
|
60
|
+
say("Cloning instance...")
|
61
|
+
say("Instance cloned #{from_to}")
|
62
|
+
elsif options[0]
|
63
|
+
# Clone from gist sha, gist url, url, file, or instance
|
64
|
+
say("Unpacking...")
|
65
|
+
@name = ask(["Source specifies instance name: §#{@original_name.underline}§",
|
66
|
+
"Enter a new name or leave blank, then press enter"])
|
67
|
+
@name = @original_name if @name.empty?
|
68
|
+
from_to = from_to_message(@original_name, @name, source: @downloaded)
|
69
|
+
say('Cloning instance...')
|
70
|
+
say("Instance cloned #{from_to}")
|
71
|
+
else
|
72
|
+
# Walk through clone
|
73
|
+
@name = message(:ask, 'Please enter an instance name, gist id, or path to archive')
|
74
|
+
message(:say, "Instance Selected: \"#{@original_name}\"")
|
75
|
+
message(:say, "MC #{@minecraft}") # Also show forge version and stuff
|
76
|
+
message(:say, "Mods:")
|
77
|
+
|
78
|
+
puts_columns(@mods)
|
79
|
+
@new_name = message(:ask, 'Please enter a name for the clone')
|
80
|
+
message(:say, 'Cloning Instance...')
|
81
|
+
message(:say, "Instance cloned (\"#{@original_name}\" -> \"#{@new_name}\")")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
Craft.start
|
data/lib/crafter.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
3
|
+
module Crafter
|
4
|
+
module CLIHelpers
|
5
|
+
#
|
6
|
+
# Say something! Use § characters around parts of text you have colorized
|
7
|
+
# @param *args [String] Arguments to pass to #low_say
|
8
|
+
# @param bold: true [Boolean] Enable or disable auto-bolding
|
9
|
+
# @param force_new_line: false [Boolean] Force new line?
|
10
|
+
def say(*args, superify: false, bold: true, force_new_line: false)
|
11
|
+
return super *args if superify
|
12
|
+
arrow(colors: :blue)
|
13
|
+
low_say(*args, bold: bold, force_new_line: force_new_line)
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# Asks for information from the user.
|
18
|
+
# @param message [String] Message to provide.
|
19
|
+
# @param valid: [] [Array<String>] Valid options.
|
20
|
+
# An empty array will be ignored.
|
21
|
+
#
|
22
|
+
# @return [String] User response.
|
23
|
+
def ask(message, valid: [], bold: true, force_new_line: false)
|
24
|
+
return loop_valid(message, valid) unless valid.empty?
|
25
|
+
stringify_message!(message); arrow(colors: :blue)
|
26
|
+
message << "\n > "
|
27
|
+
low_say(message, bold: bold, force_new_line: force_new_line)
|
28
|
+
STDIN.gets
|
29
|
+
end
|
30
|
+
|
31
|
+
def say_error(message)
|
32
|
+
arrow(colors: :red)
|
33
|
+
low_say(message, colors: :red)
|
34
|
+
end
|
35
|
+
|
36
|
+
def from_to_message(from, to, source: '')
|
37
|
+
"(§#{(source.dup << ' ').colorize(:default) unless source.empty?}§"\
|
38
|
+
"§#{from.underline}§ -> §#{to.underline}§)"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def loop_valid(message, valid)
|
44
|
+
valid.map!(&:to_s)
|
45
|
+
loop do
|
46
|
+
response = ask("#{message} #{valid.to_s.delete('"')}")
|
47
|
+
return response if valid.include? response.downcase.strip
|
48
|
+
say_error('Invalid choice')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Adds argument to array if it is truthy
|
53
|
+
def conditional_arg!(args_array, arg)
|
54
|
+
args_array << arg if arg
|
55
|
+
end
|
56
|
+
|
57
|
+
def low_say(message, colors: [], bold: true, force_new_line: nil)
|
58
|
+
stringify_message!(message)
|
59
|
+
message = generate_bold_text(message) if bold
|
60
|
+
conditional_arg!(args = [], force_new_line)
|
61
|
+
say(message, colors, *args, superify: true)
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_bold_text(text)
|
65
|
+
if text.scan('§').length % 2 == 1
|
66
|
+
raise "There must be an even number of §'s in the message: #{text}"
|
67
|
+
end
|
68
|
+
|
69
|
+
text.split('§').map do |string|
|
70
|
+
string.colorized? ? string : string.bold
|
71
|
+
end.join
|
72
|
+
end
|
73
|
+
|
74
|
+
def arrow(colors: [])
|
75
|
+
low_say('==> ', bold: false, colors: colors)
|
76
|
+
end
|
77
|
+
|
78
|
+
def stringify_message!(message)
|
79
|
+
message = [message].flatten.join("\n ")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/crafter/dsl.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
module Crafter
|
2
|
+
|
3
|
+
class CraftfileError < RuntimeError; end
|
4
|
+
class DSL
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
def eval_craftfile(craftfile, contents = nil)
|
11
|
+
contents ||= File.open(craftfile, 'rb') do |file|
|
12
|
+
file.read
|
13
|
+
end
|
14
|
+
instance_eval(contents, craftfile.to_s, 1)
|
15
|
+
rescue SyntaxError => error
|
16
|
+
message = error.message.split('\n')[1..-1]
|
17
|
+
raise CraftfileError, ['Craftfile syntax error:' *message].join('\n')
|
18
|
+
rescue ScriptError, RegexpError, NameError, ArgumentError => error
|
19
|
+
error.backtrace[0] = "#{error.backtrace[0]}: #{error.message} (#{error.class})"
|
20
|
+
SRDERR.puts error.backtrace.join('\n ')
|
21
|
+
raise CraftfileError, 'There was an error in your Craftfile, and Crafter cannot continue.'
|
22
|
+
end
|
23
|
+
|
24
|
+
def minecraft(version)
|
25
|
+
@minecraft = version
|
26
|
+
end
|
27
|
+
|
28
|
+
def type(executable = 'universal')
|
29
|
+
@type = executable
|
30
|
+
end
|
31
|
+
|
32
|
+
def forge(version)
|
33
|
+
@forge = version
|
34
|
+
end
|
35
|
+
|
36
|
+
def canary(version)
|
37
|
+
@canary = version
|
38
|
+
end
|
39
|
+
|
40
|
+
# Bukkit Replacement Binary, with it being legally impossible to get Bukkit binaries anymore.
|
41
|
+
def glowstone(version)
|
42
|
+
@glowstone = version
|
43
|
+
end
|
44
|
+
|
45
|
+
# No Promises here. Might be cool one day.
|
46
|
+
def minecraftruby(version)
|
47
|
+
@minecraftruby = version
|
48
|
+
end
|
49
|
+
|
50
|
+
# Only applicable to Minecraft > 1.8
|
51
|
+
def sponge(version)
|
52
|
+
@sponge = version
|
53
|
+
end
|
54
|
+
|
55
|
+
# Only applicable to Minecraft < 1.6.4, I think...
|
56
|
+
def spout(version)
|
57
|
+
@spout = version
|
58
|
+
end
|
59
|
+
|
60
|
+
# Old Server Mod...
|
61
|
+
def hmod(version)
|
62
|
+
@hmod = version
|
63
|
+
end
|
64
|
+
|
65
|
+
def source(location, options = {})
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def mod(name, *args)
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def resource_pack(name, options = {})
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
alias_method :rp, :resource_pack
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'crafter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'minecraft-crafter'
|
8
|
+
spec.version = Crafter::VERSION
|
9
|
+
spec.version = "#{spec.version}-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
|
10
|
+
spec.authors = ['Kepler Sticka-Jones', 'Theron Boerner']
|
11
|
+
spec.email = ['kbsj269@gmail.com', 'hunterboerner@gmail.com']
|
12
|
+
spec.summary = 'Crafter gets you from code to craft'
|
13
|
+
spec.description = ''
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'GNU Public License Version 3'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
28
|
+
spec.add_runtime_dependency 'colorize'
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Crafter::CLIHelpers do
|
2
|
+
before do
|
3
|
+
@dummy_class = Class.new()
|
4
|
+
@dummy_class.extend(Crafter::CLIHelpers)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "#from_to_message" do
|
8
|
+
it "should give me a from to message" do
|
9
|
+
expect(@dummy_class.from_to_message('This mod pack',
|
10
|
+
'another mod pack')).
|
11
|
+
to eql("(§§§\e[4;39;49mThis mod pack\e[0m§ ->"\
|
12
|
+
" §\e[4;39;49manother mod pack\e[0m§)")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should give me a from to message with source" do
|
16
|
+
expect(@dummy_class.from_to_message('This mod pack',
|
17
|
+
'another mod pack', source: 'somefile.zip')).
|
18
|
+
to eql("(§\e[0;39;49msomefile.zip \e[0m§§\e[4;39;49mThis mod pack\e[0m§"\
|
19
|
+
" -> §\e[4;39;49manother mod pack\e[0m§)")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'codeclimate-test-reporter'
|
2
|
+
CodeClimate::TestReporter.start
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'crafter'
|
6
|
+
Bundler.setup
|
7
|
+
|
8
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
9
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
10
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
11
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
12
|
+
#
|
13
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
14
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
15
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
16
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
17
|
+
# a separate helper file that requires the additional dependencies and performs
|
18
|
+
# the additional setup, and require it from the spec files that actually need it.
|
19
|
+
#
|
20
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
21
|
+
# users commonly want.
|
22
|
+
#
|
23
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
24
|
+
|
25
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
26
|
+
# in spec/support/ and its subdirectories.
|
27
|
+
Dir['support/**/*.rb'].each { |f| require f }
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
# rspec-expectations config goes here. You can use an alternate
|
31
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
32
|
+
# assertions if you prefer.
|
33
|
+
config.expect_with :rspec do |expectations|
|
34
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
35
|
+
# and `failure_message` of custom matchers include text for helper methods
|
36
|
+
# defined using `chain`, e.g.:
|
37
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
38
|
+
# # => "be bigger than 2 and smaller than 4"
|
39
|
+
# ...rather than:
|
40
|
+
# # => "be bigger than 2"
|
41
|
+
#expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
42
|
+
end
|
43
|
+
|
44
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
45
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
46
|
+
config.mock_with :rspec do |mocks|
|
47
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
48
|
+
# a real object. This is generally recommended, and will default to
|
49
|
+
# `true` in RSpec 4.
|
50
|
+
mocks.verify_partial_doubles = true
|
51
|
+
end
|
52
|
+
|
53
|
+
# The settings below are suggested to provide a good initial experience
|
54
|
+
# with RSpec, but feel free to customize to your heart's content.
|
55
|
+
|
56
|
+
# These two settings work together to allow you to limit a spec run
|
57
|
+
# to individual examples or groups you care about by tagging them with
|
58
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
59
|
+
# get run.
|
60
|
+
config.filter_run :focus
|
61
|
+
config.run_all_when_everything_filtered = true
|
62
|
+
|
63
|
+
# Monkey patch :) #monkeypatchthedescribe
|
64
|
+
#
|
65
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
66
|
+
# For more details, see:
|
67
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
68
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
69
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
70
|
+
# config.disable_monkey_patching!
|
71
|
+
|
72
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
73
|
+
# be too noisy due to issues in dependencies.
|
74
|
+
config.warnings = true
|
75
|
+
|
76
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
77
|
+
# file, and it's useful to allow more verbose output when running an
|
78
|
+
# individual spec file.
|
79
|
+
if config.files_to_run.one?
|
80
|
+
# Use the documentation formatter for detailed output,
|
81
|
+
# unless a formatter has already been configured
|
82
|
+
# (e.g. via a command-line flag).
|
83
|
+
config.default_formatter = 'doc'
|
84
|
+
end
|
85
|
+
|
86
|
+
# Print the 10 slowest examples and example groups at the
|
87
|
+
# end of the spec run, to help surface which specs are running
|
88
|
+
# particularly slow.
|
89
|
+
config.profile_examples = 10
|
90
|
+
|
91
|
+
# Run specs in random order to surface order dependencies. If you find an
|
92
|
+
# order dependency and want to debug it, you can fix the order by providing
|
93
|
+
# the seed, which is printed after each run.
|
94
|
+
# --seed 1234
|
95
|
+
config.order = :random
|
96
|
+
|
97
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
98
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
99
|
+
# test failures related to randomization by passing the same `--seed` value
|
100
|
+
# as the one that triggered the failure.
|
101
|
+
Kernel.srand config.seed
|
102
|
+
|
103
|
+
end
|