mirror of
https://github.com/logos-co/logos-modules.git
synced 2026-08-31 03:51:10 +00:00
* bump all submodules * sort packages * use default #lgx-portable instead of nix bundle * bump logos-accounts-ui * make publishing optional * bump moar * script improvements * bump logos-package * bump logos-blockchain-module
132 lines
3.5 KiB
Bash
Executable File
132 lines
3.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
set -x
|
|
|
|
script_dir="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
cd "$script_dir"
|
|
|
|
base_libraries_dir="$script_dir/libraries"
|
|
list_json_path="$base_libraries_dir/list.json"
|
|
|
|
if [[ ! -f .gitmodules ]]; then
|
|
echo "No .gitmodules found in $script_dir" >&2
|
|
exit 1
|
|
fi
|
|
|
|
modules=$(git config --file .gitmodules --get-regexp path | awk '{print $2}')
|
|
|
|
if [[ -z "$modules" ]]; then
|
|
echo "No module paths found in .gitmodules" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$base_libraries_dir"
|
|
|
|
# Store module metadata for list.json generation
|
|
module_entries=()
|
|
|
|
for module in $modules; do
|
|
echo "Building $module..."
|
|
if (cd "$module" && nix build --extra-experimental-features 'nix-command flakes' -o result .#lgx-portable); then
|
|
echo "Built $module"
|
|
|
|
lgx_file=$(find "$script_dir/$module/result" -maxdepth 1 -name '*.lgx' 2>/dev/null | head -n 1)
|
|
if [[ -z "$lgx_file" ]]; then
|
|
echo "No lgx file found in $module/result/" >&2
|
|
exit 1
|
|
fi
|
|
|
|
package_name=$(basename "$lgx_file" .lgx)
|
|
cp "$lgx_file" "$base_libraries_dir/"
|
|
|
|
echo "Created ${package_name}.lgx"
|
|
|
|
# Read metadata for list.json
|
|
module_metadata_path="$script_dir/$module/metadata.json"
|
|
module_metadata_json=$(python3 - "$module_metadata_path" <<'PY'
|
|
import json, sys
|
|
try:
|
|
with open(sys.argv[1]) as f:
|
|
print(json.dumps(json.load(f)))
|
|
except:
|
|
print("{}")
|
|
PY
|
|
)
|
|
|
|
# Extract manifest from the built lgx package
|
|
module_manifest_json=$(python3 - "$lgx_file" <<'PY'
|
|
import tarfile, json, sys
|
|
with tarfile.open(sys.argv[1], 'r:gz') as tar:
|
|
for member in tar.getmembers():
|
|
if member.name == 'manifest.json':
|
|
print(tar.extractfile(member).read().decode())
|
|
break
|
|
PY
|
|
)
|
|
|
|
module_entries+=("$module::$module_metadata_json::${package_name}.lgx::${module_manifest_json}")
|
|
else
|
|
echo "Failed building $module" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Generate list.json
|
|
python3 - "$list_json_path" "${module_entries[@]}" <<'PY'
|
|
import json, os, sys
|
|
|
|
list_path = sys.argv[1]
|
|
entries = sys.argv[2:]
|
|
|
|
result_index = {}
|
|
|
|
for raw in entries:
|
|
if "::" not in raw:
|
|
continue
|
|
parts = raw.split("::", 3)
|
|
if len(parts) < 3:
|
|
continue
|
|
|
|
name, metadata_json, package_filename = parts[0], parts[1], parts[2]
|
|
manifest_json_str = parts[3] if len(parts) > 3 else ""
|
|
|
|
try:
|
|
metadata = json.loads(metadata_json)
|
|
except json.JSONDecodeError:
|
|
metadata = {}
|
|
|
|
try:
|
|
manifest = json.loads(manifest_json_str) if manifest_json_str else {}
|
|
except json.JSONDecodeError:
|
|
manifest = {}
|
|
|
|
item = {"name": name, "package": package_filename}
|
|
if manifest:
|
|
item["manifest"] = manifest
|
|
if "type" in metadata:
|
|
item["type"] = metadata["type"]
|
|
if "name" in metadata:
|
|
item["moduleName"] = metadata["name"]
|
|
if "description" in metadata:
|
|
item["description"] = metadata["description"]
|
|
if "dependencies" in metadata:
|
|
item["dependencies"] = metadata["dependencies"]
|
|
if "category" in metadata:
|
|
item["category"] = metadata["category"]
|
|
if "author" in metadata:
|
|
item["author"] = metadata["author"]
|
|
if metadata.get("version"):
|
|
item["version"] = metadata["version"]
|
|
|
|
result_index[name] = item
|
|
|
|
result = [result_index[k] for k in sorted(result_index)]
|
|
os.makedirs(os.path.dirname(list_path), exist_ok=True)
|
|
with open(list_path, "w") as f:
|
|
json.dump(result, f, indent=2)
|
|
PY
|
|
|
|
echo "All modules built successfully."
|
|
echo "LGX packages created in $base_libraries_dir"
|
|
echo "Package list written to $list_json_path."
|