DEV Community

terrierscript
terrierscript

Posted on • Updated on

Generate staging app.json for Expo like flavor

This article is depreacted
In Latest Expo version can dynamic config app.config.js

see: https://docs.expo.io/workflow/configuration/#dynamic-configuration-with-appconfigjs




In some case, we need change app.json variable for staging channel (like bundleIdentifer, icon , etc...)

But expo hasn't flavor function.
I try to generate app.json per publish.

build app.json

First, we write JSON override config.

app-staging-override.json

{
  "expo": {
    "slug":"my-application-staging"
      "ios": {
    "bundleIdentifier": "com.foo.baz.staging"
      }
    }
  }
}

Next we write app.json generator script.

bin/generate-staging-app-json.js

const merge = require("deepmerge")
const baseAppJson = require("../app.json")
const override = require("../app-staging-override.json")
const merged = merge.all([baseAppJson, override])
console.log(JSON.stringify(merged, null, 2))

This script is so simple. this merge app.json and ../app-staging-override.json and output stdout.

Finally, append prebuild script on package.json.

"scripts:"{
  "prebuild:ios:staging": "node bin/generate-staging-app-json.js > app.staging.generated.json",
  "build:ios:staging": "expo build:ios --config app.staging.generated.json --type archive --release-channel=YOUR_STAGING_CHANNEL "
}

Top comments (0)