@cloudcommerce/cli 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/ci/bunny-config-base.sh +68 -12
- package/ci/bunny-prepare-ab.sh +35 -26
- package/ci/bunny-remove-ab.sh +54 -0
- package/ci/bunny-setup.sh +103 -0
- package/config/firebase.json +0 -13
- package/lib/cli.js +4 -12
- package/package.json +2 -2
- package/src/cli.ts +8 -12
package/.turbo/turbo-build.log
CHANGED
package/ci/bunny-config-base.sh
CHANGED
|
@@ -5,11 +5,16 @@ if [ -z "$BUNNYNET_API_KEY" ]; then
|
|
|
5
5
|
exit 1
|
|
6
6
|
fi
|
|
7
7
|
if [ $# -eq 0 ]; then
|
|
8
|
+
echo "Provide the Firebase project ID as the first argument"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
if [ $# -eq 1 ]; then
|
|
8
12
|
echo "Provide the domain as the first argument"
|
|
9
13
|
exit 1
|
|
10
14
|
fi
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
project_id=$1
|
|
17
|
+
domain=$2
|
|
13
18
|
|
|
14
19
|
response=$(curl --silent --request GET \
|
|
15
20
|
--url https://api.bunny.net/pullzone \
|
|
@@ -51,9 +56,7 @@ curl --silent --request POST \
|
|
|
51
56
|
"css"
|
|
52
57
|
],
|
|
53
58
|
"EnableAccessControlOriginHeader": true,
|
|
54
|
-
"DisableCookies":
|
|
55
|
-
"EnableOriginShield": true,
|
|
56
|
-
"CacheControlMaxAgeOverride": -1,
|
|
59
|
+
"DisableCookies": true,
|
|
57
60
|
"CacheControlPublicMaxAgeOverride": -1,
|
|
58
61
|
"BurstSize": 0,
|
|
59
62
|
"RequestLimit": 0,
|
|
@@ -70,11 +73,8 @@ curl --silent --request POST \
|
|
|
70
73
|
"EnableAvifVary": false,
|
|
71
74
|
"EnableCountryCodeVary": false,
|
|
72
75
|
"EnableMobileVary": false,
|
|
73
|
-
"EnableCookieVary":
|
|
74
|
-
"CookieVaryParameters": [
|
|
75
|
-
"bid",
|
|
76
|
-
"branch"
|
|
77
|
-
],
|
|
76
|
+
"EnableCookieVary": false,
|
|
77
|
+
"CookieVaryParameters": [],
|
|
78
78
|
"EnableHostnameVary": false,
|
|
79
79
|
"LoggingIPAnonymizationEnabled": true,
|
|
80
80
|
"EnableTLS1": true,
|
|
@@ -87,7 +87,6 @@ curl --silent --request POST \
|
|
|
87
87
|
"LogForwardingEnabled": false,
|
|
88
88
|
"LoggingSaveToStorage": false,
|
|
89
89
|
"FollowRedirects": false,
|
|
90
|
-
"PermaCacheStorageZoneId": 0,
|
|
91
90
|
"OriginRetries": 0,
|
|
92
91
|
"OriginConnectTimeout": 5,
|
|
93
92
|
"OriginResponseTimeout": 15,
|
|
@@ -112,7 +111,7 @@ curl --silent --request POST \
|
|
|
112
111
|
"LogForwardingFormat": 1,
|
|
113
112
|
"ShieldDDosProtectionType": 1,
|
|
114
113
|
"ShieldDDosProtectionEnabled": false,
|
|
115
|
-
"EnableRequestCoalescing":
|
|
114
|
+
"EnableRequestCoalescing": false,
|
|
116
115
|
"RequestCoalescingTimeout": 30,
|
|
117
116
|
"DisableLetsEncrypt": false,
|
|
118
117
|
"EnableBunnyImageAi": false,
|
|
@@ -162,8 +161,65 @@ configure_edge_rule "APIs bypass CDN cache" '
|
|
|
162
161
|
"Parameter1": ""
|
|
163
162
|
}
|
|
164
163
|
],
|
|
165
|
-
"TriggerMatchingType":
|
|
164
|
+
"TriggerMatchingType": 1,
|
|
166
165
|
"Description": "APIs bypass CDN cache",
|
|
167
166
|
"Enabled": true
|
|
168
167
|
}
|
|
169
168
|
'
|
|
169
|
+
|
|
170
|
+
configure_edge_rule "APIs bypass perma-cache" '
|
|
171
|
+
{
|
|
172
|
+
"ActionType": 15,
|
|
173
|
+
"ActionParameter1": null,
|
|
174
|
+
"ActionParameter2": null,
|
|
175
|
+
"Triggers": [
|
|
176
|
+
{
|
|
177
|
+
"Type": 0,
|
|
178
|
+
"PatternMatches": [
|
|
179
|
+
"*/_api/*",
|
|
180
|
+
"*/_feeds/*",
|
|
181
|
+
"*/.*/git/*",
|
|
182
|
+
"*/_analytics"
|
|
183
|
+
],
|
|
184
|
+
"PatternMatchingType": 0,
|
|
185
|
+
"Parameter1": ""
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"TriggerMatchingType": 1,
|
|
189
|
+
"Description": "APIs bypass perma-cache",
|
|
190
|
+
"Enabled": true
|
|
191
|
+
}
|
|
192
|
+
'
|
|
193
|
+
|
|
194
|
+
configure_edge_rule "SSR browser cache" '
|
|
195
|
+
{
|
|
196
|
+
"ActionType": 16,
|
|
197
|
+
"ActionParameter1": "120",
|
|
198
|
+
"ActionParameter2": null,
|
|
199
|
+
"Triggers": [
|
|
200
|
+
{
|
|
201
|
+
"Type": 0,
|
|
202
|
+
"PatternMatches": [
|
|
203
|
+
"*/_astro/*"
|
|
204
|
+
],
|
|
205
|
+
"PatternMatchingType": 2,
|
|
206
|
+
"Parameter1": ""
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"Type": 3,
|
|
210
|
+
"PatternMatches": [
|
|
211
|
+
"webp",
|
|
212
|
+
"png",
|
|
213
|
+
"jpg",
|
|
214
|
+
"woff2",
|
|
215
|
+
"mp4"
|
|
216
|
+
],
|
|
217
|
+
"PatternMatchingType": 2,
|
|
218
|
+
"Parameter1": ""
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
"TriggerMatchingType": 1,
|
|
222
|
+
"Description": "SSR browser cache",
|
|
223
|
+
"Enabled": true
|
|
224
|
+
}
|
|
225
|
+
'
|
package/ci/bunny-prepare-ab.sh
CHANGED
|
@@ -5,17 +5,17 @@ if [ -z "$BUNNYNET_API_KEY" ]; then
|
|
|
5
5
|
exit 1
|
|
6
6
|
fi
|
|
7
7
|
if [ $# -eq 0 ]; then
|
|
8
|
+
echo "Provide the Firebase project ID as the first argument"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
if [ $# -eq 1 ]; then
|
|
8
12
|
echo "Provide the domain as the first argument"
|
|
9
13
|
exit 1
|
|
10
14
|
fi
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
curl --request POST \
|
|
16
|
-
--url "https://api.bunny.net/purge?url=https://$domain/&async=false" \
|
|
17
|
-
--header "AccessKey: $BUNNYNET_API_KEY"
|
|
18
|
-
echo "> Purged https://$domain/ cache"
|
|
16
|
+
project_id=$1
|
|
17
|
+
domain=$2
|
|
18
|
+
channel_url=$3
|
|
19
19
|
|
|
20
20
|
base_uri=""
|
|
21
21
|
additional_patterns=()
|
|
@@ -27,16 +27,12 @@ fetch_and_purge() {
|
|
|
27
27
|
|
|
28
28
|
for slug in $slugs; do
|
|
29
29
|
if [ -n "$slug" ]; then
|
|
30
|
-
curl --request POST \
|
|
31
|
-
--url "https://api.bunny.net/purge?url=https://$domain/$slug" \
|
|
32
|
-
--header "AccessKey: $BUNNYNET_API_KEY"
|
|
33
30
|
additional_patterns+=("\"https://$domain/$slug\"")
|
|
34
|
-
echo "> Purged https://$domain/$slug cache"
|
|
35
31
|
fi
|
|
36
32
|
done
|
|
37
33
|
}
|
|
38
34
|
|
|
39
|
-
if [
|
|
35
|
+
if [ -n "$ECOM_STORE_ID" ]; then
|
|
40
36
|
base_uri="https://ecomplus.io/v2/:$ECOM_STORE_ID/"
|
|
41
37
|
|
|
42
38
|
fetch_and_purge 'products?fields=slug&sort=-sales&limit=2'
|
|
@@ -119,31 +115,31 @@ ab_testing_data="
|
|
|
119
115
|
\"Enabled\": true
|
|
120
116
|
}"
|
|
121
117
|
|
|
122
|
-
|
|
118
|
+
ab_testing_bypass_data="
|
|
123
119
|
{
|
|
124
|
-
\"ActionType\":
|
|
125
|
-
\"ActionParameter1\": \"
|
|
120
|
+
\"ActionType\": 3,
|
|
121
|
+
\"ActionParameter1\": \"0\",
|
|
126
122
|
\"ActionParameter2\": \"\",
|
|
127
123
|
\"Triggers\": [
|
|
128
124
|
{
|
|
129
|
-
\"Type\":
|
|
125
|
+
\"Type\": 0,
|
|
130
126
|
\"PatternMatches\": [
|
|
131
|
-
\"
|
|
127
|
+
\"https://$domain/\"
|
|
132
128
|
],
|
|
133
129
|
\"PatternMatchingType\": 0,
|
|
134
|
-
\"Parameter1\": \"
|
|
130
|
+
\"Parameter1\": \"\"
|
|
135
131
|
}
|
|
136
132
|
],
|
|
137
133
|
\"TriggerMatchingType\": 1,
|
|
138
|
-
\"Description\": \"A/B
|
|
134
|
+
\"Description\": \"A/B CDN cache bypass [$GIT_BRANCH]\",
|
|
139
135
|
\"Enabled\": true
|
|
140
136
|
}"
|
|
141
137
|
|
|
142
|
-
|
|
138
|
+
ab_testing_perma_bypass_data="
|
|
143
139
|
{
|
|
144
|
-
\"ActionType\":
|
|
145
|
-
\"ActionParameter1\":
|
|
146
|
-
\"ActionParameter2\":
|
|
140
|
+
\"ActionType\": 15,
|
|
141
|
+
\"ActionParameter1\": null,
|
|
142
|
+
\"ActionParameter2\": null,
|
|
147
143
|
\"Triggers\": [
|
|
148
144
|
{
|
|
149
145
|
\"Type\": 0,
|
|
@@ -155,10 +151,23 @@ ab_testing_bypass_data="
|
|
|
155
151
|
}
|
|
156
152
|
],
|
|
157
153
|
\"TriggerMatchingType\": 1,
|
|
158
|
-
\"Description\": \"A/B
|
|
154
|
+
\"Description\": \"A/B perma-cache bypass [$GIT_BRANCH]\",
|
|
159
155
|
\"Enabled\": true
|
|
160
156
|
}"
|
|
161
157
|
|
|
162
158
|
configure_edge_rule "A/B testing [$GIT_BRANCH]" "$ab_testing_data"
|
|
163
|
-
configure_edge_rule "A/B
|
|
164
|
-
configure_edge_rule "A/B
|
|
159
|
+
configure_edge_rule "A/B CDN cache bypass [$GIT_BRANCH]" "$ab_testing_bypass_data"
|
|
160
|
+
configure_edge_rule "A/B perma-cache bypass [$GIT_BRANCH]" "$ab_testing_perma_bypass_data"
|
|
161
|
+
|
|
162
|
+
curl --silent --request POST \
|
|
163
|
+
--url "https://api.bunny.net/purge?url=https://$domain/" \
|
|
164
|
+
--header "AccessKey: $BUNNYNET_API_KEY"
|
|
165
|
+
printf "\n> Purged https://$domain/ cache"
|
|
166
|
+
|
|
167
|
+
for slug_url in "${additional_patterns[@]}"; do
|
|
168
|
+
clean_url=${slug_url//\"/}
|
|
169
|
+
curl --silent --request POST \
|
|
170
|
+
--url "https://api.bunny.net/purge?url=$clean_url" \
|
|
171
|
+
--header "AccessKey: $BUNNYNET_API_KEY"
|
|
172
|
+
echo "> Purged $clean_url cache"
|
|
173
|
+
done
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
if [ -z "$BUNNYNET_API_KEY" ]; then
|
|
4
|
+
echo "BUNNYNET_API_KEY env var must be set"
|
|
5
|
+
exit 1
|
|
6
|
+
fi
|
|
7
|
+
if [ $# -eq 0 ]; then
|
|
8
|
+
echo "Provide the Firebase project ID as the first argument"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
if [ $# -eq 1 ]; then
|
|
12
|
+
echo "Provide the domain as the first argument"
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
project_id=$1
|
|
17
|
+
domain=$2
|
|
18
|
+
|
|
19
|
+
if [ -z "$GIT_BRANCH" ]; then
|
|
20
|
+
echo "GIT_BRANCH env not set, skipping edge rules removal"
|
|
21
|
+
exit 0
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
response=$(curl --silent --request GET \
|
|
25
|
+
--url https://api.bunny.net/pullzone \
|
|
26
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
27
|
+
--header 'accept: application/json')
|
|
28
|
+
|
|
29
|
+
pull_zone_id=$(echo $response | jq --arg domain "$domain" '[.[] | select(.Hostnames[].Value | contains($domain)).Id][0]')
|
|
30
|
+
if [ -z "$pull_zone_id" ]; then
|
|
31
|
+
echo "bunny.net pull zone not found for domain $domain"
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
edge_rules=$(echo $response | jq --arg id "$pull_zone_id" '.[] | select(.Id == ($id | tonumber)).EdgeRules')
|
|
36
|
+
|
|
37
|
+
remove_edge_rule() {
|
|
38
|
+
local description=$1
|
|
39
|
+
local found_rule=$(echo $edge_rules | jq --arg description "$description" '.[] | select(.Description == $description)')
|
|
40
|
+
local guid=$(echo $found_rule | jq -r '.Guid // empty')
|
|
41
|
+
|
|
42
|
+
if [ -n "$guid" ]; then
|
|
43
|
+
curl --silent --request DELETE \
|
|
44
|
+
--url "https://api.bunny.net/pullzone/$pull_zone_id/edgerules/$guid" \
|
|
45
|
+
--header "AccessKey: $BUNNYNET_API_KEY"
|
|
46
|
+
echo "> Removed edge rule \"$description\""
|
|
47
|
+
else
|
|
48
|
+
echo "> Edge rule \"$description\" not found"
|
|
49
|
+
fi
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
remove_edge_rule "A/B testing [$GIT_BRANCH]"
|
|
53
|
+
remove_edge_rule "A/B CDN cache bypass [$GIT_BRANCH]"
|
|
54
|
+
remove_edge_rule "A/B perma-cache bypass [$GIT_BRANCH]"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
if [ -z "$BUNNYNET_API_KEY" ]; then
|
|
4
|
+
echo "BUNNYNET_API_KEY env var must be set"
|
|
5
|
+
exit 1
|
|
6
|
+
fi
|
|
7
|
+
if [ $# -eq 0 ]; then
|
|
8
|
+
echo "Provide the Firebase project ID as the first argument"
|
|
9
|
+
exit 1
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
project_id=$1
|
|
13
|
+
domain=$2
|
|
14
|
+
|
|
15
|
+
storage_list=$(curl --silent --request GET \
|
|
16
|
+
--url https://api.bunny.net/storagezone \
|
|
17
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
18
|
+
--header 'accept: application/json')
|
|
19
|
+
|
|
20
|
+
storage_prefix="storefront-isr-"
|
|
21
|
+
storage_id=$(echo $storage_list | jq --arg prefix "$storage_prefix" '.[] | select(.Name | startswith($prefix)) | .Id')
|
|
22
|
+
|
|
23
|
+
if [ -z "$storage_id" ]; then
|
|
24
|
+
rand_suffix=$(printf "%06d" $((RANDOM % 10000000)))
|
|
25
|
+
storage_name="${storage_prefix}${rand_suffix}"
|
|
26
|
+
|
|
27
|
+
printf "\n"
|
|
28
|
+
response=$(curl --silent --request POST \
|
|
29
|
+
--url https://api.bunny.net/storagezone \
|
|
30
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
31
|
+
--header 'accept: application/json' \
|
|
32
|
+
--header 'content-type: application/json' \
|
|
33
|
+
--data "
|
|
34
|
+
{
|
|
35
|
+
\"Name\": \"$storage_name\",
|
|
36
|
+
\"Region\": \"DE\",
|
|
37
|
+
\"ReplicationRegions\": [
|
|
38
|
+
\"NY\",
|
|
39
|
+
\"BR\"
|
|
40
|
+
],
|
|
41
|
+
\"ZoneTier\": 1
|
|
42
|
+
}
|
|
43
|
+
")
|
|
44
|
+
|
|
45
|
+
storage_id=$(echo "$response" | jq -r '.Id')
|
|
46
|
+
printf "\n\n> Created storage zone \"$storage_name\" ($storage_id)"
|
|
47
|
+
fi
|
|
48
|
+
|
|
49
|
+
if [ -z "$storage_id" ]; then
|
|
50
|
+
echo "Could not create bunny.net storage zone"
|
|
51
|
+
exit 1
|
|
52
|
+
fi
|
|
53
|
+
|
|
54
|
+
origin_url="https://$project_id.web.app"
|
|
55
|
+
|
|
56
|
+
get_pull_zone_id() {
|
|
57
|
+
pull_zone_list=$(curl --silent --request GET \
|
|
58
|
+
--url https://api.bunny.net/pullzone \
|
|
59
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
60
|
+
--header 'accept: application/json')
|
|
61
|
+
|
|
62
|
+
pull_zone_id=$(echo $pull_zone_list | jq --arg url "$origin_url" '.[] | select(.OriginUrl == $url) | .Id')
|
|
63
|
+
}
|
|
64
|
+
get_pull_zone_id
|
|
65
|
+
|
|
66
|
+
if [ -z "$pull_zone_id" ]; then
|
|
67
|
+
printf "\n"
|
|
68
|
+
response=$(curl --silent --request POST \
|
|
69
|
+
--url https://api.bunny.net/pullzone \
|
|
70
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
71
|
+
--header 'accept: application/json' \
|
|
72
|
+
--header 'content-type: application/json' \
|
|
73
|
+
--data "
|
|
74
|
+
{
|
|
75
|
+
\"OriginUrl\": \"$origin_url\",
|
|
76
|
+
\"EnableGeoZoneUS\": true,
|
|
77
|
+
\"EnableGeoZoneEU\": true,
|
|
78
|
+
\"EnableGeoZoneASIA\": false,
|
|
79
|
+
\"EnableGeoZoneSA\": true,
|
|
80
|
+
\"EnableGeoZoneAF\": false,
|
|
81
|
+
\"Name\": \"$project_id\",
|
|
82
|
+
\"PermaCacheStorageZoneId\": $storage_id,
|
|
83
|
+
\"CacheControlMaxAgeOverride\": 31919000,
|
|
84
|
+
\"EnableOriginShield\": false
|
|
85
|
+
}
|
|
86
|
+
")
|
|
87
|
+
|
|
88
|
+
get_pull_zone_id
|
|
89
|
+
printf "\n\n> Created pull zone \"$pull_zone_id\" with origin \"$origin_url\""
|
|
90
|
+
fi
|
|
91
|
+
|
|
92
|
+
if [ -n "$domain" ]; then
|
|
93
|
+
printf "\n"
|
|
94
|
+
curl --silent --request POST \
|
|
95
|
+
--url https://api.bunny.net/pullzone/$pull_zone_id/addHostname \
|
|
96
|
+
--header "AccessKey: $BUNNYNET_API_KEY" \
|
|
97
|
+
--header 'content-type: application/json' \
|
|
98
|
+
--data "{\"Hostname\":\"$domain\"}"
|
|
99
|
+
printf "\n\n> Added hostname \"$domain\" to pull zone"
|
|
100
|
+
|
|
101
|
+
script_dir=$(dirname $0)
|
|
102
|
+
bash $script_dir/bunny-config-base.sh $domain
|
|
103
|
+
fi
|
package/config/firebase.json
CHANGED
|
@@ -88,19 +88,6 @@
|
|
|
88
88
|
}
|
|
89
89
|
],
|
|
90
90
|
"headers": [
|
|
91
|
-
{
|
|
92
|
-
"source": "/**",
|
|
93
|
-
"headers": [
|
|
94
|
-
{
|
|
95
|
-
"key": "Set-Cookie",
|
|
96
|
-
"value": "bid={{BUILD_ID}}"
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"key": "Set-Cookie",
|
|
100
|
-
"value": "branch={{GIT_BRANCH}}"
|
|
101
|
-
}
|
|
102
|
-
]
|
|
103
|
-
},
|
|
104
91
|
{
|
|
105
92
|
"source": "/img/**",
|
|
106
93
|
"headers": [
|
package/lib/cli.js
CHANGED
|
@@ -10,14 +10,12 @@ import build, { prepareCodebases } from './build.js';
|
|
|
10
10
|
import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud.js';
|
|
11
11
|
import createGhSecrets from './setup-gh.js';
|
|
12
12
|
|
|
13
|
-
if (!process.env.FIREBASE_PROJECT_ID && !process.env.
|
|
13
|
+
if (!process.env.FIREBASE_PROJECT_ID && !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
14
14
|
const pwd = process.cwd();
|
|
15
15
|
dotenv.config();
|
|
16
16
|
dotenv.config({ path: joinPath(pwd, 'functions/.env') });
|
|
17
17
|
}
|
|
18
|
-
const {
|
|
19
|
-
FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS, GITHUB_TOKEN, BUILD_ID, DEPLOY_RAND, GIT_BRANCH,
|
|
20
|
-
} = process.env;
|
|
18
|
+
const { FIREBASE_PROJECT_ID, GOOGLE_APPLICATION_CREDENTIALS, GITHUB_TOKEN } = process.env;
|
|
21
19
|
// https://github.com/google/zx/issues/124
|
|
22
20
|
process.env.FORCE_COLOR = '3';
|
|
23
21
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
@@ -47,14 +45,8 @@ if (projectId) {
|
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
export default async () => {
|
|
50
|
-
const buildId = BUILD_ID || DEPLOY_RAND || `${Math.random()}`;
|
|
51
48
|
const baseConfigDir = joinPath(__dirname, '..', 'config');
|
|
52
49
|
await fs.copy(baseConfigDir, pwd);
|
|
53
|
-
const firebaseJsonPath = joinPath(pwd, 'firebase.json');
|
|
54
|
-
const firebaseJson = fs.readFileSync(firebaseJsonPath, 'utf8')
|
|
55
|
-
.replace('{{BUILD_ID}}', buildId)
|
|
56
|
-
.replace('{{GIT_BRANCH}}', GIT_BRANCH || '_');
|
|
57
|
-
fs.writeFileSync(firebaseJsonPath, firebaseJson);
|
|
58
50
|
const userConfigDir = joinPath(pwd, 'conf');
|
|
59
51
|
if (fs.existsSync(userConfigDir) && fs.lstatSync(userConfigDir).isDirectory()) {
|
|
60
52
|
await fs.copy(userConfigDir, pwd);
|
|
@@ -68,9 +60,9 @@ export default async () => {
|
|
|
68
60
|
}
|
|
69
61
|
if (userFirebaseConfig) {
|
|
70
62
|
const deepmerge = Deepmerge();
|
|
71
|
-
const baseFirebaseConfig = JSON.parse(
|
|
63
|
+
const baseFirebaseConfig = JSON.parse(fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'));
|
|
72
64
|
const mergedConfig = deepmerge(baseFirebaseConfig, userFirebaseConfig);
|
|
73
|
-
fs.writeFileSync(
|
|
65
|
+
fs.writeFileSync(joinPath(pwd, 'firebase.json'), JSON.stringify(mergedConfig, null, 2));
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
68
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcommerce/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "E-Com Plus Cloud Commerce CLI tools",
|
|
6
6
|
"bin": {
|
|
7
7
|
"cloudcommerce": "./bin/run.mjs"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"md5": "^2.3.0",
|
|
30
30
|
"typescript": "~5.2.2",
|
|
31
31
|
"zx": "^7.2.3",
|
|
32
|
-
"@cloudcommerce/api": "2.
|
|
32
|
+
"@cloudcommerce/api": "2.2.0"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "bash ../../scripts/build-lib.sh"
|
package/src/cli.ts
CHANGED
|
@@ -14,7 +14,7 @@ import build, { prepareCodebases } from './build';
|
|
|
14
14
|
import { siginGcloudAndSetIAM, createServiceAccountKey } from './setup-gcloud';
|
|
15
15
|
import createGhSecrets from './setup-gh';
|
|
16
16
|
|
|
17
|
-
if (!process.env.FIREBASE_PROJECT_ID && !process.env.
|
|
17
|
+
if (!process.env.FIREBASE_PROJECT_ID && !process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
18
18
|
const pwd = process.cwd();
|
|
19
19
|
dotenv.config();
|
|
20
20
|
dotenv.config({ path: joinPath(pwd, 'functions/.env') });
|
|
@@ -23,9 +23,6 @@ const {
|
|
|
23
23
|
FIREBASE_PROJECT_ID,
|
|
24
24
|
GOOGLE_APPLICATION_CREDENTIALS,
|
|
25
25
|
GITHUB_TOKEN,
|
|
26
|
-
BUILD_ID,
|
|
27
|
-
DEPLOY_RAND,
|
|
28
|
-
GIT_BRANCH,
|
|
29
26
|
} = process.env;
|
|
30
27
|
|
|
31
28
|
// https://github.com/google/zx/issues/124
|
|
@@ -62,14 +59,8 @@ if (projectId) {
|
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
export default async () => {
|
|
65
|
-
const buildId = BUILD_ID || DEPLOY_RAND || `${Math.random()}`;
|
|
66
62
|
const baseConfigDir = joinPath(__dirname, '..', 'config');
|
|
67
63
|
await fs.copy(baseConfigDir, pwd);
|
|
68
|
-
const firebaseJsonPath = joinPath(pwd, 'firebase.json');
|
|
69
|
-
const firebaseJson = fs.readFileSync(firebaseJsonPath, 'utf8')
|
|
70
|
-
.replace('{{BUILD_ID}}', buildId)
|
|
71
|
-
.replace('{{GIT_BRANCH}}', GIT_BRANCH || '_');
|
|
72
|
-
fs.writeFileSync(firebaseJsonPath, firebaseJson);
|
|
73
64
|
const userConfigDir = joinPath(pwd, 'conf');
|
|
74
65
|
if (fs.existsSync(userConfigDir) && fs.lstatSync(userConfigDir).isDirectory()) {
|
|
75
66
|
await fs.copy(userConfigDir, pwd);
|
|
@@ -85,9 +76,14 @@ export default async () => {
|
|
|
85
76
|
}
|
|
86
77
|
if (userFirebaseConfig) {
|
|
87
78
|
const deepmerge = Deepmerge();
|
|
88
|
-
const baseFirebaseConfig = JSON.parse(
|
|
79
|
+
const baseFirebaseConfig = JSON.parse(
|
|
80
|
+
fs.readFileSync(joinPath(baseConfigDir, 'firebase.json'), 'utf8'),
|
|
81
|
+
);
|
|
89
82
|
const mergedConfig = deepmerge(baseFirebaseConfig, userFirebaseConfig);
|
|
90
|
-
fs.writeFileSync(
|
|
83
|
+
fs.writeFileSync(
|
|
84
|
+
joinPath(pwd, 'firebase.json'),
|
|
85
|
+
JSON.stringify(mergedConfig, null, 2),
|
|
86
|
+
);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
}
|