4
4
using System ;
5
5
using System . Collections . Generic ;
6
6
using System . IO ;
7
+ using System . IO . Compression ;
7
8
using System . Linq ;
8
9
using System . Reflection ;
9
10
using System . Text ;
@@ -17,9 +18,11 @@ class Program
17
18
{
18
19
private static Release _currentRelease ;
19
20
20
- static Version GetReleaseVersion ( ReleaseProject [ ] projects )
21
+ private static DirectoryInfo outputDir ;
22
+
23
+ static ReleaseProject GetMainProject ( ReleaseProject [ ] projects )
21
24
{
22
- return projects . Single ( x => x . IsMainProject ) . Version ;
25
+ return projects . Single ( x => x . IsMainProject ) ;
23
26
}
24
27
25
28
private static void WriteHeader ( string format , params string [ ] args )
@@ -37,7 +40,7 @@ private static void WriteProgressHeader(string text)
37
40
Cli . WriteLine ( " ~Blue~~|White~{0,-" + ( Console . BufferWidth - 2 ) + "}~R~" , text ) ;
38
41
}
39
42
40
- static void Main ( string [ ] args )
43
+ private static void LoadSettings ( )
41
44
{
42
45
WriteHeader ( "Loading release settings" ) ;
43
46
var script = "PhpVH.alx" ;
@@ -47,11 +50,25 @@ static void Main(string[] args)
47
50
_currentRelease = interpreter . GetReturnValue ( ) . ConvertTo < Release > ( ) ;
48
51
var projects = _currentRelease . Projects ;
49
52
Cli . WriteLine ( ) ;
53
+ }
50
54
51
- WriteHeader ( "Copying binaries" ) ;
55
+ private static void Build ( )
56
+ {
57
+ WriteHeader ( "Building" ) ;
52
58
53
- var outputDir = new DirectoryInfo ( _currentRelease . Output )
54
- . Combine ( GetReleaseVersion ( projects ) . ToString ( ) ) ;
59
+ foreach ( var p in _currentRelease . Projects )
60
+ {
61
+ p . Clean ( ) ;
62
+ p . Build ( ) ;
63
+ }
64
+ }
65
+
66
+ private static void CopyBinaries ( )
67
+ {
68
+ WriteHeader ( "Copying binaries" ) ;
69
+ var mainProject = GetMainProject ( _currentRelease . Projects ) ;
70
+ outputDir = new DirectoryInfo ( _currentRelease . Output )
71
+ . Combine ( mainProject . GetVersion ( ) . ToString ( ) ) ;
55
72
56
73
if ( outputDir . Exists )
57
74
{
@@ -62,10 +79,10 @@ static void Main(string[] args)
62
79
Cli . WriteLine ( ) ;
63
80
WriteProgressHeader ( "Copying" ) ;
64
81
65
- var progress = new CliProgressBar ( projects . Length ) ;
82
+ var progress = new CliProgressBar ( _currentRelease . Projects . Length ) ;
66
83
progress . Write ( ) ;
67
84
68
- projects
85
+ _currentRelease . Projects
69
86
. Iter ( x =>
70
87
{
71
88
new DirectoryInfo ( x . OutputPath ) . CopyTo ( outputDir . FullName , true ) ;
@@ -75,6 +92,10 @@ static void Main(string[] args)
75
92
76
93
Cli . WriteLine ( ) ;
77
94
Cli . WriteLine ( ) ;
95
+ }
96
+
97
+ private static void Cleanup ( )
98
+ {
78
99
WriteHeader ( "Cleaning up" ) ;
79
100
Cli . WriteLine ( "Searching..." ) ;
80
101
var fsos = new List < FileSystemInfo > ( ) ;
@@ -101,11 +122,18 @@ static void Main(string[] args)
101
122
Cli . WriteLine ( ) ;
102
123
WriteProgressHeader ( "Deleting" ) ;
103
124
104
- progress = new CliProgressBar ( fsos . Count ) ;
125
+ var progress = new CliProgressBar ( fsos . Count ) ;
105
126
progress . Write ( ) ;
106
127
107
128
fsos . Iter ( x =>
108
129
{
130
+ if ( ! x . Exists )
131
+ {
132
+ progress . Value ++ ;
133
+ progress . Write ( ) ;
134
+ return ;
135
+ }
136
+
109
137
var dir = x as DirectoryInfo ;
110
138
111
139
if ( dir != null )
@@ -120,6 +148,37 @@ static void Main(string[] args)
120
148
progress . Value ++ ;
121
149
progress . Write ( ) ;
122
150
} ) ;
151
+ Cli . WriteLine ( ) ;
152
+ Cli . WriteLine ( ) ;
153
+ }
154
+
155
+ private static void ZipRelease ( )
156
+ {
157
+ WriteHeader ( "Zipping" ) ;
158
+ var name = Path . GetFileNameWithoutExtension ( _currentRelease . MainProject ) ;
159
+ var zipName = name + outputDir . Name + ".zip" ;
160
+ var zipFile = Path . Combine ( outputDir . FullName , ".." , zipName ) ;
161
+
162
+ Cli . WriteLine ( "Creating ~Cyan~{0}~R~" , Path . GetFileName ( zipFile ) ) ;
163
+
164
+ if ( File . Exists ( zipFile ) )
165
+ {
166
+ Cli . WriteLine ( "~Yellow~Zip with same name already exists, deleting.~R~" ) ;
167
+ File . Delete ( zipFile ) ;
168
+ }
169
+
170
+ ZipFile . CreateFromDirectory ( outputDir . FullName , zipFile ) ;
171
+ }
172
+
173
+ static void Main ( string [ ] args )
174
+ {
175
+ LoadSettings ( ) ;
176
+ Build ( ) ;
177
+ CopyBinaries ( ) ;
178
+ Cleanup ( ) ;
179
+ ZipRelease ( ) ;
180
+
181
+ Cli . WriteLine ( "Done\r \n " ) ;
123
182
}
124
183
}
125
184
}
0 commit comments