diff --git a/deploy.mjs b/deploy.mjs new file mode 100644 index 0000000..d52e36c --- /dev/null +++ b/deploy.mjs @@ -0,0 +1,44 @@ +import { execSync } from 'child_process'; +import { readFileSync, writeFileSync } from 'fs'; +import { join } from 'path'; +import simpleGit from 'simple-git'; +import os from 'os'; + +execSync('npx tsc', { stdio: 'inherit' }); +process.chdir('android'); + +const buildFilePath = join(process.cwd(), 'app', 'build.gradle'); +let buildFile = readFileSync(buildFilePath, 'utf8'); + +const versionCodeMatch = buildFile.match(/versionCode (\d+)/); +if (!versionCodeMatch) throw new Error('versionCode not found in build.gradle'); +const versionCode = parseInt(versionCodeMatch[1], 10) + 1; +buildFile = buildFile.replace(/versionCode \d+/, `versionCode ${versionCode}`); + +const versionNameMatch = buildFile.match(/versionName "(\d+\.\d+)"/); +if (!versionNameMatch) throw new Error('versionName not found in build.gradle'); +const versionParts = versionNameMatch[1].split('.'); +versionParts[1] = (parseInt(versionParts[1], 10) + 1).toString(); +const versionName = versionParts.join('.'); +buildFile = buildFile.replace(/versionName "\d+\.\d+"/, `versionName "${versionName}"`); + +writeFileSync(buildFilePath, buildFile); + +const packageJsonPath = join(process.cwd(), '..', 'package.json'); +let packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); +packageJson.version = versionName; +writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); + +const isWindows = os.platform() === 'win32'; +execSync(isWindows ? '.\\gradlew.bat bundleRelease' : './gradlew bundleRelease', { stdio: 'inherit' }); +execSync('bundle install', { stdio: 'inherit' }); +execSync('bundle exec fastlane supply --aab app/build/outputs/bundle/release/app-release.aab', { stdio: 'inherit' }); + +const git = simpleGit(); +git.log(['-1']).then(log => { + const lastCommitMessage = log.latest.message; + const newCommitMessage = lastCommitMessage + ` - ${versionName} 🚀`; + return git.commit(newCommitMessage, [buildFilePath, packageJsonPath]); +}).then(() => git.addTag(versionCode.toString())) + .then(() => git.push('origin', 'HEAD')) + .then(() => git.pushTags('origin')); \ No newline at end of file diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index e5facc8..0000000 --- a/deploy.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -set -ex - -npx tsc - -cd android || exit 1 - -build=app/build.gradle -versionCode=$( - grep '^\s*versionCode [0-9]*$' "$build" | awk '{print $2+1}' -) -major=$( - grep '^\s*versionName "[0-9]*\.[0-9]*"' "$build" | - sed 's/"//g' | cut -d '.' -f 1 | awk '{print $2}' -) -minor=$( - grep '^\s*versionName "[0-9]*\.[0-9]*"' "$build" | - sed 's/"//g' | cut -d '.' -f 2 -) -minor=$((minor + 1)) - -sed -i "s/\(^\s*\)versionCode [0-9]*$/\1versionCode $versionCode/" \ - "$build" -sed -i "s/\(^\s*\)versionName \"[0-9]*.[0-9]*\"$/\1versionName \"$major.$minor\"/" "$build" -sed -i "s/\"version\": \"[0-9]*.[0-9]*\"/\"version\": \"$major.$minor\"/" ../package.json - -if [ "$1" != "-n" ]; then - ./gradlew bundleRelease - bundle install - bundle exec fastlane supply --aab app/build/outputs/bundle/release/app-release.aab -fi - -git add app/build.gradle ../package.json -git commit --amend --message \ - "$(git log -1 --pretty=%B | sed " 1 s/.*/& - $major.$minor 🚀/")" -git tag "$versionCode" -git push origin HEAD -git push --tags