Skip to content

Commit

Permalink
feat(cli): detect SvelteKit and Vite (#5742)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Dec 2, 2022
1 parent b6027b2 commit 9d872ab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .changes/add-frameworks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Detect SvelteKit and Vite for the init and info commands.
42 changes: 21 additions & 21 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions tooling/cli/src/helpers/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::fmt;
#[derive(Debug, Clone)]
pub enum Framework {
Svelte,
SvelteKit,
Angular,
React,
Nextjs,

Gatsby,
Nuxt,
Quasar,
Expand All @@ -22,6 +22,7 @@ impl Framework {
pub fn dev_path(&self) -> String {
match self {
Self::Svelte => "http://localhost:8080",
Self::SvelteKit => "http://localhost:5173",
Self::Angular => "http://localhost:4200",
Self::React => "http://localhost:3000",
Self::Nextjs => "http://localhost:3000",
Expand All @@ -37,6 +38,7 @@ impl Framework {
pub fn dist_dir(&self) -> String {
match self {
Self::Svelte => "../public",
Self::SvelteKit => "../build",
Self::Angular => "../dist",
Self::React => "../build",
Self::Nextjs => "../out",
Expand All @@ -54,6 +56,7 @@ impl fmt::Display for Framework {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Svelte => write!(f, "Svelte"),
Self::SvelteKit => write!(f, "SvelteKit"),
Self::Angular => write!(f, "Angular"),
Self::React => write!(f, "React"),
Self::Nextjs => write!(f, "React (Next.js)"),
Expand All @@ -70,30 +73,37 @@ impl fmt::Display for Framework {
pub enum Bundler {
Webpack,
Rollup,
Vite,
}

impl fmt::Display for Bundler {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Webpack => write!(f, "Webpack"),
Self::Rollup => write!(f, "Rollup"),
Self::Vite => write!(f, "Vite"),
}
}
}

pub fn infer_from_package_json(package_json: &str) -> (Option<Framework>, Option<Bundler>) {
let framework_map = [
("svelte", Framework::Svelte, None),
("svelte", Framework::Svelte, Some(Bundler::Rollup)),
("@sveltejs/kit", Framework::SvelteKit, Some(Bundler::Vite)),
("@angular", Framework::Angular, Some(Bundler::Webpack)),
(r#""next""#, Framework::Nextjs, Some(Bundler::Webpack)),
("gatsby", Framework::Gatsby, Some(Bundler::Webpack)),
("react", Framework::React, None),
("nuxt", Framework::Nuxt, Some(Bundler::Webpack)),
("quasar", Framework::Quasar, Some(Bundler::Webpack)),
("@vue/cli", Framework::VueCli, Some(Bundler::Webpack)),
("vue", Framework::Vue, None),
("vue", Framework::Vue, Some(Bundler::Vite)),
];
let bundler_map = [
("webpack", Bundler::Webpack),
("rollup", Bundler::Rollup),
("vite", Bundler::Vite),
];
let bundler_map = [("webpack", Bundler::Webpack), ("rollup", Bundler::Rollup)];

let (framework, framework_bundler) = framework_map
.iter()
Expand Down

0 comments on commit 9d872ab

Please sign in to comment.