-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
Rakefile
107 lines (81 loc) · 3.03 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
CONFIG = ENV['CONFIG'] || 'Debug'
COVERAGE_DIR = 'Coverage'
COVERAGE_FILE = File.join(COVERAGE_DIR, 'coverage.xml')
GITLINK_REMOTE = 'https://github.com/canton7/stylet'
NUSPEC = 'NuGet/Stylet.nuspec'
NUSPEC_START = 'NuGet/Stylet.start.nuspec'
ASSEMBLY_INFO = 'Stylet/Properties/AssemblyInfo.cs'
CSPROJ = 'Stylet/Stylet.csproj'
TEMPLATES_CSPROJ = 'StyletTemplates/StyletTemplates.csproj'
UNIT_TESTS = 'StyletUnitTests/StyletUnitTests.csproj'
TEMPLATES_DIR = 'StyletTemplates/templates'
directory COVERAGE_DIR
desc "Build the project using the current CONFIG (or Debug)"
task :build do
sh 'dotnet', 'build', '-c', CONFIG, CSPROJ
end
desc "Run unit tests using the current CONFIG (or Debug)"
task :test do
sh 'dotnet', 'test', '-c', CONFIG, UNIT_TESTS
end
desc "Create NuGet package"
task :package do
# Not sure why these have to be this way around, but they do
sh 'dotnet', 'pack', '--no-build', '-c', CONFIG, CSPROJ, "-p:NuSpecFile=../#{NUSPEC_START}"
sh 'dotnet', 'pack', '--no-build', '-c', CONFIG, CSPROJ, '-p:IncludeSymbols=true'
sh 'dotnet', 'pack', '-c', CONFIG, TEMPLATES_CSPROJ
end
desc "Bump version number"
task :version, [:version] do |t, args|
parts = args[:version].split('.')
parts << '0' if parts.length == 3
version = parts.join('.')
content = IO.read(CSPROJ)
content[/<VersionPrefix>(.+?)<\/VersionPrefix>/, 1] = version
File.open(CSPROJ, 'w'){ |f| f.write(content) }
content = IO.read(TEMPLATES_CSPROJ)
content[/<VersionPrefix>(.+?)<\/VersionPrefix>/, 1] = version
File.open(TEMPLATES_CSPROJ, 'w'){ |f| f.write(content) }
content = IO.read(NUSPEC_START)
content[/<version>(.+?)<\/version>/, 1] = args[:version]
content[%r{<dependency id="Stylet" version="\[(.+?)\]"/>}, 1] = args[:version]
File.open(NUSPEC_START, 'w'){ |f| f.write(content) }
Dir[File.join(TEMPLATES_DIR, '**/*.csproj')].each do |csproj|
content = IO.read(csproj)
content[/<PackageReference Include="Stylet" Version="(.+?)" \/>/, 1] = version
File.open(csproj, 'w'){ |f| f.write(content) }
end
end
desc "Extract StyletIoC as a standalone file"
task :"extract-stylet-ioc" do
filenames = Dir['Stylet/StyletIoC/**/*.cs']
usings = Set.new
files = []
filenames.each do |file|
contents = File.read(file)
file_usings = contents.scan(/using .*?;$/)
usings.merge(file_usings)
matches = contents.match(/namespace (.+?)\n{\n(.+)}.*/m)
namespace, file_contents = matches.captures
files << {
:from => file,
:contents => file_contents,
:namespace => namespace
}
# merged_contents << " // Originally from #{file}\n\n" << file_contents << "\n"
end
File.open('StyletIoC.cs', 'w') do |outf|
outf.write(usings.to_a.join("\n"))
outf.puts
files.group_by{ |x| x[:namespace ] }.each do |namespace, ns_files|
outf.puts("\nnamespace #{namespace}")
outf.puts("{")
ns_files.each do |file|
outf.puts("\n // Originally from #{file[:from]}\n\n")
outf.puts(file[:contents])
end
outf.puts("}\n")
end
end
# puts merged_contents
end