1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Detection of what a project is from what it contains: its package
//! manager, its language runtime, its web framework, and whether a build is
//! served by a server or as static files.
//!
//! Each question has a detector fed with inputs (file names, language names
//! or manifest contents) and options to choose from:
//!
//! - [`PackagerDetector`] with [`Packager`]s ([`Npm`], [`Pnpm`], [`Yarn`]);
//! - [`RuntimeDetector`] with [`Runtime`]s ([`Node`], [`Php`], [`Python`]
//! and eight more), matching by a [`Strategy`];
//! - [`FrameworkDetector`] with [`Framework`]s ([`NextJs`], [`Nuxt`],
//! [`SvelteKit`], [`Astro`], [`Flutter`] and ten more), scored on files and
//! [`dependencies`];
//! - [`RenderingDetector`] with [`Rendering`]s ([`Ssr`], [`Static`]).
//!
//! Options are traits, so a project can add its own. Runtime and framework
//! detections come back as [`Detected`], which carries the detector's
//! packager into the install and build commands.
//!
//! ```
//! use utopia_detector::{FrameworkDetector, NextJs, Nuxt, SvelteKit};
//!
//! let mut detector = FrameworkDetector::new("pnpm");
//! detector.add_option(NextJs).add_option(Nuxt).add_option(SvelteKit);
//! for file in ["src", "package.json", "svelte.config.js"] {
//! detector.add_file(file);
//! }
//!
//! let framework = detector.detect().expect("a framework");
//! assert_eq!(framework.name(), "sveltekit");
//! assert_eq!(framework.build_command(), "pnpm run build");
//! ```
//!
//! ```php
//! use Utopia\Detector\Detection\Framework\NextJs;
//! use Utopia\Detector\Detection\Framework\Nuxt;
//! use Utopia\Detector\Detection\Framework\SvelteKit;
//! use Utopia\Detector\Detector\Framework;
//!
//! $detector = new Framework('pnpm');
//! $detector->addOption(new NextJs())->addOption(new Nuxt())->addOption(new SvelteKit());
//! foreach (['src', 'package.json', 'svelte.config.js'] as $file) {
//! $detector->addInput($file, Framework::INPUT_FILE);
//! }
//!
//! $framework = $detector->detect();
//! echo $framework->getName(), "\n"; // sveltekit
//! echo $framework->getBuildCommand(), "\n"; // pnpm run build
//! ```
//!
//! PHP: ports `utopia-php/detector`.
//!
//! | PHP | Rust |
//! |---|---|
//! | `Utopia\Detector\Detector` (abstract), `Detection` (abstract) | one detector type per question; no common base |
//! | `Detector::addOption()`, `addInput()`, `detect()` | `add_option`, `add_input` (`add_file` / `add_manifest` on [`FrameworkDetector`]), `detect` on each detector |
//! | `Detector\Packager`, `Detection\Packager` | [`PackagerDetector`], [`Packager`] |
//! | `Detection\Packager\NPM`, `PNPM`, `Yarn` | [`Npm`], [`Pnpm`], [`Yarn`] |
//! | `Detector\Runtime`, `Detection\Runtime` | [`RuntimeDetector`], [`Runtime`] |
//! | `Detector\Strategy` (`FILEMATCH`, `EXTENSION`, `LANGUAGES`) | [`Strategy`] |
//! | `Detection\Runtime\Bun`, `CPP`, `Dart`, `Deno`, `Dotnet`, `Java`, `Node`, `PHP`, `Python`, `Ruby`, `Swift` | [`Bun`], [`Cpp`], [`Dart`], [`Deno`], [`Dotnet`], [`Java`], [`Node`], [`Php`], [`Python`], [`Ruby`], [`Swift`] |
//! | `Detector\Framework`, `Detection\Framework` | [`FrameworkDetector`], [`Framework`] |
//! | `Framework::INPUT_FILE`, `INPUT_PACKAGES` | [`Input`] |
//! | `Framework::dependencies()` | [`dependencies`] |
//! | `Detection\Framework\JS` (abstract) | the JavaScript frameworks' shared install and build commands |
//! | `Detection\Framework\Analog`, `Angular`, `Astro`, `Flutter`, `Jaspr`, `Lynx`, `NextJs`, `Nuxt`, `React`, `ReactNative`, `Remix`, `Svelte`, `SvelteKit`, `TanStackStart`, `Vue` | [`Analog`], [`Angular`], [`Astro`], [`Flutter`], [`Jaspr`], [`Lynx`], [`NextJs`], [`Nuxt`], [`React`], [`ReactNative`], [`Remix`], [`Svelte`], [`SvelteKit`], [`TanStackStart`], [`Vue`] |
//! | `getAdapter()` (`'ssr'`, `'static'`, `''`) | [`Framework::adapter`] ([`Adapter`], `None`) |
//! | `setPackager()` on a runtime or framework | the `packager` argument of [`Runtime::commands`], [`Framework::install_command`], [`Framework::build_command`]; [`Detected`] passes the detector's |
//! | `Detector\Rendering`, `Detection\Rendering` | [`RenderingDetector`], [`Rendering`] ([`Rendered`] from `detect`) |
//! | `Detection\Rendering\SSR`, `XStatic` | [`Ssr`], [`Static`] |
//! | `\InvalidArgumentException`, `\Exception` | [`Error::InvalidArgument`], [`Error::Exception`] |
//!
//! PHP passes file names as byte strings; here they are `String`s, so a name
//! that is not UTF-8 has to be converted before it is added.
pub use Error;
pub use ;
pub use ;
pub use ;
pub use ;
/// The getting started guide (`guide.md`), compiled and run with the doctests.
;
/// A runtime or framework a detector chose, with the detector's packager:
/// its commands are the ones for that packager. Everything else is the
/// option itself, through `Deref`.
///
/// PHP: the detection object `detect()` returns after `setPackager()`.