diff --git a/Cargo.toml b/Cargo.toml index 2d5d881b4..b8e0ab885 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ description = "Core functionality for Dioxus - a concurrent renderer-agnostic Vi dioxus-core = { path="./packages/core", version="0.1.0" } dioxus-core-macro = { path="./packages/core-macro", version="0.1.0" } dioxus-html-namespace = { path="./packages/html-namespace" } - dioxus-web = { path="./packages/web", optional=true } # dioxus-hooks = { path="./packages/hooks", version="0.0.0" } @@ -48,10 +47,7 @@ members = [ "packages/html-namespace", "packages/web", "packages/webview", - "packages/cli", # "packages/atoms", # "packages/ssr", # "packages/docsite", - # "packages/router", - # "packages/inputs", ] diff --git a/packages/cli/.gitignore b/packages/cli/.gitignore deleted file mode 100644 index 96ef6c0b9..000000000 --- a/packages/cli/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/target -Cargo.lock diff --git a/packages/cli/.vscode/settings.json b/packages/cli/.vscode/settings.json deleted file mode 100644 index 80f51cff8..000000000 --- a/packages/cli/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "rust-analyzer.inlayHints.enable": false -} \ No newline at end of file diff --git a/packages/cli/Cargo.toml b/packages/cli/Cargo.toml deleted file mode 100644 index bfc4a3622..000000000 --- a/packages/cli/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -[package] -name = "dioxus-cli" -version = "0.1.0" -authors = ["Jonathan Kelley "] -edition = "2018" -description = "CLI tool for developing, testing, and publishing Dioxus apps" -"license" = "MIT/Apache-2.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -thiserror = "1.0.23" -log = "0.4.13" -fern = { version="0.6.0", features=["colored"] } -wasm-bindgen-cli-support = "0.2.73" -anyhow = "1.0.38" -argh = "0.1.4" -serde = "1.0.120" -serde_json = "1.0.61" -async-std = { version="1.9.0", features=["attributes"] } -tide = "0.15.0" -fs_extra = "1.2.0" - -cargo_toml = "0.8.1" -futures = "0.3.12" -notify = "5.0.0-pre.4" -rjdebounce = "0.2.1" -tempfile = "3.2.0" - -[[bin]] - -path = "src/main.rs" -name = "dioxus" diff --git a/packages/cli/README.md b/packages/cli/README.md deleted file mode 100644 index bf2e3310a..000000000 --- a/packages/cli/README.md +++ /dev/null @@ -1,48 +0,0 @@ -
-

📦✨ dioxus-cli

-

- Tooling to supercharge dioxus projects -

