Rust

framework

Module

Frameworks: Framework, the built-in frameworks, and the FrameworkDetector that scores them on file names and manifest dependencies.

Contents

use utopia_detector::FrameworkDetector;
Rust
pub struct FrameworkDetector

Finds a project's framework by scoring every option: one point per framework file among the file inputs, and one per framework package declared in each manifest input. The highest score wins; a tie goes to the framework with the fewest parents, except that Astro yields to the runner-up.

Options are scored by name: two options with one name share a score.

Rust
use utopia_detector::{FrameworkDetector, NextJs, React};

let mut detector = FrameworkDetector::new("npm");
detector.add_option(React).add_option(NextJs);
detector.add_file("next.config.js");
detector.add_manifest(r#"{"dependencies": {"react": "^18.0.0"}}"#);

let framework = detector.detect().expect("a framework");
assert_eq!(framework.name(), "nextjs");
assert_eq!(framework.install_command(), "npm install");
assert_eq!(framework.output_directory(), "./.next");
Also implements Debug.
use utopia_detector::Adapter;
Rust
pub enum Adapter

How a framework's build is served, as its configuration says.

use utopia_detector::Input;
Rust
pub enum Input

What a framework detector input is.

use utopia_detector::Framework;
Rust
pub trait Framework: Send + Sync

A web framework, recognised by its configuration files and the packages a project depends on.

use utopia_detector::dependencies;
Rust
pub fn dependencies(manifest: &[u8]) -> Vec<Vec<u8>>

The dependency names declared in a package.json (JSON) or pubspec.yaml (YAML), section by section; none when it parses as neither.