forked from teovillanueva/shadcn-ui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.sh
executable file
·169 lines (132 loc) · 5.1 KB
/
generate.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
rm -rf download
git clone https://github.com/shadcn/next-template download
pushd ./download
npx shadcn-ui add --overwrite --yes accordion alert alert-dialog aspect-ratio avatar badge button calendar card checkbox collapsible command context-menu dialog dropdown-menu form hover-card input label menubar navigation-menu popover progress radio-group scroll-area select separator sheet skeleton slider switch table tabs textarea toast toggle tooltip
popd
version=$(cat package.json | jq ".version")
templatePackageJson=$(cat download/package.json)
# --- Main Package ---
mainPackageDir=packages/shadcn-ui
mainPackageSrcDir=$mainPackageDir/src
mainPackageIndexPath=$mainPackageSrcDir/index.ts
mainPackagePackageJsonPath=$mainPackageDir/package.json
mkdir -p $mainPackageDir
mkdir -p $mainPackageSrcDir
rm -rf $mainPackageIndexPath
touch $mainPackageIndexPath
touch $mainPackagePackageJsonPath
mainPackagePackageJsonContent="{
\"name\": \"@teovilla/shadcn-ui-react\",
\"version\": $version,
\"main\": \"src/index.ts\",
\"dependencies\": {
\"@teovilla/shadcn-ui-react-lib\": $version
},
\"scripts\": {
\"publish-package\": \"npm publish --access public\"
},
\"publishConfig\": {
\"registry\": \"https://registry.npmjs.org/\",
\"access\": \"public\"
},
\"repository\": \"https://github.com/teovillanueva/shadcn-ui-react\",
\"author\": \"Teodoro Villanueva <[email protected]> (https://github.com/teovillanueva)\",
\"bugs\": {
\"url\": \"https://github.com/teovillanueva/shadcn-ui-react/issues\"
},
\"homepage\": \"https://github.com/teovillanueva/shadcn-ui-react#readme\"
}"
# --- LIB Package ---
libDir=packages/lib
libSrcDir=$libDir/src
libIndexPath=$libSrcDir/index.ts
libPackageJsonPath=$libDir/package.json
libPackageJsonContent="{
\"name\": \"@teovilla/shadcn-ui-react-lib\",
\"version\": $version,
\"main\": \"src/index.ts\",
\"scripts\": {
\"publish-package\": \"npm publish --access public\"
},
\"publishConfig\": {
\"registry\": \"https://registry.npmjs.org/\",
\"access\": \"public\"
},
\"repository\": \"https://github.com/teovillanueva/shadcn-ui-react\",
\"author\": \"Teodoro Villanueva <[email protected]> (https://github.com/teovillanueva)\",
\"bugs\": {
\"url\": \"https://github.com/teovillanueva/shadcn-ui-react/issues\"
},
\"homepage\": \"https://github.com/teovillanueva/shadcn-ui-react#readme\"
}"
mkdir -p $libDir
mkdir -p $libSrcDir
touch $libPackageJsonPath
rm -rf $libIndexPath
touch $libIndexPath
for file in ./download/lib/*; do
filename=$(basename -- "$file")
component="${filename%.*}"
imports=$(awk -F '\t' '/import/' "$file")
while IFS= read -r line; do
import="${line##* }"
packageDepVersion=$(echo "$templatePackageJson" | jq ".dependencies[$import]")
libPackageJsonContent=$(echo "$libPackageJsonContent" | jq ".dependencies[$import] = $packageDepVersion")
done <<<"$imports"
cp "$file" packages/lib/src
echo "export * from \"./$component\"" >>$libIndexPath
done
echo "$libPackageJsonContent" >$libPackageJsonPath
# --- Component Packages ---
for file in ./download/components/ui/*; do
filename=$(basename -- "$file")
component="${filename%.*}"
packageDir="packages/$component"
packageSrcDir="$packageDir/src"
packageIndexPath="$packageSrcDir/index.tsx"
packageJsonPath="$packageDir/package.json"
packageName=@teovilla/shadcn-ui-react-$component
mkdir -p "packages/$component"
touch "$packageJsonPath"
packageJsonContent="{
\"name\": \"$packageName\",
\"version\": $version,
\"main\": \"src/index.tsx\",
\"scripts\": {
\"publish-package\": \"npm publish --access public\"
},
\"dependencies\": {
\"@teovilla/shadcn-ui-react-lib\": $version
},
\"publishConfig\": {
\"registry\": \"https://registry.npmjs.org/\",
\"access\": \"public\"
},
\"repository\": \"https://github.com/teovillanueva/shadcn-ui-react\",
\"author\": \"Teodoro Villanueva <[email protected]> (https://github.com/teovillanueva)\",
\"bugs\": {
\"url\": \"https://github.com/teovillanueva/shadcn-ui-react/issues\"
},
\"homepage\": \"https://github.com/teovillanueva/shadcn-ui-react#readme\"
}"
mainPackagePackageJsonContent=$(echo "$mainPackagePackageJsonContent" | jq ".dependencies[\"$packageName\"] = $version")
mkdir -p "$packageSrcDir"
cp "$file" "$packageIndexPath"
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's/\@\/lib\/utils/\@teovilla\/shadcn-ui-react-lib/' "$packageIndexPath"
else
sed -i 's/\@\/lib\/utils/\@teovilla\/shadcn-ui-react-lib/' "$packageIndexPath"
fi
imports=$(awk -F '\t' '/import/' "$packageIndexPath")
while IFS= read -r line; do
import="${line##* }"
if test "$import" != "\"@teovilla/shadcn-ui-react-lib\""; then
packageDepVersion=$(echo "$templatePackageJson" | jq ".dependencies[$import]")
packageJsonContent=$(echo "$packageJsonContent" | jq ".dependencies[$import] = $packageDepVersion")
fi
done <<<"$imports"
echo "$packageJsonContent" >"$packageJsonPath"
echo "export * from \"$packageName\"" >>$mainPackageIndexPath
done
echo "$mainPackagePackageJsonContent" >"$mainPackagePackageJsonPath"