a
This commit is contained in:
parent
33cea5bc3d
commit
3fd7a59a8e
13 changed files with 2824 additions and 141 deletions
2713
Cargo.lock
generated
2713
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,4 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"backend",
|
||||
"syntax",
|
||||
"driver",
|
||||
]
|
||||
|
|
|
@ -4,6 +4,13 @@ version = "0.1.0"
|
|||
authors = ["Michael Zhang <iptq@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
gluon = { version = "0.14.1", features = ["serialization"] }
|
||||
serde_derive = "1.0.106"
|
||||
serde = "1.0.106"
|
||||
toml = "0.5.6"
|
||||
anyhow = "1.0.28"
|
||||
serde_json = "1.0.51"
|
||||
sqlx = { version = "0.3.4", features = ["sqlite"] }
|
||||
warp = "0.2.2"
|
||||
tokio = { version = "0.2.18", features = ["full"] }
|
||||
|
|
|
@ -1,7 +1,95 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
use std::convert::Infallible;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use gluon::ThreadExt;
|
||||
use anyhow::Result;
|
||||
use toml::Value;
|
||||
use warp::Filter;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct FrontConfig {
|
||||
models: Option<String>,
|
||||
routes: Option<HashMap<String, Value>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Handler {
|
||||
App(App),
|
||||
Func(),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct App {
|
||||
routes: HashMap<String, Handler>,
|
||||
}
|
||||
|
||||
pub fn build_app(path: impl AsRef<Path>) -> Result<App> {
|
||||
let path = path.as_ref();
|
||||
let mut contents = String::new();
|
||||
let mut file = File::open(path)?;
|
||||
file.read_to_string(&mut contents)?;
|
||||
|
||||
let parsed_config = toml::from_str::<FrontConfig>(&contents)?;
|
||||
println!("Config: {:?}", parsed_config);
|
||||
|
||||
let mut routes = HashMap::new();
|
||||
let mut process_path = |route: &str, value: &Value| -> Result<()> {
|
||||
if let Some(path_str) = value
|
||||
.as_table()
|
||||
.and_then(|table| table.get("path"))
|
||||
.and_then(|value| value.as_str())
|
||||
{
|
||||
let dir = path.parent().unwrap();
|
||||
let new_path = dir.join(path_str).join("_front.toml");
|
||||
if new_path.exists() {
|
||||
println!("new_path: {:?}", new_path);
|
||||
let app = build_app(new_path)?;
|
||||
routes.insert(route.to_string(), app);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
|
||||
if let Some(route_cfg) = parsed_config.routes {
|
||||
for (route, config) in route_cfg {
|
||||
if let Some(list) = config.as_array() {
|
||||
for value in list {
|
||||
process_path(&route, value)?;
|
||||
}
|
||||
} else {
|
||||
process_path(&route, &config)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(models) = parsed_config.models {
|
||||
let dir = path.parent().unwrap();
|
||||
let models_path = dir.join(models + ".glu");
|
||||
if models_path.exists() {
|
||||
let mut contents = String::new();
|
||||
let mut file = File::open(models_path)?;
|
||||
file.read_to_string(&mut contents)?;
|
||||
|
||||
let vm = gluon::new_vm();
|
||||
// vm.load_file(models_path.to_str().unwrap())?;
|
||||
let (result, _) = vm.run_expr::<String>("models", &contents)?;
|
||||
println!("OUAIS {:?}", result);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(App { routes })
|
||||
}
|
||||
|
||||
pub fn build_config_from_root(path: impl AsRef<Path>) -> Result<App> {
|
||||
build_app(path)
|
||||
}
|
||||
|
||||
pub fn create_filter(app: App) -> impl Filter<Extract = (&'static str,), Error = Infallible> + Clone {
|
||||
warp::any().map(|| "hello")
|
||||
}
|
||||
|
|
12
backend/src/main.rs
Normal file
12
backend/src/main.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use anyhow::Result;
|
||||
use warp::Filter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let app = backend::build_config_from_root("/home/michael/Projects/enterprise/examples/realworld/_front.toml")?;
|
||||
let filter = backend::create_filter(app);
|
||||
|
||||
warp::serve(filter).run(([127u8, 0, 0, 1], 3000)).await;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "driver"
|
||||
version = "0.1.0"
|
||||
authors = ["Michael Zhang <iptq@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -1,27 +0,0 @@
|
|||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(str_strip)]
|
||||
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_driver;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_errors;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_interface;
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_middle;
|
||||
|
||||
use rustc_driver::Callbacks;
|
||||
|
||||
struct DefaultCallbacks;
|
||||
impl Callbacks for DefaultCallbacks {}
|
||||
|
||||
fn main() {
|
||||
rustc_driver::run_compiler(
|
||||
&[String::from("rustc"), String::from("main.rs")],
|
||||
&mut DefaultCallbacks,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
|
||||
|
||||
[routes]
|
||||
admin = { path = "admin" }
|
||||
api = [
|
||||
{ path = "articles" },
|
||||
{ path = "auth" },
|
||||
{ path = "profiles" },
|
||||
]
|
|
@ -1 +0,0 @@
|
|||
master
|
|
@ -1,36 +0,0 @@
|
|||
#!/bin/bash
|
||||
# Set up the appropriate rustc toolchain
|
||||
|
||||
set -e
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
RTIM_PATH=$(command -v rustup-toolchain-install-master) || INSTALLED=false
|
||||
CARGO_HOME=${CARGO_HOME:-$HOME/.cargo}
|
||||
|
||||
# Check if RTIM is not installed or installed in other locations not in ~/.cargo/bin
|
||||
if [[ "$INSTALLED" == false || "$RTIM_PATH" == $CARGO_HOME/bin/rustup-toolchain-install-master ]]; then
|
||||
cargo +nightly install rustup-toolchain-install-master
|
||||
else
|
||||
VERSION=$(rustup-toolchain-install-master -V | grep -o "[0-9.]*")
|
||||
REMOTE=$(cargo +nightly search rustup-toolchain-install-master | grep -o "[0-9.]*")
|
||||
echo "info: skipping updating rustup-toolchain-install-master at $RTIM_PATH"
|
||||
echo " current version : $VERSION"
|
||||
echo " remote version : $REMOTE"
|
||||
fi
|
||||
|
||||
RUST_COMMIT=$(git ls-remote https://github.com/rust-lang/rust master | awk '{print $1}')
|
||||
|
||||
if rustc +master -Vv 2>/dev/null | grep -q "$RUST_COMMIT"; then
|
||||
echo "info: master toolchain is up-to-date"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ -n "$HOST_TOOLCHAIN" ]]; then
|
||||
TOOLCHAIN=('--host' "$HOST_TOOLCHAIN")
|
||||
else
|
||||
TOOLCHAIN=()
|
||||
fi
|
||||
|
||||
rustup-toolchain-install-master -f -n master "${TOOLCHAIN[@]}" -c rustc-dev -- "$RUST_COMMIT"
|
||||
rustup override set master
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
name = "syntax"
|
||||
version = "0.1.0"
|
||||
authors = ["Michael Zhang <iptq@protonmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -1,7 +0,0 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn it_works() {
|
||||
assert_eq!(2 + 2, 4);
|
||||
}
|
||||
}
|
29
todomvc.ent
29
todomvc.ent
|
@ -1,29 +0,0 @@
|
|||
component TodoMVC {
|
||||
model {
|
||||
value: String,
|
||||
todos: List<String>,
|
||||
}
|
||||
|
||||
view {
|
||||
InputBox [
|
||||
bind:text = model.value,
|
||||
on:submit (model, event) => { },
|
||||
] {
|
||||
|
||||
}
|
||||
|
||||
List {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
component Navbar {
|
||||
model {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
component InputBox {
|
||||
|
||||
}
|
Loading…
Reference in a new issue