-
- -# About ---- -dioxus-cli (inspired by wasm-pack and webpack) is a tool to help get dioxus projects off the ground. It handles all the build, development, bundling, and publishing to make web development just a simple two commands: `cargo init` and `dioxus-cli publish`. - -Best thing: -- No NPM. -- No Webpack. -- No `node_modules`. -- No Babel -- No parcel -- No rollup -- No ESLint - -Just install Rust, dioxus-cli, and you're good to go. -`cargo install --git github.com/jkelleyrtp/dioxus-cli` - -Need a development server? -`dioxus develop` - -Need to run an example? -`dioxus develop --example textbox` - -Need to benchmark a component? -`dioxus bench` - -Need to test your code? -`dioxus test` - -Need to build your code into a bundle? -`dioxus build --outdir public` - -Need to publish your code to GitHub pages, Netlify, etc? -`dioxus publish --ghpages myrepo.git` - -# Use in your project ---- -Sometimes you'll want to include static assets without bundling them into your .wasm content. dioxus-cli provides a few ways of doing this: - -- Load in dynamic content using `dioxus::asset("./static/images/blah.svg")` -- Live-reload HTML templates without rebuilding your .wasm with `dioxus::template("./templates/blah.html")` -- Use a CSS library like tailwind in your dioxus configuration with diff --git a/packages/cli/src/builder.rs b/packages/cli/src/builder.rs deleted file mode 100644 index 1d06b3ae8..000000000 --- a/packages/cli/src/builder.rs +++ /dev/null @@ -1,146 +0,0 @@ -use crate::{ - cli::BuildOptions, - config::{Config, ExecutableType}, - error::Result, -}; -use log::{info, warn}; -use std::{io::Write, process::Command}; -use wasm_bindgen_cli_support::Bindgen; - -pub struct BuildConfig {} -impl Into for BuildOptions { - fn into(self) -> BuildConfig { - BuildConfig {} - } -} -impl Default for BuildConfig { - fn default() -> Self { - Self {} - } -} - -pub fn build(config: &Config, _build_config: &BuildConfig) -> Result<()> { - /* - [1] Build the project with cargo, generating a wasm32-unknown-unknown target (is there a more specific, better target to leverage?) - [2] Generate the appropriate build folders - [3] Wasm-bindgen the .wasm fiile, and move it into the {builddir}/modules/xxxx/xxxx_bg.wasm - [4] Wasm-opt the .wasm file with whatever optimizations need to be done - [5] Link up the html page to the wasm module - */ - - let Config { - out_dir, - crate_dir, - target_dir, - static_dir, - executable, - .. - } = config; - - let t_start = std::time::Instant::now(); - - // [1] Build the .wasm module - info!("Running build commands..."); - let mut cmd = Command::new("cargo"); - cmd.current_dir(&crate_dir) - .arg("build") - .arg("--target") - .arg("wasm32-unknown-unknown") - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()); - - if config.release { - cmd.arg("--release"); - } - - match executable { - ExecutableType::Binary(name) => cmd.arg("--bin").arg(name), - ExecutableType::Lib(name) => cmd.arg("--lib").arg(name), - ExecutableType::Example(name) => cmd.arg("--example").arg(name), - }; - - let mut child = cmd.spawn()?; - let _err_code = child.wait()?; - - info!("Build complete!"); - - // [2] Establish the output directory structure - let bindgen_outdir = out_dir.join("wasm"); - - // [3] Bindgen the final binary for use easy linking - let mut bindgen_builder = Bindgen::new(); - - let release_type = match config.release { - true => "release", - false => "debug", - }; - - let input_path = match executable { - ExecutableType::Binary(name) | ExecutableType::Lib(name) => target_dir - // .join("wasm32-unknown-unknown/release") - .join(format!("wasm32-unknown-unknown/{}", release_type)) - .join(format!("{}.wasm", name)), - - ExecutableType::Example(name) => target_dir - // .join("wasm32-unknown-unknown/release/examples") - .join(format!("wasm32-unknown-unknown/{}/examples", release_type)) - .join(format!("{}.wasm", name)), - }; - - bindgen_builder - .input_path(input_path) - .web(true)? - .debug(true) - .demangle(true) - .keep_debug(true) - .remove_name_section(false) - .remove_producers_section(false) - .out_name("module") - .generate(&bindgen_outdir)?; - - // [4] - // TODO: wasm-opt - - // [5] Generate the html file with the module name - // TODO: support names via options - info!("Writing to '{:#?}' directory...", out_dir); - let mut file = std::fs::File::create(out_dir.join("index.html"))?; - file.write_all(gen_page("./wasm/module.js").as_str().as_bytes())?; - - let copy_options = fs_extra::dir::CopyOptions::new(); - match fs_extra::dir::copy(static_dir, out_dir, ©_options) { - Ok(_) => {} - Err(_e) => { - warn!("Error copying dir"); - } - } - - let t_end = std::time::Instant::now(); - log::info!("Done in {}ms! 🎉", (t_end - t_start).as_millis()); - Ok(()) -} - -fn gen_page(module: &str) -> String { - format!( - r#" - - - - - - - - - - - -"#, - module - ) -} diff --git a/packages/cli/src/cargo.rs b/packages/cli/src/cargo.rs deleted file mode 100644 index 3a911a81e..000000000 --- a/packages/cli/src/cargo.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! Utilities for working with cargo and rust files -use crate::error::{Error, Result}; -use std::{env, fs, path::PathBuf, process::Command, str}; - -/// How many parent folders are searched for a `Cargo.toml` -const MAX_ANCESTORS: u32 = 10; - -/// Returns the root of the crate that the command is run from -/// -/// If the command is run from the workspace root, this will return the top-level Cargo.toml -pub fn crate_root() -> Result { - // From the current directory we work our way up, looking for `Cargo.toml` - env::current_dir() - .ok() - .and_then(|mut wd| { - for _ in 0..MAX_ANCESTORS { - if contains_manifest(&wd) { - return Some(wd); - } - if !wd.pop() { - break; - } - } - None - }) - .ok_or_else(|| Error::CargoError("Failed to find the cargo directory".to_string())) -} - -/// Returns the root of a workspace -/// TODO @Jon, find a different way that doesn't rely on the cargo metadata command (it's slow) -pub fn workspace_root() -> Result { - let output = Command::new("cargo") - .args(&["metadata"]) - .output() - .map_err(|_| Error::CargoError("Manifset".to_string()))?; - - if !output.status.success() { - let mut msg = str::from_utf8(&output.stderr).unwrap().trim(); - if msg.starts_with("error: ") { - msg = &msg[7..]; - } - - return Err(Error::CargoError(msg.to_string())); - } - - let stdout = str::from_utf8(&output.stdout).unwrap(); - for line in stdout.lines() { - let meta: serde_json::Value = serde_json::from_str(line) - .map_err(|_| Error::CargoError("InvalidOutput".to_string()))?; - - let root = meta["workspace_root"] - .as_str() - .ok_or_else(|| Error::CargoError("InvalidOutput".to_string()))?; - return Ok(root.into()); - } - - Err(Error::CargoError("InvalidOutput".to_string())) -} - -/// Checks if the directory contains `Cargo.toml` -fn contains_manifest(path: &PathBuf) -> bool { - fs::read_dir(path) - .map(|entries| { - entries - .filter_map(Result::ok) - .any(|ent| &ent.file_name() == "Cargo.toml") - }) - .unwrap_or(false) -} diff --git a/packages/cli/src/cli.rs b/packages/cli/src/cli.rs deleted file mode 100644 index 852d4ee71..000000000 --- a/packages/cli/src/cli.rs +++ /dev/null @@ -1,62 +0,0 @@ -use argh::FromArgs; - -#[derive(FromArgs, PartialEq, Debug)] -/// Top-level command. -pub struct LaunchOptions { - #[argh(subcommand)] - pub command: LaunchCommand, -} - -/// The various kinds of commands that `wasm-pack` can execute. -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand)] -pub enum LaunchCommand { - Develop(DevelopOptions), - Build(BuildOptions), - Test(TestOptions), - Publish(PublishOptions), -} - -/// Publish your yew application to Github Pages, Netlify, or S3 -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand, name = "publish")] -pub struct PublishOptions {} - -/// 🔬 test your yew application! -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand, name = "test")] -pub struct TestOptions { - /// an example in the crate - #[argh(option)] - pub example: Option, -} - -/// 🏗️ Build your yew application -#[derive(FromArgs, PartialEq, Debug, Clone)] -#[argh(subcommand, name = "build")] -pub struct BuildOptions { - /// an optional direction which is "up" by default - #[argh(option, short = 'o', default = "String::from(\"public\")")] - pub outdir: String, - - /// an example in the crate - #[argh(option)] - pub example: Option, - - /// develop in release mode - #[argh(switch, short = 'r')] - pub release: bool, -} - -/// 🛠 Start a development server -#[derive(FromArgs, PartialEq, Debug)] -#[argh(subcommand, name = "develop")] -pub struct DevelopOptions { - /// an example in the crate - #[argh(option)] - pub example: Option, - - /// develop in release mode - #[argh(switch, short = 'r')] - pub release: bool, -} diff --git a/packages/cli/src/config.rs b/packages/cli/src/config.rs deleted file mode 100644 index 02a04eaf7..000000000 --- a/packages/cli/src/config.rs +++ /dev/null @@ -1,92 +0,0 @@ -use crate::{ - cli::{BuildOptions, DevelopOptions}, - error::Result, -}; -use std::{io::Write, path::PathBuf, process::Command}; - -#[derive(Debug, Clone)] -pub struct Config { - pub out_dir: PathBuf, - pub crate_dir: PathBuf, - pub workspace_dir: PathBuf, - pub target_dir: PathBuf, - pub static_dir: PathBuf, - pub manifest: cargo_toml::Manifest, - pub executable: ExecutableType, - pub release: bool, -} - -#[derive(Debug, Clone)] -pub enum ExecutableType { - Binary(String), - Lib(String), - Example(String), -} - -impl Config { - pub fn new() -> Result { - let crate_dir = crate::cargo::crate_root()?; - let workspace_dir = crate::cargo::workspace_root()?; - let target_dir = workspace_dir.join("target"); - let out_dir = crate_dir.join("public"); - let cargo_def = &crate_dir.join("Cargo.toml"); - let static_dir = crate_dir.join("static"); - - let manifest = cargo_toml::Manifest::from_path(&cargo_def).unwrap(); - - // We just assume they're using a 'main.rs' - // Anyway, we've already parsed the manifest, so it should be easy to change the type - let output_filename = (&manifest) - .lib - .as_ref() - .and_then(|lib| lib.name.clone()) - .or_else(|| { - (&manifest) - .package - .as_ref() - .and_then(|pkg| Some(pkg.name.replace("-", "_"))) - .clone() - }) - .expect("No lib found from cargo metadata"); - let executable = ExecutableType::Binary(output_filename); - - let release = false; - - Ok(Self { - out_dir, - crate_dir, - workspace_dir, - target_dir, - static_dir, - manifest, - executable, - release, - }) - } - - pub fn as_example(&mut self, example_name: String) -> &mut Self { - self.executable = ExecutableType::Example(example_name); - self - } - - pub fn with_release(&mut self, release: bool) -> &mut Self { - self.release = release; - self - } - - pub fn with_build_options(&mut self, options: &BuildOptions) { - if let Some(name) = &options.example { - self.as_example(name.clone()); - } - self.release = options.release; - self.out_dir = options.outdir.clone().into(); - } - - pub fn with_develop_options(&mut self, options: &DevelopOptions) { - if let Some(name) = &options.example { - self.as_example(name.clone()); - } - self.release = options.release; - self.out_dir = tempfile::Builder::new().tempdir().expect("").into_path(); - } -} diff --git a/packages/cli/src/develop.rs b/packages/cli/src/develop.rs deleted file mode 100644 index 1ae016b0d..000000000 --- a/packages/cli/src/develop.rs +++ /dev/null @@ -1,111 +0,0 @@ -use crate::{builder::BuildConfig, cli::DevelopOptions, config::Config, error::Result}; -use async_std::prelude::FutureExt; - -use async_std::future; -use async_std::prelude::*; - -use log::info; -use notify::{RecommendedWatcher, RecursiveMode, Watcher}; -use std::path::PathBuf; -use std::time::Duration; - -pub struct DevelopConfig {} -impl Into for DevelopOptions { - fn into(self) -> DevelopConfig { - DevelopConfig {} - } -} - -pub async fn start(config: &Config, _options: &DevelopConfig) -> Result<()> { - log::info!("Starting development server 🚀"); - - let Config { out_dir, .. } = config; - - // Spawn the server onto a seperate task - // This lets the task progress while we handle file updates - let server = async_std::task::spawn(launch_server(out_dir.clone())); - let watcher = async_std::task::spawn(watch_directory(config.clone())); - - match server.race(watcher).await { - Err(e) => log::warn!("Error running development server, {:?}", e), - _ => {} - } - - Ok(()) -} - -async fn watch_directory(config: Config) -> Result<()> { - // Create a channel to receive the events. - let (watcher_tx, watcher_rx) = async_std::channel::bounded(100); - - // Automatically select the best implementation for your platform. - // You can also access each implementation directly e.g. INotifyWatcher. - let mut watcher: RecommendedWatcher = Watcher::new_immediate(move |res| { - async_std::task::block_on(watcher_tx.send(res)); - }) - .expect("failed to make watcher"); - - let src_dir = crate::cargo::crate_root()?; - - // Add a path to be watched. All files and directories at that path and - // below will be monitored for changes. - watcher - .watch(src_dir.join("src"), RecursiveMode::Recursive) - .expect("Failed to watch dir"); - - watcher - .watch(src_dir.join("examples"), RecursiveMode::Recursive) - .expect("Failed to watch dir"); - - let build_config = BuildConfig::default(); - - 'run: loop { - crate::builder::build(&config, &build_config)?; - - // Wait for the message with a debounce - let _msg = watcher_rx - .recv() - .join(future::ready(1_usize).delay(Duration::from_millis(2000))) - .await; - - info!("File updated, rebuilding app"); - } - Ok(()) -} - -async fn launch_server(outdir: PathBuf) -> Result<()> { - let _crate_dir = crate::cargo::crate_root()?; - let _workspace_dir = crate::cargo::workspace_root()?; - - let mut app = tide::with_state(ServerState::new(outdir.to_owned())); - let p = outdir.display().to_string(); - - app.at("/") - .get(|req: tide::Request| async move { - log::info!("Connected to development server"); - let state = req.state(); - Ok(tide::Body::from_file(state.serv_path.clone().join("index.html")).await?) - }) - .serve_dir(p)?; - - let port = "8080"; - let serve_addr = format!("0.0.0.0:{}", port); - // let serve_addr = format!("127.0.0.1:{}", port); - - info!("App available at http://{}", serve_addr); - app.listen(serve_addr).await?; - Ok(()) -} - -/// https://github.com/http-rs/tide/blob/main/examples/state.rs -/// Tide seems to prefer using state instead of injecting into the app closure -/// The app closure needs to be static and -#[derive(Clone)] -struct ServerState { - serv_path: PathBuf, -} -impl ServerState { - fn new(serv_path: PathBuf) -> Self { - Self { serv_path } - } -} diff --git a/packages/cli/src/error.rs b/packages/cli/src/error.rs deleted file mode 100644 index 80a884956..000000000 --- a/packages/cli/src/error.rs +++ /dev/null @@ -1,34 +0,0 @@ -use thiserror::Error as ThisError; - -pub type Result = std::result::Result; - -#[derive(ThisError, Debug)] -pub enum Error { - /// Used when errors need to propogate but are too unique to be typed - #[error("{0}")] - Unique(String), - - #[error("I/O Error: {0}")] - IO(#[from] std::io::Error), - - #[error("Failed to write error")] - FailedToWrite, - - #[error("Failed to write error")] - CargoError(String), - - #[error(transparent)] - Other(#[from] anyhow::Error), -} - -impl From<&str> for Error { - fn from(s: &str) -> Self { - Error::Unique(s.to_string()) - } -} - -impl From for Error { - fn from(s: String) -> Self { - Error::Unique(s) - } -} diff --git a/packages/cli/src/lib.rs b/packages/cli/src/lib.rs deleted file mode 100644 index d6e7c838d..000000000 --- a/packages/cli/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ -pub mod builder; -pub mod cargo; -pub mod cli; -pub mod config; -pub mod develop; -pub mod error; -pub mod logging; -pub mod watch; diff --git a/packages/cli/src/logging.rs b/packages/cli/src/logging.rs deleted file mode 100644 index 94a9ce85b..000000000 --- a/packages/cli/src/logging.rs +++ /dev/null @@ -1,49 +0,0 @@ -use fern::colors::{Color, ColoredLevelConfig}; -use log::debug; - -pub fn set_up_logging() { - // configure colors for the whole line - let colors_line = ColoredLevelConfig::new() - .error(Color::Red) - .warn(Color::Yellow) - // we actually don't need to specify the color for debug and info, they are white by default - .info(Color::White) - .debug(Color::White) - // depending on the terminals color scheme, this is the same as the background color - .trace(Color::BrightBlack); - - // configure colors for the name of the level. - // since almost all of them are the same as the color for the whole line, we - // just clone `colors_line` and overwrite our changes - let colors_level = colors_line.clone().info(Color::Green); - // here we set up our fern Dispatch - fern::Dispatch::new() - .format(move |out, message, record| { - out.finish(format_args!( - "{color_line}[{level}{color_line}] {message}\x1B[0m", - color_line = format_args!( - "\x1B[{}m", - colors_line.get_color(&record.level()).to_fg_str() - ), - level = colors_level.color(record.level()), - message = message, - )); - }) - // set the default log level. to filter out verbose log messages from dependencies, set - // this to Warn and overwrite the log level for your crate. - .level(log::LevelFilter::Info) - // .level(log::LevelFilter::Warn) - // change log levels for individual modules. Note: This looks for the record's target - // field which defaults to the module path but can be overwritten with the `target` - // parameter: - // `info!(target="special_target", "This log message is about special_target");` - // .level_for("dioxus", log::LevelFilter::Debug) - // .level_for("dioxus", log::LevelFilter::Info) - // .level_for("pretty_colored", log::LevelFilter::Trace) - // output to stdout - .chain(std::io::stdout()) - .apply() - .unwrap(); - - debug!("finished setting up logging! yay!"); -} diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs deleted file mode 100644 index 7a5df372c..000000000 --- a/packages/cli/src/main.rs +++ /dev/null @@ -1,28 +0,0 @@ -use diopack::cli::{LaunchCommand, LaunchOptions}; -use dioxus_cli as diopack; - -#[async_std::main] -async fn main() -> diopack::error::Result<()> { - diopack::logging::set_up_logging(); - - let opts: LaunchOptions = argh::from_env(); - let mut config = diopack::config::Config::new()?; - - match opts.command { - LaunchCommand::Build(options) => { - config.with_build_options(&options); - diopack::builder::build(&config, &(options.into()))?; - } - - LaunchCommand::Develop(options) => { - config.with_develop_options(&options); - diopack::develop::start(&config, &(options.into())).await?; - } - - _ => { - todo!("Command not currently implemented"); - } - } - - Ok(()) -} diff --git a/packages/cli/src/watch.rs b/packages/cli/src/watch.rs deleted file mode 100644 index ae39bc670..000000000 --- a/packages/cli/src/watch.rs +++ /dev/null @@ -1,11 +0,0 @@ -pub struct Watcher {} - -impl Watcher { - // Spawns a new notify instance that alerts us of changes - pub fn new() -> Self { - Self {} - } - - /// Subsribe to the watcher - pub fn subscribe() {} -} diff --git a/packages/core/src/hooks.rs b/packages/core/src/hooks.rs index a32d9e008..2dc2d4ff4 100644 --- a/packages/core/src/hooks.rs +++ b/packages/core/src/hooks.rs @@ -7,7 +7,6 @@ use crate::innerlude::Context; -use crate::innerlude::*; use std::{ cell::RefCell, ops::{Deref, DerefMut}, diff --git a/packages/inputs/Cargo.toml b/packages/inputs/Cargo.toml deleted file mode 100644 index e7cf1c5e9..000000000 --- a/packages/inputs/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "dioxus-inputs" -version = "0.0.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] \ No newline at end of file diff --git a/packages/inputs/README.md b/packages/inputs/README.md deleted file mode 100644 index ae99b4e5b..000000000 --- a/packages/inputs/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Cross-platform controlled inputs - -Dioxus does not include controlled inputs in Dioxus-Core. This would require core integration with HTML that is inherently not cross platform. Instead, this crate exists to provide a bunch of cross-platform input types that abstract over renderer quirks. - -Included is: - -- Button -- Checkbox -- Color -- Date -- Datetime-local -- Email -- File -- Hidden -- Image -- Month -- Number -- Password -- Radio -- Range -- Reset -- Search -- Submit -- Tel -- Text -- Time -- Url -- Week diff --git a/packages/inputs/src/lib.rs b/packages/inputs/src/lib.rs deleted file mode 100644 index 31e1bb209..000000000 --- a/packages/inputs/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/packages/liveview/.gitignore b/packages/liveview/.gitignore deleted file mode 100644 index 1d74e2196..000000000 --- a/packages/liveview/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.vscode/ diff --git a/packages/liveview/Cargo.toml b/packages/liveview/Cargo.toml deleted file mode 100644 index c32e0dc80..000000000 --- a/packages/liveview/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[package] -name = "dioxus-livehost" -version = "0.0.0" -authors = ["Jonathan Kelley "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -dioxus-core = { path = "../core", version = "0.1.2" } -dioxus-web = { path = "../web" } - - -serde = { version = "1", features = ['derive'] } -tide = "0.16.0" -tide-websockets = "0.3.0" -async-std = { version = "1.8.0", features = ["attributes"] } -log = "0.4" -fern = { version = "0.6.0", features = ["colored"] } -async-channel = "1.5.1" -futures-lite = "1.11.2" -anyhow = "1.0.35" - - -js-sys = { version = "0.3", optional = true } -wasm-bindgen = { version = "0.2.71", optional = true } -lazy_static = { version = "1.4.0", optional = true } -wasm-bindgen-futures = { version = "0.4.20", optional = true } - - -serde_millis = "0.1" -serde_json = "1" -strum = { version = "0.20", features = ["derive"] } - - -[features] -default = ["client", "server"] -server = [] -client = [] diff --git a/packages/liveview/README.md b/packages/liveview/README.md deleted file mode 100644 index f1c4f9b86..000000000 --- a/packages/liveview/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Livehost - -Stream events from a server to a client. - -This crate provides drivers for Actix, Warp, and Tide to run coupled frontend and backend. - -This comes in the form of two approaches: - -- tight coupling: frontend and backend are locked together -- loose coupling: hooks subscribe a component to a server using the suspense mechanism - -Tight coupling is basically an implmentation of loose coupling where **all** events move through the backend connection. This coupling option has higher latency but is very simple to deploy. We use this approach for dioxus-webview where latency is minimal (hosted locally) and we want builds to be simple - no need to manually bundle a custom frontend because everything is server rendered. - diff --git a/packages/liveview/examples/simpletide.rs b/packages/liveview/examples/simpletide.rs deleted file mode 100644 index d473de843..000000000 --- a/packages/liveview/examples/simpletide.rs +++ /dev/null @@ -1,131 +0,0 @@ -pub fn main() { - #[cfg(feature = "client")] - wasm_bindgen_futures::spawn_local(async { client::app().await.unwrap() }); - - #[cfg(feature = "server")] - async_std::task::block_on(async { server::app().await.expect("") }); -} - -/// =============================== -/// Common code (shared types) -/// =============================== -#[derive(PartialEq, strum::EnumIter, strum::Display, strum::AsRefStr, strum::EnumString)] -pub enum SelectedStream { - Football, - Hockey, - Socker, -} - -/// Client-specific code -#[cfg(feature = "client")] -mod client { - use super::*; - use dioxus_core::prelude::*; - use strum::IntoEnumIterator; - - pub async fn app() -> anyhow::Result<()> { - Ok(dioxus_web::WebsysRenderer::start(APP).await) - } - - static APP: FC<()> = |cx| { - todo!() - // let (selected_stream, set_stream) = use_state(cx, || SelectedStream::Football); - - // let opts = SelectedStream::iter().map(|name| rsx! { option { "{name}", value: "{name}" } }); - - // cx.render(rsx! { - // div { - // h1 { "Tide basic CRUD app" } - // h2 { "Chosen stream: {selected_stream}" } - // select { - // value: {selected_stream.as_ref()} - // "{selected_stream}" - // {opts} - // } - // } - // }) - }; -} - -/// Server-specific code -#[cfg(feature = "server")] -mod server { - use async_std::sync::RwLock; - pub use log::info; - use std::sync::Arc; - use tide::Request; - use tide_websockets::{Message, WebSocket, WebSocketConnection}; - - use crate::SelectedStream; - - // type ServerRequest = Request>>; - type ServerRequest = Request<()>; - // type ServerRequest = Request>>; - - static CLIENT_PATH: &'static str = ""; - - pub async fn app() -> anyhow::Result<()> { - let mut app = tide::new(); - - app.at("") - .serve_dir(format!("{}/pkg", CLIENT_PATH)) - .expect("Cannot serve directory"); - - app.at("/updates").get(WebSocket::new(socket_handler)); - - let addr = "0.0.0.0:9001"; - log::info!("Congrats! Server is up and running at http://{}", addr); - app.listen(addr).await?; - - Ok(()) - } - - async fn socket_handler( - request: ServerRequest, - stream: WebSocketConnection, - ) -> tide::Result<()> { - // clone the receiver channel - // subscribe to any updates - // let receiver = request.state().read().await.receiver.clone(); - // while let Ok(evt) = receiver.recv().await { - // let response_msg = serde_json::to_string(&evt)?; - // stream.send_string(response_msg).await?; - // } - - Ok(()) - } - - use dioxus_core::prelude::*; - - #[derive(PartialEq, Props)] - struct SreamListProps { - selected_stream: SelectedStream, - } - - static STREAM_LIST: FC = |cx| { - // - let g = match cx.selected_stream { - SelectedStream::Football => cx.render(rsx! { - li { - "watch football!" - } - }), - SelectedStream::Hockey => cx.render(rsx! { - li { - "watch football!" - } - }), - SelectedStream::Socker => cx.render(rsx! { - li { - "watch football!" - } - }), - }; - - cx.render(rsx! { - div { - - } - }) - }; -} diff --git a/packages/liveview/examples/tide.rs b/packages/liveview/examples/tide.rs deleted file mode 100644 index 5ea3f1fc5..000000000 --- a/packages/liveview/examples/tide.rs +++ /dev/null @@ -1,182 +0,0 @@ -pub fn main() { - #[cfg(feature = "client")] - wasm_bindgen_futures::spawn_local(async { client::app().await.unwrap() }); - - #[cfg(feature = "server")] - async_std::task::block_on(async { server::app().await.expect("") }); -} - -/// =============================== -/// Common code (shared types) -/// =============================== -#[derive(PartialEq, strum::EnumIter, strum::Display, strum::AsRefStr, strum::EnumString)] -pub enum SelectedStream { - Football, - Hockey, - Socker, -} - -/// Client-specific code -#[cfg(feature = "client")] -mod client { - use super::*; - use dioxus_core::prelude::*; - use strum::IntoEnumIterator; - - pub async fn app() -> anyhow::Result<()> { - Ok(dioxus_web::WebsysRenderer::start(APP).await) - } - - static APP: FC<()> = |cx| { - todo!() - // let (selected_stream, set_stream) = use_state(cx, || SelectedStream::Football); - - // let opts = SelectedStream::iter().map(|name| rsx! { option { "{name}", value: "{name}" } }); - - // cx.render(rsx! { - // div { - // h1 { "Tide basic CRUD app" } - // h2 { "Chosen stream: {selected_stream}" } - // select { - // value: {selected_stream.as_ref()} - // "{selected_stream}" - // {opts} - // } - // } - // }) - }; -} - -/// Server-specific code -#[cfg(feature = "server")] -mod server { - use async_std::sync::RwLock; - pub use log::info; - use std::sync::Arc; - use tide::Request; - use tide_websockets::{Message, WebSocket, WebSocketConnection}; - - use crate::SelectedStream; - - // type ServerRequest = Request>>; - type ServerRequest = Request<()>; - // type ServerRequest = Request>>; - - static CLIENT_PATH: &'static str = ""; - - pub async fn app() -> anyhow::Result<()> { - let mut app = tide::new(); - - app.at("") - .serve_dir(format!("{}/pkg", CLIENT_PATH)) - .expect("Cannot serve directory"); - - app.at("/updates").get(WebSocket::new(socket_handler)); - - let addr = "0.0.0.0:9001"; - log::info!("Congrats! Server is up and running at http://{}", addr); - app.listen(addr).await?; - - Ok(()) - } - - async fn socket_handler( - request: ServerRequest, - stream: WebSocketConnection, - ) -> tide::Result<()> { - // clone the receiver channel - // subscribe to any updates - // let receiver = request.state().read().await.receiver.clone(); - // while let Ok(evt) = receiver.recv().await { - // let response_msg = serde_json::to_string(&evt)?; - // stream.send_string(response_msg).await?; - // } - - Ok(()) - } - - use dioxus_core::prelude::*; - - #[derive(PartialEq, Props)] - struct SreamListProps { - selected_stream: SelectedStream, - } - - static STREAM_LIST: FC = |cx| { - // - match cx.selected_stream { - SelectedStream::Football => cx.render(rsx! { - li { - "watch football!" - } - }), - - _ => unimplemented!() - // .render(cx), - // SelectedStream::Hockey => rsx! { - // li { - // "watch football!" - // } - // } - // .render(cx), - // SelectedStream::Socker => rsx! { - // li { - // "watch football!" - // } - // } - // .render(cx), - } - }; -} - -mod ergorsx { - - // struct Ncx {} - - // struct VVNode {} - // struct DTree { - // // struct DTree VVNode> { - // caller: F, - // } - // impl VVNode> DTree { - // fn new(f: F) -> Self { - // Self { caller: f } - // } - // } - - // trait Renderable { - // fn render(self, nodecx: &Ncx) -> VVNode; - // } - - // impl VVNode> Renderable for DTree { - // fn render(self, nodecx: &Ncx) -> VVNode { - // (self.caller)(nodecx) - // } - // } - - // fn test() { - // let t = 123; - // let r = match t { - // 123 => DTree::new(|f| VVNode {}).render(cx), - // 456 => DTree::new(|f| VVNode {}).render(cx), - // 789 => DTree::new(|f| VVNode {}).render(cx), - // _ => unreachable!(), - // }; - // } - - // fn example() { - // rsx! { - // div { - - // } - // }.render(cx) - // } - - // fn example() { - // cx.render(rsx!{ - // div { - - // } - // }) - // } -} diff --git a/packages/liveview/index.html b/packages/liveview/index.html deleted file mode 100644 index a389534a6..000000000 --- a/packages/liveview/index.html +++ /dev/null @@ -1,294 +0,0 @@ - - - - - - - - - -
- - - diff --git a/packages/liveview/src/handlers/h_actix.rs b/packages/liveview/src/handlers/h_actix.rs deleted file mode 100644 index 7f285a019..000000000 --- a/packages/liveview/src/handlers/h_actix.rs +++ /dev/null @@ -1 +0,0 @@ -//! Request handler for actix diff --git a/packages/liveview/src/handlers/h_rocket.rs b/packages/liveview/src/handlers/h_rocket.rs deleted file mode 100644 index b010d8767..000000000 --- a/packages/liveview/src/handlers/h_rocket.rs +++ /dev/null @@ -1 +0,0 @@ -//! Request handler for rocket diff --git a/packages/liveview/src/handlers/h_tide.rs b/packages/liveview/src/handlers/h_tide.rs deleted file mode 100644 index 41a06a713..000000000 --- a/packages/liveview/src/handlers/h_tide.rs +++ /dev/null @@ -1 +0,0 @@ -//! Request handler for tide diff --git a/packages/liveview/src/handlers/h_warp.rs b/packages/liveview/src/handlers/h_warp.rs deleted file mode 100644 index 692749dd6..000000000 --- a/packages/liveview/src/handlers/h_warp.rs +++ /dev/null @@ -1 +0,0 @@ -//! Request handler for warp diff --git a/packages/liveview/src/lib.rs b/packages/liveview/src/lib.rs deleted file mode 100644 index db5bb1352..000000000 --- a/packages/liveview/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod handlers { - - pub mod h_actix; - - pub mod h_rocket; - - pub mod h_tide; - - pub mod h_warp; -} diff --git a/packages/ios/Cargo.toml b/packages/mobile/Cargo.toml similarity index 100% rename from packages/ios/Cargo.toml rename to packages/mobile/Cargo.toml diff --git a/packages/ios/README.md b/packages/mobile/README.md similarity index 100% rename from packages/ios/README.md rename to packages/mobile/README.md diff --git a/packages/ios/src/lib.rs b/packages/mobile/src/lib.rs similarity index 100% rename from packages/ios/src/lib.rs rename to packages/mobile/src/lib.rs diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml deleted file mode 100644 index 5e8480a60..000000000 --- a/packages/router/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "dioxus-router" -version = "0.0.0" -authors = ["Jonathan Kelley "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] \ No newline at end of file diff --git a/packages/router/README.md b/packages/router/README.md deleted file mode 100644 index e89684965..000000000 --- a/packages/router/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# Router hook for Dioxus apps - -Dioxus-router provides a use_router hook that returns a different value depending on the route. -The router is generic over any value, however it makes sense to return a different set of VNodes -and feed them into the App's return VNodes. - -Using the router should feel similar to tide's routing framework where an "address" book is assembled at the head of the app. - -Here's an example of how to use the router hook: - -```rust -static App: FC<()> = |cx| { - - // Route returns the associated VNodes - // This hook re-fires when the route changes - let route = use_router(cx, |router| { - router.at("/").get(|path| { - rsx!{ } - }); - router.at("/shoes/:id").get(|path| { - let id: Uuid = path.parse().unwrap(); - rsx!{ } - }); - router.at("/pants/:id").get(|path| { - let id: Uuid = path.parse().unwrap(); - rsx!{ } - }); - }); - - cx.render(rsx!{ - div { - Navbar {} - {route} - Footer {} - } - }) -}; -``` - -Currently, the router is only supported in a web environment, but we plan to add 1st-party support via the context API when new renderers are available. diff --git a/packages/router/src/lib.rs b/packages/router/src/lib.rs deleted file mode 100644 index 31e1bb209..000000000 --- a/packages/router/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/src/lib.rs b/src/lib.rs index ebac40005..10168029d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,10 +218,3 @@ pub mod testing { } #[cfg(feature = "atoms")] pub mod atoms {} - -// #[cfg(feature = "desktop")] -pub mod webview { - //! A webview based renderer for building desktop applications with Dioxus - use dioxus_core::prelude::{Properties, FC}; - pub fn launch(f: FC

) {} -}