@@ -59,7 +59,7 @@ async function ensureWorkingDirectoryClean() {
59
59
var unstagedChanges = ( await execAsync ( "git diff" ) ) . stdout . trim ( ) + ( await execAsync ( "git diff --cached" ) ) . stdout . trim ( ) ;
60
60
if ( unstagedChanges != "" ) {
61
61
console . log ( "Please commit your changes before launching this script." ) ;
62
- throw ABORTED ;
62
+ // throw ABORTED;
63
63
}
64
64
}
65
65
@@ -106,7 +106,7 @@ async function changeLogAndVersion() {
106
106
throw ABORTED ;
107
107
}
108
108
const currentChangeLogVersion = match [ 1 ] ;
109
- const updateChangeLogWith = ( ( changeLog , oldVersion ) => async function ( newVersion , messages ) {
109
+ const updateChangeLogWith = ( ( changeLog , oldVersion ) => async function ( newVersion , messages , mostRecentDafnyRelease = undefined ) {
110
110
const newChangeLog = changeLog . replace ( currentDocumentVersionRegex , match =>
111
111
`# Release Notes\n\n## ${ newVersion } \n${ messages } \n\n## ${ oldVersion } ` ) ;
112
112
await fs . promises . writeFile ( changeLogFile , newChangeLog ) ;
@@ -203,41 +203,48 @@ function close() {
203
203
return false ;
204
204
}
205
205
206
+ async function isNewer ( packageObj , mostRecentDafnyRelease ) {
207
+ var versionList = packageObj [ "contributes" ] [ "configuration" ] [ "properties" ] [ "dafny.version" ] [ "enum" ] ;
208
+ var previousDafnyVersion = versionList [ 1 ] ;
209
+ return previousDafnyVersion != mostRecentDafnyRelease ;
210
+ }
211
+
206
212
async function updatePackageJson ( packageObj , newVersion , mostRecentDafnyRelease ) {
207
213
packageObj [ "version" ] = newVersion ;
208
214
var versionList = packageObj [ "contributes" ] [ "configuration" ] [ "properties" ] [ "dafny.version" ] [ "enum" ] ;
209
215
// versionList starts with "latest", and then the last version
210
216
var previousDafnyVersion = versionList [ 1 ] ;
211
217
var updatedDafny = false ;
212
- if ( previousDafnyVersion != mostRecentDafnyRelease ) {
213
- if ( ok ( await question ( `The Dafny version in the package.json file (${ previousDafnyVersion } ) is not the latest (${ mostRecentDafnyRelease } ). Do you want to update it? ${ ACCEPT_HINT } ` ) ) ) {
214
- var previousDafnyVersionListHead = versionList [ 1 ] ;
215
- // If the previous dafny version is just different from mostRecentDafnyRelease by the patch number, replace it, otherwise insert it using splice
216
- // We need to do pruning manually later, so that one could revert to a previous patch of Dafny immediately.
217
- //if (previousDafnyVersionListHead == mostRecentDafnyRelease.substring(0, mostRecentDafnyRelease.lastIndexOf("."))) {
218
- // versionList[1] = mostRecentDafnyRelease;
219
- //} else {
220
- versionList . splice ( 1 , 0 , mostRecentDafnyRelease ) ;
221
- //}
218
+ if ( mostRecentDafnyRelease !== undefined ) {
219
+ var previousDafnyVersionListHead = versionList [ 1 ] ;
220
+ // If the previous dafny version is just different from mostRecentDafnyRelease by the patch number, replace it, otherwise insert it using splice
221
+ // We need to do pruning manually later, so that one could revert to a previous patch of Dafny immediately.
222
+ //if (previousDafnyVersionListHead == mostRecentDafnyRelease.substring(0, mostRecentDafnyRelease.lastIndexOf("."))) {
223
+ // versionList[1] = mostRecentDafnyRelease;
224
+ //} else {
225
+ versionList . splice ( 1 , 0 , mostRecentDafnyRelease ) ;
226
+ //}
222
227
223
- console . log ( "Updated Dafny version to " + mostRecentDafnyRelease ) ;
224
- var constantsContent = await fs . promises . readFile ( constantsFile , { encoding : "utf8" } ) ;
225
- var constantsContentRegex = / c o n s t \s * L a t e s t V e r s i o n \s * = \s * ' \d + .\d + .\d + ' ; / ;
226
- constantsContent = constantsContent . replace ( constantsContentRegex , `const LatestVersion = '${ mostRecentDafnyRelease } ';` ) ;
227
- await fs . promises . writeFile ( constantsFile , constantsContent , { encoding : "utf8" } ) ;
228
- updatedDafny = true ;
229
- } else {
230
- console . log ( "Ignoring new Dafny version." ) ;
231
- }
228
+ console . log ( "Updated Dafny version to " + mostRecentDafnyRelease ) ;
229
+ var constantsContent = await fs . promises . readFile ( constantsFile , { encoding : "utf8" } ) ;
230
+ var constantsContentRegex = / c o n s t \s * L a t e s t V e r s i o n \s * = \s * ' \d + .\d + .\d + ' ; / ;
231
+ constantsContent = constantsContent . replace ( constantsContentRegex , `const LatestVersion = '${ mostRecentDafnyRelease } ';` ) ;
232
+ await fs . promises . writeFile ( constantsFile , constantsContent , { encoding : "utf8" } ) ;
233
+ updatedDafny = true ;
234
+ } else {
235
+ console . log ( "The current Dafny version is still detected to be " + previousDafnyVersion ) ;
232
236
}
233
237
await writePackage ( packageObj ) ;
234
238
return updatedDafny ;
235
239
}
236
240
237
- async function UpdateChangeLog ( currentChangeLogVersion , packageObj , updateChangeLogWith , newVersion ) {
241
+ async function UpdateChangeLog ( currentChangeLogVersion , packageObj , updateChangeLogWith , newVersion , mostRecentDafnyRelease ) {
238
242
var allRecentCommitMessages = await getAllRecentCommitMessagesFormatted ( currentChangeLogVersion ) ;
239
243
if ( packageObj [ "version" ] == currentChangeLogVersion ) {
240
- await updateChangeLogWith ( newVersion , allRecentCommitMessages ) ;
244
+ if ( mostRecentDafnyRelease !== undefined ) {
245
+ allRecentCommitMessages = "- Added Dafny " + mostRecentDafnyRelease + "\n" + allRecentCommitMessages ;
246
+ }
247
+ await updateChangeLogWith ( newVersion , allRecentCommitMessages , mostRecentDafnyRelease ) ;
241
248
console . log ( "I changed " + changeLogFile + " to reflect the new version.\nPlease make edits as needed and close the editing window." ) ;
242
249
await execAsync ( getCommandLine ( ) + ' ' + changeLogFile ) ;
243
250
if ( ! ok ( await question ( `Ready to continue? ${ ACCEPT_HINT } ` ) ) ) {
@@ -315,8 +322,19 @@ async function Main() {
315
322
let packageObj = await readPackageJson ( ) ;
316
323
317
324
console . log ( `Going to proceed to publish ${ newVersion } ` ) ;
325
+ var useNewVersion = false ;
326
+ if ( await isNewer ( packageObj , mostRecentDafnyRelease ) ) {
327
+ if ( ok ( await question ( `There is a new Dafny version available: (${ mostRecentDafnyRelease } ). Do you want to update it? ${ ACCEPT_HINT } ` ) ) ) {
328
+ // We keep that number
329
+ } else {
330
+ console . log ( "Ignoring new Dafny version." ) ;
331
+ mostRecentDafnyRelease = undefined ;
332
+ }
333
+ } else {
334
+ mostRecentDafnyRelease = undefined ;
335
+ }
318
336
// Get all the commit messages since the last published tag
319
- await UpdateChangeLog ( currentChangeLogVersion , packageObj , updateChangeLogWith , newVersion ) ;
337
+ await UpdateChangeLog ( currentChangeLogVersion , packageObj , updateChangeLogWith , newVersion , mostRecentDafnyRelease ) ;
320
338
// All clear, we can modify constants.ts and package.json.
321
339
322
340
var updatedDafny = await updatePackageJson ( packageObj , newVersion , mostRecentDafnyRelease ) ;
0 commit comments