Skip to content

Commit 05e6268

Browse files
committed
better sunniesnow integration
use optparse for better cli ux more command line options for 'sscharter serve' support init in existing dir bump version bump dependencies update tutorial
1 parent d0bbf8d commit 05e6268

File tree

9 files changed

+268
-175
lines changed

9 files changed

+268
-175
lines changed

Gemfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ source "https://rubygems.org"
66
gemspec
77

88
group :develop do
9-
gem "rake", "~> 13.0"
10-
gem "minitest", "~> 5.0"
9+
gem 'rake', '~> 13.0'
10+
gem 'minitest', '~> 5.0'
1111
end
1212

1313
gem 'rubyzip', '~> 2.3'
1414
gem 'launchy', '~> 2.5'
1515
gem 'webrick', '~> 1.8'
1616
gem 'filewatcher', '~> 2.0'
17+
gem 'em-websocket', '~> 0.5'

Gemfile.lock

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
PATH
22
remote: .
33
specs:
4-
sscharter (0.5.4)
4+
sscharter (0.6.0)
5+
em-websocket (~> 0.5)
56
filewatcher (~> 2.0)
67
launchy (~> 2.5)
78
rubyzip (~> 2.3)
@@ -10,23 +11,29 @@ PATH
1011
GEM
1112
remote: https://rubygems.org/
1213
specs:
13-
addressable (2.8.6)
14-
public_suffix (>= 2.0.2, < 6.0)
14+
addressable (2.8.7)
15+
public_suffix (>= 2.0.2, < 7.0)
16+
em-websocket (0.5.3)
17+
eventmachine (>= 0.12.9)
18+
http_parser.rb (~> 0)
19+
eventmachine (1.2.7)
1520
filewatcher (2.1.0)
1621
module_methods (~> 0.1.0)
22+
http_parser.rb (0.8.0)
1723
launchy (2.5.2)
1824
addressable (~> 2.8)
19-
minitest (5.22.3)
25+
minitest (5.24.1)
2026
module_methods (0.1.0)
21-
public_suffix (5.0.4)
22-
rake (13.1.0)
27+
public_suffix (6.0.1)
28+
rake (13.2.1)
2329
rubyzip (2.3.2)
2430
webrick (1.8.1)
2531

2632
PLATFORMS
2733
x86_64-linux
2834

2935
DEPENDENCIES
36+
em-websocket (~> 0.5)
3037
filewatcher (~> 2.0)
3138
launchy (~> 2.5)
3239
minitest (~> 5.0)
@@ -36,4 +43,4 @@ DEPENDENCIES
3643
webrick (~> 1.8)
3744

3845
BUNDLED WITH
39-
2.5.4
46+
2.5.16

exe/sscharter

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
require 'sscharter'
55
require 'sscharter/cli'
66

7-
command = ARGV.shift&.to_sym
8-
unless Sunniesnow::Charter::CLI::COMMANDS.include? command
9-
$stderr.puts "Usage: #{File.basename $0} <#{Sunniesnow::Charter::CLI::COMMANDS.join '|'}>"
7+
unless subcommand = Sunniesnow::Charter::CLI.commands[ARGV.shift&.to_sym]
8+
$stderr.puts "Usage: #{File.basename $0} <#{Sunniesnow::Charter::CLI.commands.keys.join '|'}>"
109
exit 1
1110
end
1211

13-
exit Sunniesnow::Charter::CLI.send(command, *ARGV) || 0
12+
exit subcommand.run || 0

lib/sscharter.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ def big_text duration_beats = 0, text
634634
end
635635
end
636636

637-
def to_sunniesnow
638-
result = Sunniesnow::Chart.new
637+
def to_sunniesnow **opts
638+
result = Sunniesnow::Chart.new **opts
639639
result.title = @title
640640
result.artist = @artist
641641
result.charter = @charter
@@ -647,8 +647,8 @@ def to_sunniesnow
647647
result
648648
end
649649

650-
def output_json
651-
to_sunniesnow.to_json
650+
def output_json **opts
651+
to_sunniesnow(**opts).to_json
652652
end
653653

654654
def inspect

lib/sscharter/chart.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Sunniesnow::Chart
1010
attr_accessor :difficulty_name, :difficulty_color, :difficulty, :difficulty_sup
1111
attr_reader :events
1212

13-
def initialize
13+
def initialize live_reload_port: 31108, production: false, live_restart: false
1414
@title = ''
1515
@artist = ''
1616
@charter = ''
@@ -19,10 +19,13 @@ def initialize
1919
@difficulty = ''
2020
@difficulty_sup = ''
2121
@events = []
22+
@live_reload_port = live_reload_port
23+
@production = production
24+
@live_restart = live_restart
2225
end
2326

2427
def to_json *args
25-
{
28+
hash = {
2629
title: @title,
2730
artist: @artist,
2831
charter: @charter,
@@ -31,7 +34,13 @@ def to_json *args
3134
difficulty: @difficulty,
3235
difficultySup: @difficulty_sup,
3336
events: @events
34-
}.to_json
37+
}
38+
hash[:sscharter] = {
39+
version: Sunniesnow::Charter::VERSION,
40+
port: @live_reload_port,
41+
liveRestart: @live_restart
42+
} unless @production
43+
hash.to_json
3544
end
3645
end
3746

0 commit comments

Comments
 (0)