-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rakefile
125 lines (107 loc) · 3.56 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require 'rake/clean'
require 'rubygems'
require 'json'
require 'redcarpet'
require 'pathname'
plugin_name = "Card Fighters' Clash"
plugin_dir = "o8g"
plugin_id = "e3d56d9e-900d-49c6-b6ae-22cbb51be153"
# Get the path to OCTGN data from OCTGN config
OCTGN_dir = File.join(ENV["USERPROFILE"], "AppData", "Local", "Programs", "OCTGN")
OCTGN_data_path = File.open(File.join(OCTGN_dir, "data.path"))
OCTGN_data_dir = Pathname.new(OCTGN_data_path.read().split('\\').join('/'))
# Setup clean task
CLOBBER.include [
"#{plugin_dir}/*.o8g", OCTGN_data_dir + "LocalFeed/#{plugin_name}*.nupkg",
"#{plugin_dir}/Scripts/**/*.pyc"
]
# Rock'n roll
start_time = Time.now
task :default => [:build]
desc "Builds a .o8g and a .nupkg file from the game definition files"
task :build => [:versionbump] do
sh "o8build.exe -d=#{plugin_dir}"
end
desc "Increases the build number by 1"
task :versionbump do
filename = "#{plugin_dir}/definition.xml"
file = File.open(filename, 'r')
str = ''
m = nil
regexp = /version="(\d+)\.(\d+)\.(\d+)\.(\d+)"/
file.each_line do |line|
if m.nil?
m = line.match(regexp)
if m
buildnum = m[4].to_i + 1
puts "Bumping build number to #{buildnum} (#{m[1]}.#{m[2]}.#{m[3]}.#{buildnum})\n\r"
line.sub!('.'+m[4]+'"', '.'+buildnum.to_s+'"')
end
end
str += line
end
file.close
File.open(filename, 'w') do |out|
out << str
end
end
desc "Builds and moves the NUPKG file to the OCTGN LocalFeed dir"
task :deploy => [:clobber, :build] do
mv Dir.glob("#{plugin_dir}/*.nupkg"), "#{OCTGN_data_dir}/LocalFeed/"
# Rake::Task["octgn"].execute
end_time = Time.now
puts "\nTask completed at " + Time.now.strftime("%d-%m-%Y %H:%M")
puts "Time elapsed: #{(end_time - start_time)*1000} milliseconds"
end
desc "Copies python files to the game's script folder under OCTGN's games database folder"
task :copy => [:test] do
cp_r "#{plugin_dir}/Scripts/.", "#{OCTGN_data_dir}/GameDatabase/#{plugin_id}/Scripts/"
puts "\nTask completed at " + Time.now.strftime("%d-%m-%Y %H:%M")
end
desc "Verifies the files as a valid game definition"
task :test do
sh "o8build.exe -v -d=#{plugin_dir}"
end
desc "Runs OCTGN in dev mode, in the table view with the CFC game loaded"
task :octgn do
# OCTGN window closes after the loading screen ends ¯\_(ツ)_/¯
# system "OCTGN.exe /t /g=#{plugin_id} /x"
puts "Run OCTGN.exe /t /g=#{plugin_id} /x"
end
desc "Converts Markdown documents in the Documents/ folder into HTML files"
task :docs do
puts "Converting Markdown files into HTML..."
# Initializes a Markdown parser
renderer = Redcarpet::Render::HTML.new({:with_toc_data=>true, :hard_wrap=>true, :tables => true})
# Initializes a Markdown HTML renderer
markdown = Redcarpet::Markdown.new(renderer, {:autolink=>true, :underline=>true, :tables => true, :strikethrough => true})
toc_md = Redcarpet::Markdown.new(Redcarpet::Render::HTML_TOC.new)
Dir.glob("#{plugin_dir}/Documents/*.md") do |md_file|
puts " " + md_file
base_name = File.basename(md_file, ".md")
html_file = File.join(File.dirname(md_file), base_name + ".html")
File.open(html_file, 'w') { |f|
file_contents = File.read(md_file)
doc = markdown.render(file_contents)
toc_idx = file_contents.index('<!-- toc -->')
if toc_idx
toc = toc_md.render(file_contents[toc_idx..-1])
doc.sub!('<!-- toc -->', toc)
end
f.puts <<EOD
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>#{base_name}</title>
<link href="doc.css" rel="stylesheet">
</head>
<body>
#{doc}
</body>
</html>
EOD
}
end
puts ""
end