Skip to content

Commit

Permalink
Refactor script to add Intercom api keys (#3426)
Browse files Browse the repository at this point in the history
* Refactor

* Revert capacitor config mod

* changelog
  • Loading branch information
mariopino authored and faboweb committed Jan 16, 2020
1 parent f417656 commit 496a5cf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions changes/mario_3425-refactor-intercom-keys-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Added] [#3425](https://github.com/cosmos/lunie/issues/3425) Refactor script to add Intercom API keys at the top-level capacitor config file. @mariopino
42 changes: 22 additions & 20 deletions tasks/add-intercom-key.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
const fs = require("fs")

const iosConfigPath = "ios/App/App/capacitor.config.json"
const androidConfigPath = "android/app/src/main/assets/capacitor.config.json"

/*
* this script adds the required intercom keys to the capacitor configs
* this script adds the required intercom keys to the capacitor config
* this is done in this script to avoid checking the keys into GitHub
*
* Usage:
*
* node tasks/add-intercom-key.js INTERCOM_APP_ID INTERCOM_ANDROID_KEY INTERCOM_IOS_KEY
*
*/

const fs = require("fs")

const capacitorConfigPath = "capacitor.config.json"

function main() {
const intercomAppId = process.argv[2]
const androidKey = process.argv[3]
const iosKey = process.argv[4]

const iosConfig = JSON.parse(fs.readFileSync(iosConfigPath))
if (!iosConfig.plugins) {
iosConfigPath.plugins = {}
const capacitorConfig = JSON.parse(fs.readFileSync(capacitorConfigPath))

if (!capacitorConfig.plugins) {
capacitorConfigPath.plugins = {}
}
iosConfig.plugins.IntercomPlugin = {

capacitorConfig.plugins.IntercomPlugin = {
"android-apiKey": androidKey,
"android-appId": intercomAppId,
"ios-apiKey": iosKey,
"ios-appId": intercomAppId
}
fs.writeFileSync(iosConfigPath, JSON.stringify(iosConfig))

const androidConfig = JSON.parse(fs.readFileSync(androidConfigPath))
if (!androidConfig.plugins) {
androidConfig.plugins = {}
}
androidConfig.plugins.IntercomPlugin = {
"android-apiKey": androidKey,
"android-appId": intercomAppId
}
fs.writeFileSync(androidConfigPath, JSON.stringify(androidConfig))
fs.writeFileSync(
capacitorConfigPath,
JSON.stringify(capacitorConfig, null, 2)
)
}

main()

0 comments on commit 496a5cf

Please sign in to comment.