-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewVersion.sh
More file actions
executable file
·95 lines (84 loc) · 3.01 KB
/
newVersion.sh
File metadata and controls
executable file
·95 lines (84 loc) · 3.01 KB
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
#!/bin/bash
set -euo pipefail
# Check that jq is installed
if ! command -v jq &> /dev/null; then
echo "Error: 'jq' is required but not installed."
exit 1
fi
# Check that Node.js and npx are installed
if ! command -v npx &> /dev/null; then
echo "Error: 'npx' is required but not installed."
exit 1
fi
# Get and filter versions from npm using jq
versions_json=$(npm view create-nx-workspace versions --json)
filtered_versions=$(echo "$versions_json" | jq -r '
.[]
| select(
test("(canary|beta|pr|rc|alpha)") == false and
. != "0.0.1" and
. != "0.0.2" and
(
(split(".") | map(tonumber)) as $v |
($v[0] > 20) or
($v[0] == 20 and $v[1] >= 0)
)
)
')
# Store valid versions in array
versions=()
while IFS= read -r version; do
versions+=("$version")
done <<< "$filtered_versions"
lastVersion="7.6.2"
rebaseNeeded=false
for version in "${versions[@]}"; do
if [ -n "$(git branch --list "${version}")" ] || [ -n "$(git branch --list --remote "origin/${version}")" ];
then
echo "${version} already generated."
git checkout "${version}"
if [ ${rebaseNeeded} = true ]
then
git rebase --onto "${lastVersion}" HEAD~ "${version}" -X theirs
diffStat=$(git --no-pager diff HEAD~ --shortstat)
git push origin "${version}" -f
diffUrl="[${lastVersion}...${version}](https://github.com/danymarques/nx-cli-diff/compare/${lastVersion}...${version})"
git checkout main
sed -i.bak -e "/^${version}|/ d" README.md && rm README.md.bak
sed -i.bak -e 's/----|----|----/----|----|----\
NEWLINE/g' README.md && rm README.md.bak
sed -i.bak -e "s@NEWLINE@${version}|${diffUrl}|${diffStat}@" README.md && rm README.md.bak
git commit -a --amend --no-edit
git checkout "${version}"
fi
lastVersion=${version}
continue
fi
echo "Generate ${version}"
rebaseNeeded=true
git checkout -b "${version}"
rm -rf org
npx --yes create-nx-workspace@"${version}" --name=org --preset=angular-monorepo --appName=frontend --bundler=esbuild --style=scss --no-ssr --e2eTestRunner=playwright --nxCloud=skip
cd org
npx nx g @nx/angular:library --directory=libs/my-lib --publishable=true --importPath=@org/my-lib --no-interactive
npx nx add @nx/nest
npx nx g @nx/nest:app apps/backend --frontendProject frontend
cd ..
git add org
git commit -am "chore: version ${version}"
diffStat=$(git --no-pager diff HEAD~ --shortstat)
git push origin "${version}" -f
git checkout main
diffUrl="[${lastVersion}...${version}](https://github.com/danymarques/nx-cli-diff/compare/${lastVersion}...${version})"
# insert a row in the version table of the README
sed -i.bak "/^${version}|/ d" README.md && rm README.md.bak
sed -i.bak 's/----|----|----/----|----|----\
NEWLINE/g' README.md && rm README.md.bak
sed -i.bak "s@NEWLINE@${version}|${diffUrl}|${diffStat}@" README.md && rm README.md.bak
# commit
git commit -a --amend --no-edit
git checkout "${version}"
lastVersion=${version}
done
git checkout main
git push origin main -f