mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 01:58:39 +02:00
Simplify generate-sources.sh
This commit is contained in:
@@ -8,74 +8,36 @@
|
|||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./flatpak/generate-sources.sh
|
# ./flatpak/generate-sources.sh
|
||||||
#
|
|
||||||
# This script generates:
|
|
||||||
# flatpak/cargo-sources.json - Cargo crate sources from Cargo.lock
|
|
||||||
# flatpak/node-sources.json - npm package sources from package-lock.json
|
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
|
||||||
# Check for flatpak-cargo-generator.py
|
# Generate cargo-sources.json
|
||||||
CARGO_GENERATOR=""
|
python3 "$SCRIPT_DIR/flatpak-builder-tools/cargo/flatpak-cargo-generator.py" \
|
||||||
if command -v flatpak-cargo-generator.py &>/dev/null; then
|
-o "$SCRIPT_DIR/cargo-sources.json" "$REPO_ROOT/Cargo.lock"
|
||||||
CARGO_GENERATOR="flatpak-cargo-generator.py"
|
|
||||||
elif [ -f "$SCRIPT_DIR/flatpak-builder-tools/cargo/flatpak-cargo-generator.py" ]; then
|
|
||||||
CARGO_GENERATOR="python3 $SCRIPT_DIR/flatpak-builder-tools/cargo/flatpak-cargo-generator.py"
|
|
||||||
else
|
|
||||||
echo "Error: flatpak-cargo-generator.py not found."
|
|
||||||
echo "Either install it in PATH or clone flatpak-builder-tools:"
|
|
||||||
echo " cd $SCRIPT_DIR && git clone https://github.com/flatpak/flatpak-builder-tools"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check for flatpak-node-generator
|
# Generate node-sources.json from a patched copy of the lockfile.
|
||||||
if ! command -v flatpak-node-generator &>/dev/null; then
|
# npm omits resolved/integrity for some workspace deps, and
|
||||||
echo "Error: flatpak-node-generator not found."
|
# flatpak-node-generator can't handle workspace link entries.
|
||||||
echo "Install it with: pip install flatpak-node-generator"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Generating cargo-sources.json..."
|
|
||||||
$CARGO_GENERATOR -o "$SCRIPT_DIR/cargo-sources.json" "$REPO_ROOT/Cargo.lock"
|
|
||||||
echo " Done: flatpak/cargo-sources.json"
|
|
||||||
|
|
||||||
echo "Generating node-sources.json..."
|
|
||||||
|
|
||||||
# npm sometimes omits `resolved` and `integrity` fields from the lockfile for
|
|
||||||
# nested dependencies inside workspace packages. flatpak-node-generator needs
|
|
||||||
# these fields to know which tarballs to download. We fix the lockfile in a temp
|
|
||||||
# copy before running the generator.
|
|
||||||
#
|
|
||||||
# We also strip workspace link entries (no download needed for local packages).
|
|
||||||
TMPDIR=$(mktemp -d)
|
TMPDIR=$(mktemp -d)
|
||||||
trap 'rm -rf "$TMPDIR"' EXIT
|
trap 'rm -rf "$TMPDIR"' EXIT
|
||||||
|
|
||||||
cp "$REPO_ROOT/package-lock.json" "$TMPDIR/package-lock.json"
|
cp "$REPO_ROOT/package-lock.json" "$TMPDIR/package-lock.json"
|
||||||
cp "$REPO_ROOT/package.json" "$TMPDIR/package.json"
|
cp "$REPO_ROOT/package.json" "$TMPDIR/package.json"
|
||||||
|
|
||||||
# Add missing resolved/integrity fields
|
|
||||||
node "$SCRIPT_DIR/fix-lockfile.mjs" "$TMPDIR/package-lock.json"
|
node "$SCRIPT_DIR/fix-lockfile.mjs" "$TMPDIR/package-lock.json"
|
||||||
|
|
||||||
# Strip workspace link entries (flatpak-node-generator doesn't handle them)
|
|
||||||
node -e "
|
node -e "
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const p = process.argv[1];
|
const p = process.argv[1];
|
||||||
const data = JSON.parse(fs.readFileSync(p, 'utf-8'));
|
const d = JSON.parse(fs.readFileSync(p, 'utf-8'));
|
||||||
const packages = data.packages || {};
|
for (const [name, info] of Object.entries(d.packages || {})) {
|
||||||
for (const [name, info] of Object.entries(packages)) {
|
if (name && (info.link || !info.resolved)) delete d.packages[name];
|
||||||
if (!name) continue;
|
|
||||||
if (info.link || (!info.resolved && !name.includes('node_modules/'))) {
|
|
||||||
delete packages[name];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fs.writeFileSync(p, JSON.stringify(data, null, 2));
|
fs.writeFileSync(p, JSON.stringify(d, null, 2));
|
||||||
" "$TMPDIR/package-lock.json"
|
" "$TMPDIR/package-lock.json"
|
||||||
|
|
||||||
flatpak-node-generator --no-requests-cache -o "$SCRIPT_DIR/node-sources.json" npm "$TMPDIR/package-lock.json"
|
flatpak-node-generator --no-requests-cache \
|
||||||
echo " Done: flatpak/node-sources.json"
|
-o "$SCRIPT_DIR/node-sources.json" npm "$TMPDIR/package-lock.json"
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Source files generated. Commit them alongside the manifest."
|
|
||||||
|
|||||||
Reference in New Issue
Block a user