Skip to content

Commit

Permalink
Hotfix#314 (#315)
Browse files Browse the repository at this point in the history
* chore: fmt

* fix: Compilation error after creating the app  #314

* chore: clippy
  • Loading branch information
AnthonyMichaelTDM authored Aug 27, 2023
1 parent 7be0062 commit 6d07b20
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 67 deletions.
4 changes: 2 additions & 2 deletions create-rust-app/src/dev/dev_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ pub async fn start(
let app = Router::new()
.route("/", get(|| async {
// Let user know the server is running
Html(r###"
Html(r#"
<html style="background-color: #171717; height: 100%; width: 100%;">
<head><title>Create Rust App: Development Server</title></head>
<body style="text-align: center; color: white; fony-family: sans-serif; padding: 50px;">
<img style="margin-right: 12px" height="50px" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJwAAACcCAYAAACKuMJNAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAGIpJREFUeJztnXtUU1faxp8QUEAJWBG8gFaRq5RRq6Aig1ipYnGEgrIqFagjrVYHPu1iUOmI2mLVpehotTKOVYttLV5oB0cEvLTcvFSgIAJjURABFUQQkWuS/f3BkDEkQHKSnCSwf2udtTjZt/eEJ2fvc/a73w38Dy6AIABXADwDQOhBDwWOZwAuA1gOQAfdeA3AzxpgJD3653EFwDAA4KDzznYZgDsoFNVxFcA8Ljpvef+nZmMo/Z/xAEq5APb+94RCUTXGHAD1AEzUbQllQPCMg85BHYXCChKPqxSKKqGCo7AKFRyFVajgKKxCBUdhFSo4CqtQwVFYhQqOwiq6qqxcX18fBgYGqmyCogG0tbWhublZ5vwqc0uJiooilP7PoUOHZNYE7VIprEIFR2EVKjgKq6j0oUEaWVlZqK6uZrtZipIwNjbG22+/zbg864LbuXMnkpKS2G6WoiScnJwUEhztUimsQgVHYRXGgrO3t8eECROUaYvW4+7ujo0bN8LIyEjdpmgsjARna2uLS5cuYdiw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7CKlRwFFahgqOwChUchVV0ANSr2wjKgKFOB0Ceuq2gDBjydAAcV7cVlAHDcQ46u9VLADzUbAylf3MFgKcOACEAPwDUX5yiKi4D8Een1kToAHgfnXe7OmjAvk700OrjKYA0AIF45W3I/wOF92+1NRY5lQAAAABJRU5ErkJggg==" alt="" />
<h3>Create Rust App: Development Server</h3>
</body>
</html>
"###)
"#)
}))
.route("/vitejs-down", get(vitejs_down_handler))
.route("/vitejs-up", get(vitejs_up_handler))
Expand Down
4 changes: 2 additions & 2 deletions create-rust-app_cli/src/content/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ fn add_bins_to_cargo_toml(
.cra_enabled_features
.contains(&"plugin_tasks".to_string())
{
r##"
r#"
[[bin]]
name = "queue"
path = "backend/queue.rs"
"##
"#
} else {
""
};
Expand Down
17 changes: 8 additions & 9 deletions create-rust-app_cli/src/plugins/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,14 @@ impl Plugin for Dev {

fs::append(
"frontend/src/dev.tsx",
indoc! {r##"
// Sets up the development environment.
//
// Note: When running `cargo frontend` and `cargo backend` individually, "DEV_SERVER_PORT" is not set.
// Use `cargo fullstack` for the full development experience.
if (import.meta.env.DEV_SERVER_PORT) {
import('./setupDevelopment')
}
"##},
indoc! {r#"// Sets up the development environment.
//
// Note: When running `cargo frontend` and `cargo backend` individually, "DEV_SERVER_PORT" is not set.
// Use `cargo fullstack` for the full development experience.
if (import.meta.env.DEV_SERVER_PORT) {
import('./setupDevelopment')
}
"#},
)?;

match install_config.backend_framework {
Expand Down
14 changes: 7 additions & 7 deletions create-rust-app_cli/src/plugins/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ import { GraphQLPage } from './containers/GraphQLPage'"#,
fs::replace(
"frontend/bundles/index.tsx",
"ReactDOM.createRoot",
r##"import {ApolloProvider} from "@apollo/client";
r#"import {ApolloProvider} from "@apollo/client";
import {useAuthenticatedApolloClient} from "../src/hooks/useAuthenticatedApolloClient";
const AuthenticatedApolloProvider = (props: { children: React.ReactNode }) => {
Expand All @@ -96,7 +96,7 @@ const AuthenticatedApolloProvider = (props: { children: React.ReactNode }) => {
</ApolloProvider>
}
ReactDOM.createRoot"##,
ReactDOM.createRoot"#,
)?;

fs::replace(
Expand All @@ -108,18 +108,18 @@ ReactDOM.createRoot"##,

fs::replace(
"frontend/package.json",
r##""dependencies": {"##,
r##""dependencies": {
r#""dependencies": {"#,
r#""dependencies": {
"@apollo/client": "^3.5.10",
"graphql-ws": "^5.6.4",
"graphql": "^16.3.0","##,
"graphql": "^16.3.0","#,
)?;

fs::replace("backend/main.rs", "mod mail;", "mod mail;\nmod graphql;")?;

// update auth plugin's logout button
let old_logout_link = r##"{ auth.isAuthenticated && <a className="NavButton" onClick={() => auth.logout()}>Logout</a> }"##;
let new_logout_link = r##"{ auth.isAuthenticated && <a className="NavButton" onClick={() => { auth.logout(); apollo.resetStore(); }}>Logout</a> }"##;
let old_logout_link = r#"{ auth.isAuthenticated && <a className="NavButton" onClick={() => auth.logout()}>Logout</a> }"#;
let new_logout_link = r#"{ auth.isAuthenticated && <a className="NavButton" onClick={() => { auth.logout(); apollo.resetStore(); }}>Logout</a> }"#;
fs::replace("frontend/src/App.tsx", old_logout_link, new_logout_link)?;

// make sure auth plugin is wrapped on top
Expand Down
45 changes: 22 additions & 23 deletions create-rust-app_cli/src/plugins/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,28 @@ impl Plugin for Tasks {

crate::content::migration::create(
"plugin_tasks",
indoc! {r##"
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE fang_task_state AS ENUM ('new', 'in_progress', 'failed', 'finished', 'retried');
CREATE TABLE fang_tasks (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
metadata jsonb NOT NULL,
error_message TEXT,
state fang_task_state DEFAULT 'new' NOT NULL,
task_type VARCHAR DEFAULT 'common' NOT NULL,
uniq_hash CHAR(64),
retries INTEGER DEFAULT 0 NOT NULL,
scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE INDEX fang_tasks_state_index ON fang_tasks(state);
CREATE INDEX fang_tasks_type_index ON fang_tasks(task_type);
CREATE INDEX fang_tasks_scheduled_at_index ON fang_tasks(scheduled_at);
CREATE INDEX fang_tasks_uniq_hash ON fang_tasks(uniq_hash);
"##},
indoc! {r#"CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TYPE fang_task_state AS ENUM ('new', 'in_progress', 'failed', 'finished', 'retried');
CREATE TABLE fang_tasks (
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
metadata jsonb NOT NULL,
error_message TEXT,
state fang_task_state DEFAULT 'new' NOT NULL,
task_type VARCHAR DEFAULT 'common' NOT NULL,
uniq_hash CHAR(64),
retries INTEGER DEFAULT 0 NOT NULL,
scheduled_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
CREATE INDEX fang_tasks_state_index ON fang_tasks(state);
CREATE INDEX fang_tasks_type_index ON fang_tasks(task_type);
CREATE INDEX fang_tasks_scheduled_at_index ON fang_tasks(scheduled_at);
CREATE INDEX fang_tasks_uniq_hash ON fang_tasks(uniq_hash);
"#},
r#"DROP TABLE fang_tasks;"#,
)?;

Expand Down
54 changes: 30 additions & 24 deletions create-rust-app_cli/template/.cargo/bin/dsync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::path::PathBuf;
use dsync;
use dsync::{GenerationConfig, TableOptions};
use std::collections::HashMap;
use std::path::PathBuf;

pub fn main() {
let dir = env!("CARGO_MANIFEST_DIR");
Expand All @@ -13,32 +13,38 @@ pub fn main() {

ensure_schema_is_generated(&schema_file);

dsync::generate_files(schema_file, models_dir, GenerationConfig {
connection_type: "create_rust_app::Connection".to_string(),
default_table_options: TableOptions::default()
.tsync()
.autogenerated_columns(vec!["id", "created_at", "updated_at"]),
table_options: HashMap::from([
// plugin_storage
("attachment_blobs", TableOptions::default().ignore()),
("attachments", TableOptions::default().ignore()),

// plugin_auth
("role_permissions", TableOptions::default().ignore()),
("user_permissions", TableOptions::default().ignore()),
("user_roles", TableOptions::default().ignore()),
("user_sessions", TableOptions::default().ignore()),
("users", TableOptions::default().ignore()),

// plugin_tasks
("fang_tasks", TableOptions::default().ignore()),
]),
});
dsync::generate_files(
schema_file,
models_dir,
GenerationConfig {
connection_type: "create_rust_app::Connection".to_string(),
default_table_options: TableOptions::default().tsync().autogenerated_columns(vec![
"id",
"created_at",
"updated_at",
]),
table_options: HashMap::from([
// plugin_storage
("attachment_blobs", TableOptions::default().ignore()),
("attachments", TableOptions::default().ignore()),
// plugin_auth
("role_permissions", TableOptions::default().ignore()),
("user_permissions", TableOptions::default().ignore()),
("user_roles", TableOptions::default().ignore()),
("user_sessions", TableOptions::default().ignore()),
("users", TableOptions::default().ignore()),
// plugin_tasks
("fang_tasks", TableOptions::default().ignore()),
]),
model_path: "crate::models::".to_string(),
schema_path: "crate::schema::".to_string(),
},
);
}

pub fn ensure_schema_is_generated(schema_file: &PathBuf) {
// check that the diesel schema file is not empty
let content = std::fs::read_to_string(schema_file).unwrap_or_default();
let content = std::fs::read_to_string(schema_file).unwrap_or_default();

if content.trim().is_empty() {
println!("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
Expand Down

0 comments on commit 6d07b20

Please sign in to comment.