Skip to content

Commit

Permalink
refactor: improved package.json scripts and cleaned up demo components
Browse files Browse the repository at this point in the history
  • Loading branch information
usotsukki committed Oct 19, 2024
1 parent 795d644 commit 97d3092
Show file tree
Hide file tree
Showing 24 changed files with 367 additions and 169 deletions.
1 change: 1 addition & 0 deletions .easignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ credentials.json
*.key
*.mobileprovision
*.keystore
.idea/

# Metro
.metro-health-check*
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/eas-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 20
cache: yarn

- name: Setup Expo and EAS
Expand All @@ -24,9 +24,6 @@ jobs:
- name: Run linters
run: yarn lint

- name: Run prettier
run: yarn format:check

- name: Run tests
run: yarn test

Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/eas-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: eas update auto
on:
workflow_dispatch:
push:
branches:
- main
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn

- name: 🏗 Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}

- name: 📦 Install dependencies
run: yarn install

- name: 🚀 Create update
run: eas update --auto --non-interactive
6 changes: 2 additions & 4 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
node-version: 20
cache: yarn

- name: Install dependencies
Expand All @@ -21,11 +21,9 @@ jobs:
- name: Run linters
run: yarn lint

- name: Run prettier
run: yarn format:check

- name: Run tests
run: yarn test

- name: Check for code duplication
run: yarn check-duplicates
run: yarn duplication:check
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ credentials.json
*.key
*.mobileprovision
*.keystore
.idea/

# Metro
.metro-health-check*
Expand Down
2 changes: 1 addition & 1 deletion .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yarn lint:commit ${1}
yarn lint-commit ${1}
45 changes: 22 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@
"private": true,
"main": "expo-router/entry",
"scripts": {
"android": "yarn expo run:android -d",
"eas-android": "eas build -p android -e development",
"eas-ios": "eas build -p ios -e development",
"eas-run-android": "eas build:run --latest -p android -e development",
"eas-run-ios": "eas build:run --latest -p ios -e development",
"check-deps": "./scripts/check-unused-deps.sh",
"check-duplicates": "yarn jscpd --config jscpd.json",
"check-duplicates:i": "yarn jscpd --config jscpd.json && open ./cpd/html/index.html",
"fast": "yarn install && yarn install-pods-fast",
"format": "prettier --write .",
"format:check": "prettier --check .",
"android": "expo run:android",
"android:prebuild": "expo prebuild -p android",
"android:rebuild": "run-s android:prebuild android",
"eas-android": "eas build --no-wait -e development -p android",
"eas-ios": "eas build --no-wait -e development -p ios",
"eas-run": "eas build:run --latest -e development -p",
"check-unused-deps": "./scripts/check-unused-deps.sh",
"duplication:check": "jscpd --config jscpd.json",
"duplication:view": "jscpd --config jscpd.json && open ./cpd/html/index.html",
"increment-version": "./scripts/bump-version.sh",
"install-all": "yarn install && yarn install-pods",
"install-pods": "cd ios && pod install --repo-update && cd ..",
"install-pods-fast": "cd ios && pod install && cd ..",
"ios": "yarn expo run:ios",
"ios:prebuild": "yarn expo prebuild -p ios",
"ios:rebuild": "yarn ios:prebuild && yarn ios",
"lint": "yarn lint:js && yarn lint:ts",
"lint:commit": "yarn commitlint --config commitlint.config.js --edit",
"install-pods": "(cd ios && pod install)",
"ios": "expo run:ios",
"ios:prebuild": "expo prebuild -p ios",
"ios:rebuild": "run-s ios:prebuild ios",
"lint": "run-p lint:*",
"lint-commit": "commitlint --config commitlint.config.js --edit ",
"lint:format": "prettier --write .",
"lint:format:check": "prettier --check .",
"lint:js": "eslint --cache . --quiet",
"lint:ts": "yarn tsc --skipLibCheck --noEmit",
"lint:ts": "tsc --skipLibCheck --noEmit",
"nuke": "./scripts/nuke.sh",
"postinstall": "patch-package",
"prepare": "husky",
"start": "yarn expo start --dev-client",
"start": "expo start --dev-client",
"switch-env": "./scripts/switch-env.sh",
"test": "yarn jest src",
"test": "jest src",
"test-e2e": "./scripts/run-maestro-tests.sh",
"test-detox:build": "detox build -c ios.sim.debug",
"test-detox": "detox test -c ios.sim.debug"
Expand Down Expand Up @@ -62,7 +60,6 @@
"expo-build-properties": "~0.12.5",
"expo-constants": "~16.0.2",
"expo-dev-client": "~4.0.28",
"expo-dev-launcher": "^4.0.28",
"expo-font": "~12.0.10",
"expo-image": "~1.13.0",
"expo-insights": "~0.7.0",
Expand Down Expand Up @@ -122,6 +119,7 @@
"babel-plugin-transform-remove-console": "^6.9.4",
"conventional-changelog-atom": "^5.0.0",
"detox": "^20.27.3",
"dotenv-cli": "^7.4.2",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-babel-module": "^5.3.2",
Expand All @@ -141,6 +139,7 @@
"jest-expo": "^51.0.4",
"jscpd": "^4.0.5",
"lint-staged": "^15.2.10",
"npm-run-all": "^4.1.5",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "3.3.3",
Expand Down
25 changes: 12 additions & 13 deletions scripts/bump-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ SUCCESS_ICON="✅"
ERROR_ICON="👺"
UPDATING_ICON="🌸"

COMMIT_VERSION_UPDATE=true # Set to false to disable Git commit

json_file="app.json"

# Define the expo_sdk_version variable
Expand All @@ -20,40 +22,33 @@ expo_sdk_version="051"
update_type="$1"
decrement_flag="$2"

# Validate the update type argument (it must be major, minor, or patch)
if [ -z "$update_type" ] || ! [[ "$update_type" =~ ^(major|minor|patch)$ ]]; then
echo -e "${RED}${ERROR_ICON} Error: Invalid update type. Use one of <major|minor|patch>${NC}"
exit 1
fi

# Validate the second argument (must be --decrement or nothing)
if [ -n "$decrement_flag" ] && [ "$decrement_flag" != "--decrement" ]; then
echo -e "${RED}${ERROR_ICON} Error: Invalid option. Use --decrement to decrease the version.${NC}"
exit 1
fi

# Check if the JSON file exists
if [ ! -f "$json_file" ]; then
echo -e "${RED}${ERROR_ICON} Error: JSON file not found at path: $json_file${NC}"
exit 1
fi

# Display a starting message with an emoji
echo -e "${GREEN}${STARTING_ICON} Starting the update process... ${STARTING_ICON}${NC}"

# Extract the current version, buildNumber, and versionCode from the JSON file
current_version=$(jq -r '.expo.version' "$json_file")
current_build_number=$(jq -r '.expo.ios.buildNumber' "$json_file")
current_version_code=$(jq -r '.expo.android.versionCode' "$json_file")

# Split the version into major, minor, and patch components
IFS='.' read -r -a version_parts <<< "$current_version"

# Handle the decrement flag (if present, decrement instead of increment)
if [ "$decrement_flag" == "--decrement" ]; then
case "$update_type" in
"major")
# Prevent decrementing major below 1
if ((version_parts[0] > 1)); then
((version_parts[0]--))
version_parts[1]=0
Expand All @@ -64,7 +59,6 @@ if [ "$decrement_flag" == "--decrement" ]; then
fi
;;
"minor")
# Prevent decrementing minor below 0 and reset patch
if ((version_parts[1] > 0)); then
((version_parts[1]--))
version_parts[2]=0
Expand All @@ -74,7 +68,6 @@ if [ "$decrement_flag" == "--decrement" ]; then
fi
;;
"patch")
# Prevent decrementing patch below 0
if ((version_parts[2] > 0)); then
((version_parts[2]--))
else
Expand Down Expand Up @@ -108,20 +101,26 @@ for i in "${!version_parts[@]}"; do
fi
done

