-
Notifications
You must be signed in to change notification settings - Fork 140
/
cli
executable file
·210 lines (167 loc) · 3.92 KB
/
cli
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env bash
PRETTIER_PATTERN=("./*.js" "src/**" "test/**" "db/**")
build() {
build:pkg "$@"
}
build:pkg() {
pnpm rollup -c rollup.config.js "$@"
}
# shellcheck disable=SC2120
build:visual() {
build:pkg
pnpm vite build -c test/visual/vite.config.js "$@" test/visual
}
build:www() {
pnpm vite build -c www/vite.config.js www/
}
dev() {
info:visual
}
info:bundlesize() {
build
tar -c dist | gzip > dist.tar.gz
du -h dist dist.tar.gz
rm dist.tar.gz
}
info:visual() {
pnpm vite --force -c vite.config.js test/visual/
}
info:www() {
pnpm vite -c vite.config.js www/
}
task:icons-shot() {
./cli build:www
pnpx playwright
}
task:fmt() {
pnpm prettier -u -w "${PRETTIER_PATTERN[@]}"
}
task:update-node() {
brew upgrade nodenv node-build
latest="$(node-build --definitions | sort -rn | head -n 1)"
echo "$latest" > .node-version
nodenv install --skip-existing "$(cat .node-version)"
corepack enable
node -e "
var packagejson = require('./package.json')
packagejson.packageManager = 'pnpm@$(pnpm -v)'
fs.writeFileSync(
'./package.json',
JSON.stringify(packagejson, null, 2)
)
"
}
task:setup-dev() {
brew install nodenv node-build
echo "eval \"\$(nodenv init -)\"" >> ".${SHELL/[a-z\/]*\//}rc"
nodenv install
corepack enable
pnpm install
}
task:update-readme-image() {
echo "...checking playwright install..."
pnpm playwright install
echo "...building website..."
pnpm vite build -l silent -c www/vite.config.js www/
echo "...running server..."
pnpm vite preview \
--host 0.0.0.0 \
--port 4173 \
--strictPort \
-c vite.config.js \
-l silent \
"www" &
echo "...taking screenshot..."
node --experimental-detect-module -e "
import { chromium } from 'playwright';
import { scheduler } from 'node:timers/promises';
const load = async page => {
for (let i = 0; i < 10; i++) {
try {
await page.goto('http://localhost:4173');
break;
}
catch(error) {
await scheduler.wait(500);
}
}
}
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({
vewport: { width: 1440, height: 800 },
deviceScaleFactor: 2
});
await load(page);
await page.locator('#lib').screenshot({ path: 'readme-image.png' });
await page.close();
await browser.close();
})()
"
echo "...killing server..."
ps | grep 'vite.*preview.*port.4173' | grep -v 'grep' | awk '{ print $1 }' | xargs kill
echo "...uploading image..."
pnpm wrangler r2 object put \
--file readme-image.png \
--content-type "image/png" \
react-social-icons/readme-image.png
echo '...cleaning up image...'
rm readme-image.png
echo "---Finished---"
}
test:lint() {
build --silent
pnpm eslint .eslintrc.cjs . db/*
}
test:publint() {
build --silent
pnpm publint .
}
test:fmt() {
pnpm prettier -u -c "${PRETTIER_PATTERN[@]}"
}
test:ts() {
pnpm tsc
}
test:unit() {
build --silent
pnpm vitest test/unit/*.test.js "$@"
}
test:src() {
pnpm vitest test/unit/src.test.js "$@"
}
test:codesplitting() {
build --silent
./test/codesplitting.sh
}
test:visual() {
scale=2
network=tiktok
out=./tmp/visual-test/shot.png
pnpx playwright screenshot \
--viewport-size="$((1250 * scale)), $((400 * scale))" \
"http://localhost:5173/?network=$network&knobs=false&scale=$scale" \
"$out"
}
test:dep() {
[[ ! -a 'package-lock.json' ]] || (
echo "Error: invalid package manager npm detected, this project uses pnpm." && exit 1
)
[[ ! -a 'yarn.lock' ]] || (
echo "Error: invalid package manager yarn detected, this project uses pnpm." && exit 1
)
}
test:() {
set -e
test:lint;
test:publint;
test:fmt;
test:ts;
test:unit --run --silent;
test:codesplitting;
test:dep
echo
echo Passed All Tests
set +e
}
"$@"