File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed
Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ XC_CONFIG_FILE=" Versions.local.xcconfig"
5+ CONTEXT_JSON=" changelog-context.local.json"
6+
7+ get_key_from_xcconfig () {
8+ local xcconfig_file=" $1 "
9+ local key=" ${2:- APP_VERSION} "
10+
11+ if [[ ! -f " $xcconfig_file " ]]; then
12+ echo " Error: file not found: $xcconfig_file " >&2
13+ return 1
14+ fi
15+
16+ local value
17+ value=" $( sed -nE " s/^[[:space:]]*$key [[:space:]]*=[[:space:]]*(.*)\$ /\1/p" " $xcconfig_file " ) "
18+ value=" ${value%% [[:space:]]* } "
19+
20+ if [[ -z " $value " ]]; then
21+ echo " Error: $key not found in $xcconfig_file " >&2
22+ return 1
23+ fi
24+
25+ echo " $value "
26+ }
27+
28+ update_json_property () {
29+ local json_file=" $1 "
30+ local property=" $2 "
31+ local prop_value=" $3 "
32+
33+ if [[ ! -f " $json_file " ]]; then
34+ echo " Error: file not found: $json_file " >&2
35+ return 1
36+ fi
37+
38+ sed -i ' ' -E \
39+ ' s/^([[:space:]]*"' $property ' ":[[:space:]]*")[^"]*(")/\1' " $prop_value " ' \2/' \
40+ " $json_file "
41+ }
42+
43+ rename_json_property () {
44+ local json_file=" $1 "
45+ local old_name=" $2 "
46+ local new_name=" $3 "
47+
48+ if [[ ! -f " $json_file " ]]; then
49+ echo " Error: file not found: $json_file " >&2
50+ return 1
51+ fi
52+
53+ sed -i ' ' -E \
54+ ' s/^([[:space:]]*")' $old_name ' (":)/\1' " $new_name " ' \2/' \
55+ " $json_file "
56+ }
57+
58+
59+ version=" $( get_key_from_xcconfig $XC_CONFIG_FILE ) "
60+ update_json_property $CONTEXT_JSON " appVersion" " v$version "
61+
62+ if [ " $1 " == " all" ]; then
63+ rename_json_property $CONTEXT_JSON " excludeTypes" " _excludeTypes"
64+ else
65+ rename_json_property $CONTEXT_JSON " _excludeTypes" " excludeTypes"
66+ fi
67+
68+ npx conventional-changelog -p visualdiffer -c $CONTEXT_JSON
You can’t perform that action at this time.
0 commit comments