# Create the new version string
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"

# Calculate the new versionCode dynamically
new_version_code_dynamic="${expo_sdk_version}$(printf "%02d" "${version_parts[0]}")$(printf "%02d" "${version_parts[1]}")$(printf "%02d" "${version_parts[2]}")"

# Update the version, buildNumber, and versionCode fields in the JSON file
jq --arg new_version "$new_version" --arg new_version_code "$new_version_code_dynamic" '.expo.version = $new_version | .expo.ios.buildNumber = $new_version | .expo.android.versionCode = ($new_version_code | tonumber)' "$json_file" > tmp.json && mv tmp.json "$json_file"

# Run formatter to format the JSON file
prettier --write "$json_file"

# Display a success message with an emoji
echo -e "${GREEN} version, buildNumber and versionCode updated ${UPDATING_ICON}${NC}"
echo -e "${GREEN}${SUCCESS_ICON}${NC} version: $new_version"
echo -e "${GREEN}${SUCCESS_ICON}${NC} buildNumber: $new_version"
echo -e "${GREEN}${SUCCESS_ICON}${NC} versionCode: $new_version_code_dynamic"

if [ "$COMMIT_VERSION_UPDATE" = true ]; then
git add "$json_file"
git commit -m "chore: bump version to $new_version"
if [ $? -eq 0 ]; then
echo -e "${GREEN}${SUCCESS_ICON} Successfully committed version bump to $new_version.${NC}"
else
echo -e "${RED}${ERROR_ICON} Failed to create a commit.${NC}"
fi
fi
Loading

0 comments on commit 97d3092

Please sign in to comment.