Crate Download

Crate Download 

Source
Expand description

============================================================================== Universal Sidecar Vendor - Rust Edition

This program automates downloading and organizing full distributions of various sidecar runtimes (like Node.js) for a Tauri application. It is a Rust rewrite of the original shell script, enhanced with modern features.

Key Features:

  • Asynchronous, Concurrent Downloads: Leverages Tokio to download multiple binaries in parallel, significantly speeding up the process.
  • Intelligent Caching: Maintains a Cache.json file to track downloaded versions. It automatically detects if a newer patch version is available for a requested major version and updates the binary.
  • Git LFS Management: Automatically creates or updates the .gitattributes file to ensure large binaries are tracked by Git LFS.
  • Extensible Design: Easily configured to support new sidecars, versions, and platforms.
  • Robust Error Handling: Uses anyhow for clear and concise error reporting.
  • Preserved File Structure: The final output directory structure remains identical to the original script (Architecture/SidecarName/Version).

==============================================================================

StructsΒ§

DownloadCache πŸ”’
Represents the structure of the Cache.json file. It uses a HashMap to map a unique key (representing a specific sidecar/version/platform) to the full version string that was last downloaded.
DownloadTask πŸ”’
Contains all the necessary information to perform a single download and installation task. An instance of this struct is created for each binary that needs to be downloaded.
NodeVersionInfo πŸ”’
Represents a specific version of Node.js as returned by the official index. Used for deserializing the JSON response from nodejs.org.
PlatformTarget πŸ”’
Represents a single platform target for which binaries will be downloaded. This struct holds all the necessary identifiers for a given platform.

EnumsΒ§

ArchiveType πŸ”’
Defines the type of archive being handled, which determines the extraction logic.

ConstantsΒ§

LogEnv
Environment variable for setting the log level.

FunctionsΒ§

DownloadFile πŸ”’
Downloads a file from a URL to a specified path.
ExtractArchive πŸ”’
Extracts the contents of a downloaded archive to a target directory. This function now performs a full extraction to ensure a complete distribution.
FetchNodeVersions πŸ”’
Fetches the official Node.js versions index from nodejs.org.
Fn
GetBaseSidecarDirectory πŸ”’
Returns the root directory where all sidecars will be stored. This is determined dynamically by navigating up from the executable’s location and detecting the SideCar project root. It handles both:
GetPlatformMatrix πŸ”’
Defines the matrix of platforms to target. Each entry specifies how to download and identify binaries for a specific architecture.
GetSidecarsToFetch πŸ”’
Defines which sidecars and versions to fetch. This structure makes it easy to add more sidecars like Deno in the future.
Logger
Sets up the global logger for the application.
ProcessDownloadTask πŸ”’
The main asynchronous function for processing a single download task. This function is designed to be run concurrently for multiple tasks.
ResolveLatestPatchVersion πŸ”’
Resolves a major version string (e.g., β€œ22”) to the latest full patch version (e.g., β€œv22.3.0”) using the fetched version index.
UpdateGitattributes πŸ”’
Manages the .gitattributes file to ensure binaries are tracked by Git LFS. If the file does not exist, it is created. If it exists, missing rules are appended.
main πŸ”’
Main executable function.