2021-02-01 13:52:45 +02:00
import * as fs from 'fs-extra' ;
2021-12-16 18:10:17 +02:00
import { rootDir , gitPullTry , completeReleaseWithChangelog } from './tool-utils' ;
2021-12-16 18:04:52 +02:00
const { unique } = require ( '@joplin/lib/ArrayUtils' ) ;
2021-02-01 13:52:45 +02:00
const mobileDir = ` ${ rootDir } /packages/app-mobile ` ;
2021-05-14 14:52:29 +02:00
// Note that it will update all the MARKETING_VERSION and
// CURRENT_PROJECT_VERSION fields, including for extensions (such as the
// ShareExtension), which is normally what we want.
// https://github.com/laurent22/joplin/pull/4963
2021-02-01 13:52:45 +02:00
async function updateCodeProjVersions ( filePath : string ) {
const originalContent = await fs . readFile ( filePath , 'utf8' ) ;
let newContent = originalContent ;
let newVersion = '' ;
2021-11-07 13:55:34 +02:00
let newVersionId = 0 ;
2021-02-01 13:52:45 +02:00
// MARKETING_VERSION = 10.1.0;
newContent = newContent . replace ( /(MARKETING_VERSION = )(\d+\.\d+)\.(\d+)(.*)/g , function ( _match , prefix , majorMinorVersion , buildNum , suffix ) {
const n = Number ( buildNum ) ;
if ( isNaN ( n ) ) throw new Error ( ` Invalid version code: ${ buildNum } ` ) ;
newVersion = ` ${ majorMinorVersion } . ${ n + 1 } ` ;
return ` ${ prefix } ${ newVersion } ${ suffix } ` ;
} ) ;
// CURRENT_PROJECT_VERSION = 58;
newContent = newContent . replace ( /(CURRENT_PROJECT_VERSION = )(\d+)(.*)/g , function ( _match , prefix , projectVersion , suffix ) {
const n = Number ( projectVersion ) ;
if ( isNaN ( n ) ) throw new Error ( ` Invalid version code: ${ projectVersion } ` ) ;
2021-11-07 13:55:34 +02:00
newVersionId = n + 1 ;
return ` ${ prefix } ${ newVersionId } ${ suffix } ` ;
2021-02-01 13:52:45 +02:00
} ) ;
if ( ! newVersion ) throw new Error ( 'Could not determine new version' ) ;
if ( newContent === originalContent ) throw new Error ( 'No change was made to project file' ) ;
await fs . writeFile ( filePath , newContent , 'utf8' ) ;
2021-11-07 13:55:34 +02:00
return { newVersion , newVersionId } ;
2021-02-01 13:52:45 +02:00
}
2021-12-16 18:04:52 +02:00
// Check that deployment targets of all projects match
// IPHONEOS_DEPLOYMENT_TARGET
// If they don't we get this kind of error:
// https://github.com/laurent22/joplin/issues/4945#issuecomment-995802706
async function checkDeploymentTargets ( filePath : string ) {
const content = await fs . readFile ( filePath , 'utf8' ) ;
const re = /IPHONEOS_DEPLOYMENT_TARGET = ([0-9.]+)/g ;
let match = re . exec ( content ) ;
let versions : string [ ] = [ ] ;
while ( match ) {
versions . push ( match [ 1 ] ) ;
match = re . exec ( content ) ;
}
versions = unique ( versions ) ;
if ( versions . length > 1 ) throw new Error ( ` Detected mismatched IPHONEOS_DEPLOYMENT_TARGET: ${ versions . join ( ', ' ) } . Set them all to the same target. In ${ filePath } ` ) ;
if ( ! versions . length ) throw new Error ( ` Could not find IPHONEOS_DEPLOYMENT_TARGET in ${ filePath } ` ) ;
}
2021-02-01 13:52:45 +02:00
async function main() {
await gitPullTry ( ) ;
2021-12-16 18:04:52 +02:00
const pbxprojFilePath = ` ${ mobileDir } /ios/Joplin.xcodeproj/project.pbxproj ` ;
await checkDeploymentTargets ( pbxprojFilePath ) ;
2021-02-01 13:52:45 +02:00
console . info ( 'Updating version numbers...' ) ;
2021-12-16 18:04:52 +02:00
const { newVersion , newVersionId } = await updateCodeProjVersions ( pbxprojFilePath ) ;
2021-11-07 13:55:34 +02:00
console . info ( ` New version: ${ newVersion } ( ${ newVersionId } ) ` ) ;
2021-02-01 13:52:45 +02:00
const tagName = ` ios-v ${ newVersion } ` ;
2021-11-07 13:55:34 +02:00
console . info ( ` Tag name: ${ tagName } ` ) ;
2021-12-16 18:10:17 +02:00
const changelogPath = ` ${ rootDir } /readme/changelog_ios.md ` ;
await completeReleaseWithChangelog ( changelogPath , newVersion , tagName , 'iOS' , false ) ;
2021-02-01 13:52:45 +02:00
}
main ( ) . catch ( ( error ) = > {
console . error ( 'Fatal error' ) ;
console . error ( error ) ;
process . exit ( 1 ) ;
} ) ;