Skip to content

Commit 840b8e6

Browse files
authored
Merge pull request #1406 from appwrite/feat/ts-sdk-lockfiles
feat: add lock files to TS SDK templates
2 parents a913c51 + 5d0d5c2 commit 840b8e6

18 files changed

Lines changed: 10413 additions & 8 deletions

File tree

scripts/update-lockfiles.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
# Updates committed lock files for all TS-based SDK templates.
3+
# Run this whenever dependencies in a package.json.twig change.
4+
#
5+
# Usage:
6+
# ./scripts/update-lockfiles.sh # update all
7+
# ./scripts/update-lockfiles.sh web # update one (web | node | react-native | cli)
8+
9+
set -euo pipefail
10+
11+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
12+
TARGET="${1:-all}"
13+
WORKDIR="$(mktemp -d)"
14+
trap 'rm -rf "$WORKDIR"' EXIT
15+
16+
strip_twig() {
17+
# Replace {{ ... }} expressions with a safe placeholder so npm/bun
18+
# can parse the file as plain JSON. Only metadata fields use Twig
19+
# vars; dependency versions are all static.
20+
sed 's/{{[^}]*}}/PLACEHOLDER/g' "$1"
21+
}
22+
23+
update_npm() {
24+
local lang="$1"
25+
local extra_flags="${2:-}"
26+
local template="$ROOT/templates/$lang/package.json.twig"
27+
local dest="$ROOT/templates/$lang/package-lock.json"
28+
local dir="$WORKDIR/$lang"
29+
30+
echo "$lang (npm)"
31+
mkdir -p "$dir"
32+
strip_twig "$template" > "$dir/package.json"
33+
# shellcheck disable=SC2086
34+
(cd "$dir" && npm install --package-lock-only --ignore-scripts --silent $extra_flags 2>/dev/null)
35+
cp "$dir/package-lock.json" "$dest"
36+
echo " updated templates/$lang/package-lock.json"
37+
}
38+
39+
update_bun() {
40+
local dir="$WORKDIR/cli"
41+
local template="$ROOT/templates/cli/package.json.twig"
42+
local dest="$ROOT/templates/cli/bun.lock"
43+
44+
echo "→ cli (bun)"
45+
mkdir -p "$dir"
46+
strip_twig "$template" > "$dir/package.json"
47+
cd "$dir" && bun install --silent 2>/dev/null
48+
cp "$dir/bun.lock" "$dest"
49+
echo " updated templates/cli/bun.lock"
50+
}
51+
52+
case "$TARGET" in
53+
web) update_npm web ;;
54+
node) update_npm node ;;
55+
react-native) update_npm react-native --legacy-peer-deps ;;
56+
cli) update_bun ;;
57+
all)
58+
update_npm web
59+
update_npm node
60+
update_npm react-native --legacy-peer-deps
61+
update_bun
62+
;;
63+
*)
64+
echo "Unknown target: $TARGET. Use web | node | react-native | cli | all"
65+
exit 1
66+
;;
67+
esac
68+
69+
echo ""
70+
echo "Done. Review the diffs and commit the updated lock files."

src/SDK/Language/CLI.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public function getFiles(): array
203203
'destination' => 'bunfig.toml',
204204
'template' => 'cli/bunfig.toml',
205205
],
206+
[
207+
'scope' => 'copy',
208+
'destination' => 'bun.lock',
209+
'template' => 'cli/bun.lock',
210+
],
206211
[
207212
'scope' => 'default',
208213
'destination' => 'LICENSE.md',

src/SDK/Language/Node.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ public function getFiles(): array
250250
'destination' => 'src/models/{{ requestModel.name | caseKebab }}.ts',
251251
'template' => 'node/src/models/requestModel.ts.twig',
252252
],
253+
[
254+
'scope' => 'copy',
255+
'destination' => '.gitignore',
256+
'template' => 'node/.gitignore',
257+
],
258+
[
259+
'scope' => 'copy',
260+
'destination' => 'package-lock.json',
261+
'template' => 'node/package-lock.json',
262+
],
253263
];
254264
}
255265
}

src/SDK/Language/ReactNative.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ public function getFiles(): array
130130
'destination' => 'src/enums/{{ enum.name | caseKebab }}.ts',
131131
'template' => 'react-native/src/enums/enum.ts.twig',
132132
],
133+
[
134+
'scope' => 'copy',
135+
'destination' => '.gitignore',
136+
'template' => 'react-native/.gitignore',
137+
],
138+
[
139+
'scope' => 'copy',
140+
'destination' => 'package-lock.json',
141+
'template' => 'react-native/package-lock.json',
142+
],
133143
];
134144
}
135145

src/SDK/Language/Web.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public function getFiles(): array
150150
'destination' => 'src/enums/{{ enum.name | caseKebab }}.ts',
151151
'template' => 'web/src/enums/enum.ts.twig',
152152
],
153+
[
154+
'scope' => 'copy',
155+
'destination' => '.gitignore',
156+
'template' => 'web/.gitignore',
157+
],
158+
[
159+
'scope' => 'copy',
160+
'destination' => 'package-lock.json',
161+
'template' => 'web/package-lock.json',
162+
],
153163
];
154164
}
155165

templates/cli/.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
bun-version: "latest"
3232

3333
- name: Install Node dependencies
34-
run: npm install
34+
run: npm ci
3535

3636
- name: Build project
3737
run: npm run build
@@ -43,7 +43,7 @@ jobs:
4343
run: npm pack
4444

4545
- name: Install dependencies
46-
run: bun install
46+
run: bun install --frozen-lockfile
4747

4848
- name: Build all platform binaries
4949
run: |

templates/cli/.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
3333
- name: Install dependencies and build for Linux and Windows
3434
run: |
35-
bun install
35+
bun install --frozen-lockfile
3636
bun run linux-x64
3737
bun run linux-arm64
3838
bun run mac-x64

templates/cli/.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/
22
build/
33
.DS_Store
4-
bun.lock
5-
dist/
4+
dist/

0 commit comments

Comments
 (0)