forked from bcdice/bcdice-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
106 lines (81 loc) · 2.12 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# frozen_string_literal: true
require 'rake'
require 'json'
require './scripts/builder.rb'
$srcDir = 'src'
$bcdiceDir = 'BCDice/src'
$patchesDir = 'patches'
$patchedDir = 'patched'
$outputDir = 'lib'
$LOAD_PATH.unshift("./#{$bcdiceDir}")
def getGameTypes
Dir
.glob("#{$patchedDir}/diceBot/*.rb")
.map { |file| file.match(%r{([^/]+)\.rb$}) }
.select { |m| m }
.map { |m| m[1] }
.reject { |gameType| gameType.match(/^(_.*|DiceBotLoader(List)?|test)$/) }
end
task default: :build
task :copy do
FileUtils.mkdir_p($patchedDir)
sh "cp -r #{$bcdiceDir}/* #{$patchedDir}"
end
task patch: [:copy] do
sh 'patch -p2 < ../patch.diff', { chdir: $patchedDir }, {}
end
task build: %i[
extract_info_list
build_opal
build_core
build_dicebot
] do
end
task extract_info_list: [:patch] do
require("./#{$bcdiceDir}/diceBot/DiceBot")
print 'extracting DiceBot '
infoList = getGameTypes.map do |gameType|
require("./#{$bcdiceDir}/diceBot/#{gameType}.rb")
diceBot = Object.const_get(gameType).new
print '.'
{
gameType: gameType,
gameName: diceBot.name,
sortKey: diceBot.sort_key,
prefixes: diceBot.prefixes.flatten,
info: diceBot.help_message
}
end
print "\n"
infoList.sort_by! { |info| info[:sortKey] }
json = JSON.pretty_generate(
infoList: infoList
)
FileUtils.mkdir_p($outputDir)
File.write("#{$outputDir}/diceBot.json", json)
end
task :build_opal do
puts 'building opal'
builder = Builder.new
builder.build('opal')
builder.build("./#{$srcDir}/rubyfix.rb")
builder.write("#{$outputDir}/opal.js")
end
task build_core: [:patch] do
puts 'building cgiDiceBot'
builder = Builder.new
builder.build("./#{$patchedDir}/cgiDiceBot.rb")
builder.build("./#{$srcDir}/DiceBotLoader.rb")
builder.build("./#{$srcDir}/Logger.rb")
builder.write("#{$outputDir}/cgiDiceBot.js")
end
task build_dicebot: [:patch] do
print 'building DiceBot '
getGameTypes.each do |gameType|
builder = Builder.new
builder.build("./#{$patchedDir}/diceBot/#{gameType}.rb")
builder.write("#{$outputDir}/diceBot/#{gameType}.js")
print '.'
end
print "\n"
end