4
4
5
5
using System ;
6
6
using System . Collections . Generic ;
7
- using System . ComponentModel ;
8
7
using System . IO ;
9
8
using System . Linq ;
10
- using System . Linq . Expressions ;
11
9
using System . Reflection ;
12
10
using System . Text ;
13
- using System . Threading . Tasks ;
14
- using System . Xml . XPath ;
15
11
using JetBrains . Annotations ;
16
- using Newtonsoft . Json ;
17
- using Newtonsoft . Json . Linq ;
18
12
using Nuke . Common ;
19
13
using Nuke . Common . IO ;
20
14
using Nuke . Common . Tooling ;
@@ -103,58 +97,60 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
103
97
104
98
#region Additional
105
99
106
- var defaultBuildDefinitions = new List < string > ( ) ;
100
+ var definitions = new List < string > ( ) ;
107
101
108
102
if ( solutionFile != null &&
109
- ConsoleHelper . PromptForChoice ( "Do you need help getting started with a basic build?" ,
110
- ( true , "Yes, get me started!" ) ,
111
- ( false , "No, I can do this myself..." ) ) )
103
+ projectFormat == FORMAT_SDK &&
104
+ ConsoleHelper . PromptForChoice (
105
+ "Do you need help getting started with a basic build?" ,
106
+ ( true , "Yes, get me started!" ) ,
107
+ ( false , "No, I can do this myself..." ) ) )
112
108
{
113
- defaultBuildDefinitions . Add (
109
+ definitions . Add (
114
110
ConsoleHelper . PromptForChoice ( "Restore, compile, pack using ..." ,
115
111
( "DOTNET" , "dotnet CLI" ) ,
116
112
( "MSBUILD" , "MSBuild/Mono" ) ,
117
113
( null , "Neither" ) ) ) ;
118
114
119
- defaultBuildDefinitions . Add (
115
+ definitions . Add (
120
116
ConsoleHelper . PromptForChoice ( "Source files are located in ..." ,
121
117
( "SOURCE_DIR" , "./source" ) ,
122
118
( "SRC_DIR" , "./src" ) ,
123
119
( null , "Neither" ) ) ) ;
124
120
125
- defaultBuildDefinitions . Add (
121
+ definitions . Add (
126
122
ConsoleHelper . PromptForChoice ( "Move packages to ..." ,
127
123
( "OUTPUT_DIR" , "./output" ) ,
128
124
( "ARTIFACTS_DIR" , "./artifacts" ) ,
129
125
( null , "Neither" ) ) ) ;
130
126
131
- defaultBuildDefinitions . Add (
127
+ definitions . Add (
132
128
ConsoleHelper . PromptForChoice ( "Where do test projects go?" ,
133
129
( "TESTS_DIR" , "./tests" ) ,
134
130
( null , "Same as source" ) ) ) ;
135
131
136
132
if ( Directory . Exists ( Path . Combine ( rootDirectory , ".git" ) ) )
137
- defaultBuildDefinitions . Add ( "GIT" ) ;
133
+ definitions . Add ( "GIT" ) ;
138
134
else
139
135
{
140
- defaultBuildDefinitions . Add (
136
+ definitions . Add (
141
137
ConsoleHelper . PromptForChoice ( "Do you use git?" ,
142
138
( "GIT" , "Yes, just not setup yet" ) ,
143
139
( null , "No, something else" ) ) ) ;
144
140
}
145
141
146
142
if ( File . Exists ( Path . Combine ( rootDirectory , "GitVersion.yml" ) ) )
147
- defaultBuildDefinitions . Add ( "GITVERSION" ) ;
148
- else if ( defaultBuildDefinitions . Contains ( "GIT" ) )
143
+ definitions . Add ( "GITVERSION" ) ;
144
+ else if ( definitions . Contains ( "GIT" ) )
149
145
{
150
- defaultBuildDefinitions . Add (
146
+ definitions . Add (
151
147
ConsoleHelper . PromptForChoice ( "Do you use GitVersion?" ,
152
148
( "GITVERSION" , "Yes, just not setup yet" ) ,
153
149
( null , "No, custom versioning" ) ) ) ;
154
150
}
155
151
}
156
152
157
- defaultBuildDefinitions . RemoveAll ( x => x == null ) ;
153
+ definitions . RemoveAll ( x => x == null ) ;
158
154
159
155
#endregion
160
156
@@ -171,7 +167,7 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
171
167
172
168
if ( solutionFile != null )
173
169
{
174
- defaultBuildDefinitions . Add ( "SOLUTION_FILE" ) ;
170
+ definitions . Add ( "SOLUTION_FILE" ) ;
175
171
176
172
var solutionFileContent = TextTasks . ReadAllLines ( solutionFile ) . ToList ( ) ;
177
173
var buildProjectFileRelative = ( WinRelativePath ) GetRelativePath ( solutionDirectory , buildProjectFile ) ;
@@ -185,6 +181,7 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
185
181
buildProjectFile ,
186
182
TemplateUtility . FillTemplate (
187
183
GetTemplate ( $ "_build.{ projectFormat } .csproj") ,
184
+ definitions ,
188
185
replacements : GetDictionary (
189
186
new
190
187
{
@@ -216,7 +213,7 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
216
213
Path . Combine ( buildDirectory , "Build.cs" ) ,
217
214
TemplateUtility . FillTemplate (
218
215
GetTemplate ( "Build.cs" ) ,
219
- defaultBuildDefinitions ,
216
+ definitions ,
220
217
replacements : GetDictionary (
221
218
new
222
219
{
@@ -227,7 +224,6 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
227
224
Path . Combine ( EnvironmentInfo . WorkingDirectory , "build.ps1" ) ,
228
225
TemplateUtility . FillTemplate (
229
226
GetTemplate ( $ "build.{ targetPlatform } .ps1") ,
230
- definitions : null ,
231
227
replacements : GetDictionary (
232
228
new
233
229
{
@@ -243,7 +239,6 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
243
239
Path . Combine ( EnvironmentInfo . WorkingDirectory , "build.sh" ) ,
244
240
TemplateUtility . FillTemplate (
245
241
GetTemplate ( $ "build.{ targetPlatform } .sh") ,
246
- definitions : null ,
247
242
replacements : GetDictionary (
248
243
new
249
244
{
@@ -254,14 +249,21 @@ private static void Setup([CanBeNull] string rootDirectory, string[] args)
254
249
buildProjectName ,
255
250
nugetVersion = "latest"
256
251
} ) ) ) ;
252
+
253
+ if ( definitions . Contains ( "SRC_DIR" ) )
254
+ FileSystemTasks . EnsureExistingDirectory ( Path . Combine ( rootDirectory , "src" ) ) ;
255
+ if ( definitions . Contains ( "SOURCE_DIR" ) )
256
+ FileSystemTasks . EnsureExistingDirectory ( Path . Combine ( rootDirectory , "source" ) ) ;
257
+ if ( definitions . Contains ( "TESTS_DIR" ) )
258
+ FileSystemTasks . EnsureExistingDirectory ( Path . Combine ( rootDirectory , "tests" ) ) ;
257
259
258
260
#endregion
259
261
260
262
#region Wizard+Generation (addon)
261
263
262
264
if ( new [ ] { "addon" , "addin" , "plugin" } . Any ( x => x . EqualsOrdinalIgnoreCase ( args . FirstOrDefault ( ) ) ) )
263
265
{
264
- ControlFlow . Assert ( defaultBuildDefinitions . Contains ( "SOURCE_DIR" ) , "definitions.Contains('SOURCE_DIR')" ) ;
266
+ ControlFlow . Assert ( definitions . Contains ( "SOURCE_DIR" ) , "definitions.Contains('SOURCE_DIR')" ) ;
265
267
266
268
var organization = ConsoleHelper . PromptForInput ( "Organization name:" , defaultValue : "nuke-build" ) ;
267
269
var addonName = ConsoleHelper . PromptForInput ( "Organization name:" , defaultValue : null ) ;
0 commit comments