Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/scripts/max-line-length.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ for glob in "${glob_array[@]}"; do
if [ $? -eq 1 ]; then
found_lines=1
fi
done < <(find "$folder_path" -type f -name "$glob" -print0)
done < <(find "$folder_path" -type f -name "$glob" \
! -name "*.lock" ! -name "*.lock.*" ! -name "*-lock.*" -print0)
done

# Exit with appropriate code
Expand Down
71 changes: 59 additions & 12 deletions scripts/update-lockfiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,55 @@ strip_twig() {
sed 's/{{[^}]*}}/PLACEHOLDER/g' "$1"
}

replace_first() {
# POSIX-portable first-match replacement (no GNU sed required).
# Exits with code 2 if the pattern is not found.
# Usage: replace_first <file> <literal_old> <literal_new>
local file="$1" old="$2" new="$3"
awk -v o="$old" -v n="$new" -v done=0 \
'{ if (!done && index($0, o)) { sub(o, n); done=1 } print } END { exit(done ? 0 : 2) }' \
"$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
}

restore_twig_npm() {
# Replace PLACEHOLDER values in package-lock.json with the correct
# Twig expressions extracted from the corresponding package.json.twig.
# PLACEHOLDER appears in: root "name", root "version",
# packages[""] "name", "version", "license".
local lockfile="$1"
local twig_name="$2"

replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"'
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"'
replace_first "$lockfile" '"license": "PLACEHOLDER"' '"license": "{{ sdk.license }}"'

if grep -q '"PLACEHOLDER"' "$lockfile"; then
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
return 1
fi
}
Comment thread
ChiragAgg5k marked this conversation as resolved.

restore_twig_bun() {
# Replace PLACEHOLDER in bun.lock with the correct Twig expression.
local lockfile="$1"
local twig_name="$2"

replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""

if grep -q '"PLACEHOLDER"' "$lockfile"; then
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
return 1
fi
}

update_npm() {
local lang="$1"
local extra_flags="${2:-}"
local twig_name="$3"
local template="$ROOT/templates/$lang/package.json.twig"
local dest="$ROOT/templates/$lang/package-lock.json"
local dest="$ROOT/templates/$lang/package-lock.json.twig"
local dir="$WORKDIR/$lang"

echo "→ $lang (npm)"
Expand All @@ -33,32 +77,35 @@ update_npm() {
# shellcheck disable=SC2086
(cd "$dir" && npm install --package-lock-only --ignore-scripts --silent $extra_flags 2>/dev/null)
cp "$dir/package-lock.json" "$dest"
echo " updated templates/$lang/package-lock.json"
restore_twig_npm "$dest" "$twig_name"
echo " updated templates/$lang/package-lock.json.twig"
}

update_bun() {
local twig_name="$1"
local dir="$WORKDIR/cli"
local template="$ROOT/templates/cli/package.json.twig"
local dest="$ROOT/templates/cli/bun.lock"
local dest="$ROOT/templates/cli/bun.lock.twig"

echo "→ cli (bun)"
mkdir -p "$dir"
strip_twig "$template" > "$dir/package.json"
cd "$dir" && bun install --silent 2>/dev/null
cp "$dir/bun.lock" "$dest"
echo " updated templates/cli/bun.lock"
restore_twig_bun "$dest" "$twig_name"
echo " updated templates/cli/bun.lock.twig"
}

case "$TARGET" in
web) update_npm web ;;
node) update_npm node ;;
react-native) update_npm react-native --legacy-peer-deps ;;
cli) update_bun ;;
web) update_npm web "" "{{ language.params.npmPackage }}" ;;
node) update_npm node "" "{{ language.params.npmPackage | caseDash }}" ;;
react-native) update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}" ;;
cli) update_bun "{{ language.params.npmPackage|caseDash }}" ;;
all)
update_npm web
update_npm node
update_npm react-native --legacy-peer-deps
update_bun
update_npm web "" "{{ language.params.npmPackage }}"
update_npm node "" "{{ language.params.npmPackage | caseDash }}"
update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}"
update_bun "{{ language.params.npmPackage|caseDash }}"
;;
*)
echo "Unknown target: $TARGET. Use web | node | react-native | cli | all"
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public function getFiles(): array
'template' => 'cli/bunfig.toml',
],
[
'scope' => 'copy',
'scope' => 'default',
'destination' => 'bun.lock',
'template' => 'cli/bun.lock',
'template' => 'cli/bun.lock.twig',
],
[
'scope' => 'default',
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ public function getFiles(): array
'template' => 'node/.gitignore',
],
[
'scope' => 'copy',
'scope' => 'default',
'destination' => 'package-lock.json',
'template' => 'node/package-lock.json',
'template' => 'node/package-lock.json.twig',
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/ReactNative.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public function getFiles(): array
'template' => 'react-native/.gitignore',
],
[
'scope' => 'copy',
'scope' => 'default',
'destination' => 'package-lock.json',
'template' => 'react-native/package-lock.json',
'template' => 'react-native/package-lock.json.twig',
],
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Language/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public function getFiles(): array
'template' => 'web/.gitignore',
],
[
'scope' => 'copy',
'scope' => 'default',
'destination' => 'package-lock.json',
'template' => 'web/package-lock.json',
'template' => 'web/package-lock.json.twig',
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion templates/cli/bun.lock → templates/cli/bun.lock.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"configVersion": 1,
"workspaces": {
"": {
"name": "PLACEHOLDER",
"name": "{{ language.params.npmPackage|caseDash }}",
"dependencies": {
"@appwrite.io/console": "*",
"chalk": "4.1.2",
Expand Down
8 changes: 8 additions & 0 deletions templates/cli/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ class Client {
return this;
}

/**
* Get Headers
*
* Returns a copy of the current request headers, including any
* authentication headers. Handle with care.
*
* @returns {Headers}
*/
getHeaders(): Headers {
return { ...this.headers };
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions templates/node/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ class Client {
return this;
}

/**
* Get Headers
*
* Returns a copy of the current request headers, including any
* authentication headers. Handle with care.
*
* @returns {Headers}
*/
getHeaders(): Headers {
return { ...this.headers };
}
Expand Down
4 changes: 3 additions & 1 deletion templates/react-native/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
node_modules/
dist/*
!dist/cjs/
!dist/cjs/package.json
!dist/esm/
dist/cjs/*
dist/esm/*
!dist/cjs/package.json
!dist/esm/package.json
types/
.DS_Store

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions templates/react-native/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ class Client {
{% endfor %}
};

/**
* Get Headers
*
* Returns a copy of the current request headers, including any
* authentication headers. Handle with care.
*
* @returns {Headers}
*/
getHeaders(): Headers {
return { ...this.headers };
}
Expand Down
4 changes: 3 additions & 1 deletion templates/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
node_modules/
dist/*
!dist/cjs/
!dist/cjs/package.json
!dist/esm/
dist/cjs/*
dist/esm/*
!dist/cjs/package.json
!dist/esm/package.json
types/
.DS_Store

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions templates/web/src/client.ts.twig
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ class Client {
{%~ endfor %}
};

/**
* Get Headers
*
* Returns a copy of the current request headers, including any
* authentication headers. Handle with care.
*
* @returns {Headers}
*/
getHeaders(): Headers {
return { ...this.headers };
}
Expand Down
Loading