mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
refactor: move static string into templates/ folder (#676)
This commit is contained in:
@@ -10,7 +10,7 @@ repository = "https://github.com/tuono-labs/tuono"
|
|||||||
readme = "../../README.md"
|
readme = "../../README.md"
|
||||||
license-file = "../../LICENSE.md"
|
license-file = "../../LICENSE.md"
|
||||||
categories = ["web-programming"]
|
categories = ["web-programming"]
|
||||||
include = ["src/**/*.rs", "Cargo.toml"]
|
include = ["src/**/*.rs", "templates/*", "Cargo.toml"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "tuono"
|
name = "tuono"
|
||||||
|
|||||||
@@ -13,76 +13,14 @@ use crate::mode::Mode;
|
|||||||
use crate::route::AxumInfo;
|
use crate::route::AxumInfo;
|
||||||
use crate::route::Route;
|
use crate::route::Route;
|
||||||
|
|
||||||
const FALLBACK_HTML: &str = r#"<!doctype html>
|
#[cfg(not(target_os = "windows"))]
|
||||||
<html>
|
const FALLBACK_HTML: &str = include_str!("../templates/fallback.html");
|
||||||
<body>
|
#[cfg(not(target_os = "windows"))]
|
||||||
<script>
|
const SERVER_ENTRY_DATA: &str = include_str!("../templates/server.ts");
|
||||||
window['__TUONO_SERVER_PAYLOAD__'] = [SERVER_PAYLOAD]
|
#[cfg(not(target_os = "windows"))]
|
||||||
</script>
|
const CLIENT_ENTRY_DATA: &str = include_str!("../templates/client.ts");
|
||||||
<script type="module" async>
|
#[cfg(not(target_os = "windows"))]
|
||||||
import RefreshRuntime from '[BASE_URL]/vite-server/@react-refresh'
|
const AXUM_ENTRY_POINT: &str = include_str!("../templates/server.rs");
|
||||||
RefreshRuntime.injectIntoGlobalHook(window)
|
|
||||||
window.$RefreshReg$ = () => { }
|
|
||||||
window.$RefreshSig$ = () => (type) => type
|
|
||||||
window.__vite_plugin_react_preamble_installed__ = true
|
|
||||||
</script>
|
|
||||||
<script type="module" async src="[BASE_URL]/vite-server/@vite/client"></script>
|
|
||||||
<script type="module" async src="[BASE_URL]/vite-server/client-main.tsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>"#;
|
|
||||||
|
|
||||||
const SERVER_ENTRY_DATA: &str = "// File automatically generated by tuono
|
|
||||||
// Do not manually update this file
|
|
||||||
import { routeTree } from './routeTree.gen'
|
|
||||||
import { serverSideRendering } from 'tuono/ssr'
|
|
||||||
|
|
||||||
export const renderFn = serverSideRendering(routeTree)
|
|
||||||
";
|
|
||||||
|
|
||||||
const CLIENT_ENTRY_DATA: &str = "// File automatically generated by tuono
|
|
||||||
// Do not manually update this file
|
|
||||||
import 'vite/modulepreload-polyfill'
|
|
||||||
import { hydrate } from 'tuono/hydration'
|
|
||||||
|
|
||||||
// Import the generated route tree
|
|
||||||
import { routeTree } from './routeTree.gen'
|
|
||||||
|
|
||||||
hydrate(routeTree)
|
|
||||||
";
|
|
||||||
|
|
||||||
const AXUM_ENTRY_POINT: &str = r##"
|
|
||||||
// File automatically generated
|
|
||||||
// Do not manually change it
|
|
||||||
|
|
||||||
use tuono_lib::{tokio, Mode, Server, axum::Router, tuono_internal_init_v8_platform};
|
|
||||||
// AXUM_GET_ROUTE_HANDLER
|
|
||||||
|
|
||||||
const MODE: Mode = /*MODE*/;
|
|
||||||
|
|
||||||
// MODULE_IMPORTS
|
|
||||||
|
|
||||||
//MAIN_FILE_IMPORT//
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() {
|
|
||||||
tuono_internal_init_v8_platform();
|
|
||||||
println!("\n ⚡ Tuono v/*VERSION*/");
|
|
||||||
|
|
||||||
//MAIN_FILE_DEFINITION//
|
|
||||||
|
|
||||||
let router = Router::new()
|
|
||||||
// ROUTE_BUILDER
|
|
||||||
//MAIN_FILE_USAGE//;
|
|
||||||
|
|
||||||
Server::init(router, MODE).await.start().await
|
|
||||||
}
|
|
||||||
"##;
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
const MAIN_FILE_PATH: &str = ".\\.tuono\\main.rs";
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
const FALLBACK_HTML_PATH: &str = ".\\.tuono\\index.html";
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
const MAIN_FILE_PATH: &str = "./.tuono/main.rs";
|
const MAIN_FILE_PATH: &str = "./.tuono/main.rs";
|
||||||
@@ -93,6 +31,21 @@ const FALLBACK_HTML_PATH: &str = "./.tuono/index.html";
|
|||||||
const ROUTE_FOLDER: &str = "src/routes";
|
const ROUTE_FOLDER: &str = "src/routes";
|
||||||
const DEV_FOLDER: &str = ".tuono";
|
const DEV_FOLDER: &str = ".tuono";
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const FALLBACK_HTML: &str = include_str!("..\\templates\\fallback.html");
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const SERVER_ENTRY_DATA: &str = include_str!("..\\templates\\server.ts");
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const CLIENT_ENTRY_DATA: &str = include_str!("..\\templates\\client.ts");
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const AXUM_ENTRY_POINT: &str = include_str!("..\\templates\\server.rs");
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const MAIN_FILE_PATH: &str = ".\\.tuono\\main.rs";
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
const FALLBACK_HTML_PATH: &str = ".\\.tuono\\index.html";
|
||||||
|
|
||||||
// Use this function to instruct the users on how to
|
// Use this function to instruct the users on how to
|
||||||
// fix their setup to make tuono work
|
// fix their setup to make tuono work
|
||||||
fn recoverable_error(message: &str) -> ! {
|
fn recoverable_error(message: &str) -> ! {
|
||||||
@@ -152,6 +105,7 @@ impl SourceBuilder {
|
|||||||
let Self { app, mode, .. } = &self;
|
let Self { app, mode, .. } = &self;
|
||||||
|
|
||||||
let src = AXUM_ENTRY_POINT
|
let src = AXUM_ENTRY_POINT
|
||||||
|
.replace("\r", "")
|
||||||
.replace(
|
.replace(
|
||||||
"// ROUTE_BUILDER\n",
|
"// ROUTE_BUILDER\n",
|
||||||
&create_routes_declaration(&app.route_map),
|
&create_routes_declaration(&app.route_map),
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// File automatically generated by tuono
|
||||||
|
// Do not manually update this file
|
||||||
|
import 'vite/modulepreload-polyfill'
|
||||||
|
import { hydrate } from 'tuono/hydration'
|
||||||
|
|
||||||
|
// Import the generated route tree
|
||||||
|
import { routeTree } from './routeTree.gen'
|
||||||
|
|
||||||
|
hydrate(routeTree)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<script>
|
||||||
|
window['__TUONO_SERVER_PAYLOAD__'] = [SERVER_PAYLOAD]
|
||||||
|
</script>
|
||||||
|
<script type="module" async>
|
||||||
|
import RefreshRuntime from '[BASE_URL]/vite-server/@react-refresh'
|
||||||
|
RefreshRuntime.injectIntoGlobalHook(window)
|
||||||
|
window.$RefreshReg$ = () => { }
|
||||||
|
window.$RefreshSig$ = () => (type) => type
|
||||||
|
window.__vite_plugin_react_preamble_installed__ = true
|
||||||
|
</script>
|
||||||
|
<script type="module" async src="[BASE_URL]/vite-server/@vite/client"></script>
|
||||||
|
<script type="module" async src="[BASE_URL]/vite-server/client-main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// File automatically generated
|
||||||
|
// Do not manually change it
|
||||||
|
|
||||||
|
use tuono_lib::{tokio, Mode, Server, axum::Router, tuono_internal_init_v8_platform};
|
||||||
|
// AXUM_GET_ROUTE_HANDLER
|
||||||
|
|
||||||
|
const MODE: Mode = /*MODE*/;
|
||||||
|
|
||||||
|
// MODULE_IMPORTS
|
||||||
|
|
||||||
|
//MAIN_FILE_IMPORT//
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
tuono_internal_init_v8_platform();
|
||||||
|
println!("\n ⚡ Tuono v/*VERSION*/");
|
||||||
|
|
||||||
|
//MAIN_FILE_DEFINITION//
|
||||||
|
|
||||||
|
let router = Router::new()
|
||||||
|
// ROUTE_BUILDER
|
||||||
|
//MAIN_FILE_USAGE//;
|
||||||
|
|
||||||
|
Server::init(router, MODE).await.start().await
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// File automatically generated by tuono
|
||||||
|
// Do not manually update this file
|
||||||
|
import { serverSideRendering } from 'tuono/ssr'
|
||||||
|
|
||||||
|
import { routeTree } from './routeTree.gen'
|
||||||
|
|
||||||
|
export const renderFn = serverSideRendering(routeTree)
|
||||||
Reference in New Issue
Block a user