pub struct FrameworkDetector { /* private fields */ }Expand description
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.
PHP: Utopia\Detector\Detector\Framework.
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");use Utopia\Detector\Detection\Framework\NextJs;
use Utopia\Detector\Detection\Framework\React;
use Utopia\Detector\Detector\Framework;
$detector = new Framework('npm');
$detector->addOption(new React())->addOption(new NextJs());
$detector->addInput('next.config.js', Framework::INPUT_FILE);
$detector->addInput('{"dependencies": {"react": "^18.0.0"}}', Framework::INPUT_PACKAGES);
$framework = $detector->detect();
echo $framework->getName(), "\n"; // nextjs
echo $framework->getInstallCommand(), "\n"; // npm install
echo $framework->getOutputDirectory(), "\n"; // ./.nextImplementations§
Source§impl FrameworkDetector
impl FrameworkDetector
Sourcepub fn new(packager: impl Into<String>) -> Self
pub fn new(packager: impl Into<String>) -> Self
A detector for a project using packager (pnpm when unsure).
PHP: new Framework($packager).
Sourcepub fn add_option(&mut self, option: impl Framework + 'static) -> &mut Self
pub fn add_option(&mut self, option: impl Framework + 'static) -> &mut Self
Adds a framework to score.
PHP: addOption($framework).
Sourcepub fn add_file(&mut self, file: impl Into<String>) -> &mut Self
pub fn add_file(&mut self, file: impl Into<String>) -> &mut Self
Adds a file name of the project.
PHP: addInput($file, Framework::INPUT_FILE).
Sourcepub fn add_manifest(&mut self, content: impl Into<Vec<u8>>) -> &mut Self
pub fn add_manifest(&mut self, content: impl Into<Vec<u8>>) -> &mut Self
Adds the content of a manifest (package.json, pubspec.yaml), whose
dependencies count for the frameworks that list them.
PHP: addInput($content, Framework::INPUT_PACKAGES).