diff --git a/src/index.ts b/src/index.ts index bf1e7c2..2873d4d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -173,6 +173,7 @@ class PackageJSONManager { private readonly basePath: () => string; public content: { version: string; + versionCode?: string; } | null = null; constructor(basePath: () => string) { @@ -212,6 +213,32 @@ class PackageJSONManager { return { next, current }; } + + getVersionCode() { + return this.read().versionCode; + } + + setVersionCode(next: string) { + const current = this.getVersionCode(); + this.content!.versionCode = next; + + return { next, current }; + } + + bumpVersionCode() { + const current = this.getVersionCode(); + if (current) { + const currentCode = parseInt(current, 10); + const nextCode = currentCode + 1; + const next = nextCode.toString(); + + this.content!.versionCode = next; + + return { next, current }; + } + + return null; + } } class ProjectFilesManager { @@ -278,6 +305,13 @@ class ProjectFilesManager { } = this.buildGradle.bumpCode(); console.log(`Android build.gradle code: ${gradleCurrent} -> ${gradleNext}`); } + + // Bump package.json versionCode + const packageVersionCodeResult = this.packageJSON.bumpVersionCode(); + if (packageVersionCodeResult) { + const { next: packageNext, current: packageCurrent } = packageVersionCodeResult; + console.log(`package.json versionCode: ${packageCurrent} -> ${packageNext}`); + } } run() {