diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/README.md | 5 | ||||
-rwxr-xr-x | scripts/bumpAndroidBuildNumber.sh | 10 | ||||
-rwxr-xr-x | scripts/bumpIosBuildNumber.sh | 10 | ||||
-rw-r--r-- | scripts/bundleUpdate.js | 104 | ||||
-rw-r--r-- | scripts/bundleUpdate.sh | 26 | ||||
-rwxr-xr-x | scripts/updateExtensions.sh | 10 | ||||
-rwxr-xr-x | scripts/useBuildNumberEnv.sh | 11 |
7 files changed, 156 insertions, 20 deletions
diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 000000000..99d6236f9 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,5 @@ +# Tool Scripts + +## updateExtensions.sh + +Updates the extensions in `/modules` with the current iOS/Android project changes. diff --git a/scripts/bumpAndroidBuildNumber.sh b/scripts/bumpAndroidBuildNumber.sh deleted file mode 100755 index 105f1296d..000000000 --- a/scripts/bumpAndroidBuildNumber.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# The number here should always be the line number the iOS build variable is on -line=$(sed "30q;d" ./app.config.js) -currentBuildNumber=$(echo "$line" | grep -oE '[0-9]+([.][0-9]+)?') -newBuildNumber=$((currentBuildNumber+1)) -newBuildVariable="const ANDROID_VERSION_CODE = '$newBuildNumber'" -sed -i.bak "30s/.*/ $newBuildVariable/" ./app.config.js -rm -rf ./app.config.js.bak - -echo "Android build number bumped to $newBuildNumber" diff --git a/scripts/bumpIosBuildNumber.sh b/scripts/bumpIosBuildNumber.sh deleted file mode 100755 index b78d2e69d..000000000 --- a/scripts/bumpIosBuildNumber.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh -# The number here should always be the line number the iOS build variable is on -line=$(sed "24q;d" ./app.config.js) -currentBuildNumber=$(echo "$line" | grep -oE '[0-9]+([.][0-9]+)?') -newBuildNumber=$((currentBuildNumber+1)) -newBuildVariable="const IOS_BUILD_NUMBER = '$newBuildNumber'" -sed -i.bak "24s/.*/ $newBuildVariable/" ./app.config.js -rm -rf ./app.config.js.bak - -echo "iOS build number bumped to $newBuildNumber" diff --git a/scripts/bundleUpdate.js b/scripts/bundleUpdate.js new file mode 100644 index 000000000..00217dcd7 --- /dev/null +++ b/scripts/bundleUpdate.js @@ -0,0 +1,104 @@ +const crypto = require('crypto') +const fs = require('fs') +const fsp = fs.promises +const path = require('path') + +const DIST_DIR = './dist' +const BUNDLES_DIR = '/_expo/static/js' +const IOS_BUNDLE_DIR = path.join(DIST_DIR, BUNDLES_DIR, '/ios') +const ANDROID_BUNDLE_DIR = path.join(DIST_DIR, BUNDLES_DIR, '/android') +const METADATA_PATH = path.join(DIST_DIR, '/metadata.json') +const DEST_DIR = './bundleTempDir' + +// Weird, don't feel like figuring out _why_ it wants this +const METADATA = require(`../${METADATA_PATH}`) +const IOS_METADATA_ASSETS = METADATA.fileMetadata.ios.assets +const ANDROID_METADATA_ASSETS = METADATA.fileMetadata.android.assets + +const getMd5 = async path => { + return new Promise(res => { + const hash = crypto.createHash('md5') + const rStream = fs.createReadStream(path) + rStream.on('data', data => { + hash.update(data) + }) + rStream.on('end', () => { + res(hash.digest('hex')) + }) + }) +} + +const moveFiles = async () => { + console.log('Making directory...') + await fsp.mkdir(DEST_DIR) + await fsp.mkdir(path.join(DEST_DIR, '/assets')) + + console.log('Getting ios md5...') + const iosCurrPath = path.join( + IOS_BUNDLE_DIR, + (await fsp.readdir(IOS_BUNDLE_DIR))[0], + ) + const iosMd5 = await getMd5(iosCurrPath) + const iosNewPath = `bundles/${iosMd5}.bundle` + + console.log('Copying ios bundle...') + await fsp.cp(iosCurrPath, path.join(DEST_DIR, iosNewPath)) + + console.log('Getting android md5...') + const androidCurrPath = path.join( + ANDROID_BUNDLE_DIR, + (await fsp.readdir(ANDROID_BUNDLE_DIR))[0], + ) + const androidMd5 = await getMd5(androidCurrPath) + const androidNewPath = `bundles/${androidMd5}.bundle` + + console.log('Copying android bundle...') + await fsp.cp(androidCurrPath, path.join(DEST_DIR, androidNewPath)) + + const iosAssets = [] + const androidAssets = [] + + console.log('Getting ios asset md5s and moving them...') + for (const asset of IOS_METADATA_ASSETS) { + const currPath = path.join(DIST_DIR, asset.path) + const md5 = await getMd5(currPath) + const withExtPath = `assets/${md5}.${asset.ext}` + iosAssets.push(withExtPath) + await fsp.cp(currPath, path.join(DEST_DIR, withExtPath)) + } + + console.log('Getting android asset md5s and moving them...') + for (const asset of ANDROID_METADATA_ASSETS) { + const currPath = path.join(DIST_DIR, asset.path) + const md5 = await getMd5(currPath) + const withExtPath = `assets/${md5}.${asset.ext}` + androidAssets.push(withExtPath) + await fsp.cp(currPath, path.join(DEST_DIR, withExtPath)) + } + + const result = { + version: 0, + bundler: 'metro', + fileMetadata: { + ios: { + bundle: iosNewPath, + assets: iosAssets, + }, + android: { + bundle: androidNewPath, + assets: androidAssets, + }, + }, + } + + console.log('Writing metadata...') + await fsp.writeFile( + path.join(DEST_DIR, 'metadata.json'), + JSON.stringify(result), + ) + + console.log('Finished!') + console.log('Metadata:', result) +} + +moveFiles() diff --git a/scripts/bundleUpdate.sh b/scripts/bundleUpdate.sh new file mode 100644 index 000000000..18db81a20 --- /dev/null +++ b/scripts/bundleUpdate.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -o errexit +set -o pipefail +set -o nounset + +rm -rf bundleTempDir +rm -rf bundle.tar.gz + +echo "Creating tarball..." +node scripts/bundleUpdate.js + +cd bundleTempDir || exit + +BUNDLE_VERSION=$(date +%s) +DEPLOYMENT_URL="https://updates.bsky.app/v1/upload?runtime-version=$RUNTIME_VERSION&bundle-version=$BUNDLE_VERSION" + +tar czvf bundle.tar.gz ./* + +echo "Deploying to $DEPLOYMENT_URL..." + +curl -o - --form "bundle=@./bundle.tar.gz" --user "bsky:$DENIS_API_KEY" --basic "$DEPLOYMENT_URL" + +cd .. + +rm -rf bundleTempDir +rm -rf bundle.tar.gz diff --git a/scripts/updateExtensions.sh b/scripts/updateExtensions.sh new file mode 100755 index 000000000..f4e462b74 --- /dev/null +++ b/scripts/updateExtensions.sh @@ -0,0 +1,10 @@ +#!/bin/bash +IOS_SHARE_EXTENSION_DIRECTORY="./ios/Share-with-Bluesky" +MODULES_DIRECTORY="./modules" + +if [ ! -d $IOS_SHARE_EXTENSION_DIRECTORY ]; then + echo "$IOS_SHARE_EXTENSION_DIRECTORY not found inside of your iOS project." + exit 1 +else + cp -R $IOS_SHARE_EXTENSION_DIRECTORY $MODULES_DIRECTORY +fi diff --git a/scripts/useBuildNumberEnv.sh b/scripts/useBuildNumberEnv.sh new file mode 100755 index 000000000..fe273d394 --- /dev/null +++ b/scripts/useBuildNumberEnv.sh @@ -0,0 +1,11 @@ +#!/bin/bash +outputIos=$(eas build:version:get -p ios) +outputAndroid=$(eas build:version:get -p android) +currentIosVersion=${outputIos#*buildNumber - } +currentAndroidVersion=${outputAndroid#*versionCode - } + +BSKY_IOS_BUILD_NUMBER=$((currentIosVersion+1)) +BSKY_ANDROID_VERSION_CODE=$((currentAndroidVersion+1)) + +bash -c "BSKY_IOS_BUILD_NUMBER=$BSKY_IOS_BUILD_NUMBER BSKY_ANDROID_VERSION_CODE=$BSKY_ANDROID_VERSION_CODE $*" + |