forked from digidem/release-automations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.config.js
126 lines (110 loc) · 2.37 KB
/
app.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// @ts-check
const { execSync } = require('node:child_process')
const packageJson = require('./package.json')
/** @import {ConfigContext, ExpoConfig} from 'expo/config' */
module.exports = dynamicConfig
/**
* @param {ConfigContext} configContext
* @returns {Partial<ExpoConfig>}
*/
function dynamicConfig(configContext) {
const appVariant = process.env.APP_VARIANT || 'development'
const version = getVersion(packageJson.version, appVariant)
const name = getDisplayedName(appVariant)
const appId = getAppId(appVariant)
const result = {
...configContext.config,
version,
name,
android: {
...configContext.config.android,
package: appId,
},
ios: {
...configContext.config.ios,
bundleIdentifier: appId,
},
}
return result
}
/**
* @param {string} packageJsonVersion
* @param {string} variant
*
* @returns {string}
*/
function getVersion(packageJsonVersion, variant) {
const base = packageJsonVersion.replace(/-.*/, '')
let suffix = ''
switch (variant) {
case 'development': {
suffix = '-dev'
break
}
case 'releaseCandidate': {
suffix = '-rc'
break
}
case 'production': {
break
}
default: {
throw new Error(`Invalid variant: ${variant}`)
}
}
if (variant !== 'production') {
try {
// SHA of commit this version was built from
const commitSha =
process.env.EAS_BUILD_GIT_COMMIT_HASH ||
execSync('git rev-parse HEAD').toString().trim()
const commitShaShort = commitSha.slice(0, 7)
suffix += `+${commitShaShort}`
} catch (e) {
// Expo-doctor runs in a temp directory which is not a git repo, so this command will fail.
}
}
return base + suffix
}
/**
* @param {string} variant
* @returns {string}
*/
function getDisplayedName(variant) {
let base = 'Release Automations Example'
switch (variant) {
case 'development': {
return `${base} (Dev)`
}
case 'releaseCandidate': {
return `${base} (RC)`
}
case 'production': {
return base
}
default: {
throw new Error(`Invalid variant: ${variant}`)
}
}
}
/**
* @param {string} variant
* @returns {string}
*/
function getAppId(variant) {
let base = 'com.andrewchou.releaseautomationsexample'
switch (variant) {
case 'development': {
return `${base}.dev`
}
case 'releaseCandidate': {
return `${base}.rc`
}
case 'production': {
return base
}
default: {
throw new Error(`Invalid variant: ${variant}`)
}
}
}