@@ -189,7 +189,7 @@ void writeVersionToIndexHtml(
189
189
indexHtml.writeAsStringSync (revisedLines.joinWithNewLine ());
190
190
}
191
191
192
- String incrementDevVersion (String currentVersion, String devType ) {
192
+ String incrementDevVersion (String currentVersion) {
193
193
final alreadyHasDevVersion = isDevVersion (currentVersion);
194
194
if (alreadyHasDevVersion) {
195
195
final devVerMatch = RegExp (
@@ -208,8 +208,17 @@ String incrementDevVersion(String currentVersion, String devType) {
208
208
return newVersion;
209
209
}
210
210
} else {
211
- final nextVersion = incrementVersionByType (currentVersion, devType);
212
- return '$nextVersion -dev.0' ;
211
+ return '$currentVersion -dev.0' ;
212
+ }
213
+ }
214
+
215
+ String stripPreReleases (String currentVersion) {
216
+ final devVerMatch =
217
+ RegExp (r'^(?<semver>\d+\.\d+\.\d+).*$' ).firstMatch (currentVersion);
218
+ if (devVerMatch == null ) {
219
+ throw 'Could not strip pre-releases from version: $currentVersion ' ;
220
+ } else {
221
+ return devVerMatch.namedGroup ('semver' )! ;
213
222
}
214
223
}
215
224
@@ -280,48 +289,83 @@ class AutoUpdateCommand extends Command {
280
289
final name = 'auto' ;
281
290
@override
282
291
final description = 'Automatically update devtools to a new version.' ;
283
-
284
292
AutoUpdateCommand () {
285
- argParser.addOption ('type' ,
286
- abbr: 't' ,
287
- allowed: ['dev' , 'dev,patch' , 'dev,major' , 'patch' , 'minor' , 'major' ],
288
- allowedHelp: {
289
- 'dev' :
290
- 'bumps the version to the next dev pre-release value (minor by default)' ,
291
- 'dev,patch' : 'bumps the version to the next dev pre-patch value' ,
292
- 'dev,major' : 'bumps the version to the next dev pre-major value' ,
293
- 'patch' : 'bumps the version to the next patch value' ,
294
- 'minor' : 'bumps the version to the next minor value' ,
295
- 'major' : 'bumps the version to the next major value' ,
296
- },
297
- mandatory: true ,
298
- help: 'Bumps the devtools version by the selected type.' );
293
+ argParser.addOption (
294
+ 'type' ,
295
+ abbr: 't' ,
296
+ allowed: ['release' , 'dev' , 'patch' , 'minor' , 'major' ],
297
+ allowedHelp: {
298
+ 'release' : [
299
+ 'strips any pre-release versions from the version.' ,
300
+ 'Examples:' ,
301
+ '\t 1.2.3 => 1.2.3' ,
302
+ '\t 1.2.3-dev.4 => 1.2.3' ,
303
+ ].join ('\n ' ),
304
+ 'dev' : [
305
+ 'bumps the version to the next dev pre-release value (minor by default).' ,
306
+ 'Examples:' ,
307
+ '\t 1.2.3 => 1.2.3-dev.0' ,
308
+ '\t 1.2.3-dev.4 => 1.2.3-dev.5' ,
309
+ ].join ('\n ' ),
310
+ 'patch' : [
311
+ 'bumps the version to the next patch value.' ,
312
+ 'Examples:' ,
313
+ '\t 1.2.3 => 1.2.4' ,
314
+ '\t 1.2.3-dev.4 => 1.2.4' ,
315
+ ].join ('\n ' ),
316
+ 'minor' : [
317
+ 'bumps the version to the next minor value.' ,
318
+ 'Examples:' ,
319
+ '\t 1.2.3 => 1.3.0' ,
320
+ '\t 1.2.3-dev.4 => 1.3.0' ,
321
+ ].join ('\n ' ),
322
+ 'major' : [
323
+ 'bumps the version to the next major value.' ,
324
+ 'Examples:' ,
325
+ '\t 1.2.3 => 2.0.0' ,
326
+ '\t 1.2.3-dev.4 => 2.0.0' ,
327
+ ].join ('\n ' ),
328
+ },
329
+ mandatory: true ,
330
+ help: 'Bumps the devtools version by the selected type.' ,
331
+ );
332
+ argParser.addFlag (
333
+ 'dry-run' ,
334
+ abbr: 'd' ,
335
+ defaultsTo: false ,
336
+ help: 'Displays the version change that would happen, without performing '
337
+ 'it.' ,
338
+ );
299
339
}
300
340
301
341
@override
302
- void run () {
342
+ void run () async {
303
343
final type = argResults! ['type' ].toString ();
344
+ final isDryRun = argResults! ['dry-run' ];
304
345
final currentVersion = versionFromPubspecFile ();
305
346
String ? newVersion;
306
347
if (currentVersion == null ) {
307
348
throw 'Could not automatically determine current version.' ;
308
349
}
309
350
switch (type) {
310
- case 'dev' :
311
- newVersion = incrementDevVersion (currentVersion, 'minor' );
312
- break ;
313
- case 'dev,patch' :
314
- newVersion = incrementDevVersion (currentVersion, 'patch' );
351
+ case 'release' :
352
+ newVersion = stripPreReleases (currentVersion);
315
353
break ;
316
- case 'dev,major ' :
317
- newVersion = incrementDevVersion (currentVersion, 'major' );
354
+ case 'dev' :
355
+ newVersion = incrementDevVersion (currentVersion);
318
356
break ;
319
357
default :
320
358
newVersion = incrementVersionByType (currentVersion, type);
359
+ if (newVersion == null ) {
360
+ throw 'Failed to determine the newVersion.' ;
361
+ }
321
362
}
322
- if (newVersion == null ) {
323
- throw 'Failed to determine the newVersion.' ;
363
+ print ('Updating from $currentVersion to $newVersion ' );
364
+
365
+ if (isDryRun) {
366
+ return ;
324
367
}
368
+
325
369
performTheVersionUpdate (
326
370
currentVersion: currentVersion,
327
371
newVersion: newVersion,
0 commit comments