-
Notifications
You must be signed in to change notification settings - Fork 22
/
Sakefile.shade
105 lines (86 loc) · 4.8 KB
/
Sakefile.shade
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
var PROJECT='OWIN Hosting Components'
var VERSION='0.9.9'
var FULL_VERSION='${VERSION}'
var AUTHORS='Microsoft Open Technologies, Inc.'
var BASE_DIR='${Directory.GetCurrentDirectory()}'
var TARGET_DIR='${Path.Combine(BASE_DIR, "target")}'
var BUILD_DIR='${Path.Combine(TARGET_DIR, "build")}'
var TEST_DIR='${Path.Combine(TARGET_DIR, "test")}'
var NUGET_DEPLOY='http://www.myget.org/F/owin/'
var BUILD_PROJECTS='${Files.Include("src/main/**/*.csproj")}'
-// include range of standard general targets. run "sake targets" to display
use-standard-lifecycle
-// include sets of standard work targets. features include 'nuget,xunit,nunit'
use-standard-goals features='nuget,xunit,stylecop'
-// additional work targets are defined below
#release
@{
// To publish, call `build release deploy`
NUGET_DEPLOY = '';
FULL_VERSION = VERSION;
}
-// override nuget-package to pin OWIN to 1.0
#nuget-package target='package' description='Create NuGet packages'
for each='var file in Files.Include("target/build/**/*.nuspec")'
var baseName='${Path.GetFileNameWithoutExtension(file)}'
var packageVersion='${FULL_VERSION}'
set packageVersion='1.0' if='file.EndsWith("Owin.nuspec")'
nuget-pack nuspecFile='${file}' outputDir='${TARGET_DIR}' extra='-NoPackageAnalysis -Properties "id=${baseName};authors=${AUTHORS}"'
#nuget-deploy target='deploy' description='Upload NuGet packages to gallery'
var extra=''
set extra='${extra} -Source ${NUGET_DEPLOY}' if='!string.IsNullOrEmpty(NUGET_DEPLOY)'
nuget-push each='var nupkgFile in Files.Include("target/*.nupkg").Exclude("target/Owin.1.0.nupkg")'
#sources-package-prepare target='package-prepare'
for each='var file in Files.Include("src/**/*.Sources.nuspec")'
var projectDir='${Path.GetDirectoryName(file)}'
var projectName='${Path.GetFileName(projectDir)}'
copy sourceDir='${projectDir}' include='**/*.cs' exclude='**/App_Packages/**/*' outputDir='${BUILD_DIR}\${projectName}' overwrite='${true}'
copy sourceDir='${projectDir}' include='**/*.resx' exclude='**/App_Packages/**/*' outputDir='${BUILD_DIR}\${projectName}' overwrite='${true}'
copy sourceDir='.' include='LICENSE.txt' outputDir='${BUILD_DIR}\${projectName}' overwrite='${true}'
copy sourceDir='.' include='NOTICE.txt' outputDir='${BUILD_DIR}\${projectName}' overwrite='${true}'
var deleteFiles='${new[]{
BUILD_DIR + "/" + projectName + "/**/AssemblyInfo.cs",
BUILD_DIR + "/" + projectName + "/**/Temporary*.cs"
}}'
for each='var deleteFile in Files.Include(deleteFiles)' -File.Delete(deleteFile);
var files='${new Dictionary<string,IList<FileGrammar.Hunk>>()}'
use import='FileGrammar'
update-file each='var updateFile in Files.Include(BUILD_DIR + "/" + projectName + "/**/*.cs")'
@{
updateText = updateText
.Replace("public static partial class", "internal static partial class")
.Replace("public static class", "internal static class")
.Replace("public class", "internal class")
.Replace("public struct", "internal struct")
.Replace("public partial struct", "internal partial struct")
.Replace("public enum", "internal enum")
.Replace("public delegate", "internal delegate")
.Replace("public interface", "internal interface")
.Replace("// Sources:", "")
.Replace(" /// ", " // ");
var hunks = new FileGrammar().Hunks(new Position(new SourceContext(updateText, 0, updateFile)));
files.Add(updateFile, hunks.Value);
}
var groups="${files.GroupBy(kv => Path.GetDirectoryName(kv.Key) + '\\' + Path.GetFileName(kv.Key).Split((char)'.').First())}"
for each="var group in groups"
test if='group.Count() == 1'
log info='Skipping single file group ${group.Key}'
else
log info='Output group ${group.Key} has ${group.Count()} parts'
var allHunks='${group.SelectMany(kv=>kv.Value)}'
var allNamespaces='${allHunks.Where(x=>x.Type=="using").Select(x=>x.Namespace).Distinct().OrderBy(x=>(x.Contains("=")?"1":"0")+ x)}'
var allCode='${allHunks.Where(x=>x.Type=="namespace")}'
content var='newCode'
copyright filename='${group.Key.Split((char)'\\',(char)'/').Last() + ".cs"}' company='${AUTHORS}'
for each='var ns in allNamespaces' line|using !{ns};
line|
line|namespace !{allCode.First().Namespace.Trim()}
line|{
for each='var code in allCode'
line|#region !{Path.GetFileNameWithoutExtension(code.Position.SourceContext.FileName)}
|!{code.Code}
line|#endregion
line|
line|}
for each='var kv in group' -File.Delete(kv.Key);
-File.WriteAllText(group.Key + ".cs", newCode);