Files
tauri/tooling/cli/src/helpers/framework.rs
Amr Bashir 8de308d1bf feat(core): implement new config structure (#8723)
* feat(core): implement new config structure

RFC#5 f3e82a6b0c/texts/0005-tauri-config-restructure.md

* fixes

* remove tauri-plugin copy [skip ci]

* move platform specific configs

* fix build

* fix cli

* doctests

* change files

* read updater plugin config on CLI

* doctests

* remove env var from docs

* fix getting pubkey

* add migrations

* clippy

* update change file [skip ci]

* rename frontendDist to prodFrontend?

* Revert "rename frontendDist to prodFrontend?"

This reverts commit ef7394f085.

* fix all_features check

* fix field name

* single license getter on bundler

* readd msiexec_args

* remove unused fixture

* update template

* Update .changes/tauri-bundle-settings-rfc-5.md

* Update .changes/config-restructure-rfc-5.md

* lint bundler, fix change file

* rename AppUrl to FrontendDist, add explicit variants for docs

* fix build

* lint

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
2024-02-03 00:39:48 -03:00

132 lines
3.8 KiB
Rust

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use std::fmt;
#[derive(Debug, Clone)]
pub enum Framework {
SolidJS,
SolidStart,
Svelte,
SvelteKit,
Angular,
React,
Nextjs,
Gatsby,
Nuxt,
Quasar,
VueCli,
Vue,
}
impl Framework {
pub fn dev_url(&self) -> String {
match self {
Self::SolidJS => "http://localhost:3000",
Self::SolidStart => "http://localhost:3000",
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",
Self::Gatsby => "http://localhost:8000",
Self::Nuxt => "http://localhost:3000",
Self::Quasar => "http://localhost:8080",
Self::VueCli => "http://localhost:8080",
Self::Vue => "http://localhost:8080",
}
.into()
}
pub fn frontend_dist(&self) -> String {
match self {
Self::SolidJS => "../dist",
Self::SolidStart => "../dist/public",
Self::Svelte => "../public",
Self::SvelteKit => "../build",
Self::Angular => "../dist",
Self::React => "../build",
Self::Nextjs => "../out",
Self::Gatsby => "../public",
Self::Nuxt => "../dist",
Self::Quasar => "../dist/spa",
Self::VueCli => "../dist",
Self::Vue => "../dist",
}
.into()
}
}
impl fmt::Display for Framework {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::SolidJS => write!(f, "SolidJS"),
Self::SolidStart => write!(f, "SolidStart"),
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)"),
Self::Gatsby => write!(f, "React (Gatsby)"),
Self::Nuxt => write!(f, "Vue.js (Nuxt)"),
Self::Quasar => write!(f, "Vue.js (Quasar)"),
Self::VueCli => write!(f, "Vue.js (Vue CLI)"),
Self::Vue => write!(f, "Vue.js"),
}
}
}
#[derive(Debug, Clone)]
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 = [
("solid-start", Framework::SolidStart, Some(Bundler::Vite)),
("solid-js", Framework::SolidJS, Some(Bundler::Vite)),
("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, Some(Bundler::Vite)),
];
let bundler_map = [
("webpack", Bundler::Webpack),
("rollup", Bundler::Rollup),
("vite", Bundler::Vite),
];
let (framework, framework_bundler) = framework_map
.iter()
.find(|(keyword, _, _)| package_json.contains(keyword))
.map(|(_, framework, bundler)| (Some(framework.clone()), bundler.clone()))
.unwrap_or((None, None));
let bundler = bundler_map
.iter()
.find(|(keyword, _)| package_json.contains(keyword))
.map(|(_, bundler)| bundler.clone())
.or(framework_bundler);
(framework, bundler)
}