Skip to content

Commit

Permalink
[EpicsDAO#6] generate new project instead of downloading a ZIP template
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasCir committed Oct 5, 2022
1 parent efd2671 commit 7cd4c2e
Show file tree
Hide file tree
Showing 31 changed files with 196 additions and 249 deletions.
39 changes: 5 additions & 34 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -18,7 +18,6 @@ path = "src/main.rs"
clap = { version = "3.1.15", features = ["derive", "cargo"] }
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
serde_yaml = "0.8.24"
console = "0.15.0"
regex = "1.5.6"
chrono = "0.4"
Expand Down
1 change: 1 addition & 0 deletions resources/templates/new/.dockerignore
@@ -0,0 +1 @@
.env
File renamed without changes.
45 changes: 21 additions & 24 deletions src/new/resources/Cargo.toml → resources/templates/new/Cargo.toml
@@ -1,45 +1,42 @@
[package]
name = "barbaz"
name = "{{ app_name }}"
version = "0.1.0"
edition = "2021"
rust-version= "1.64"
rust-version = "1.64"

[workspace]
members = [".", "entity", "migration"]

[workspace.dependencies]
tokio = { version = "1.0", features = ["full"] }
# graphql base library
async-graphql = { version = "4.0.13", features = ["chrono"] }
# graphql integration for axum web framework
async-graphql-axum = "4.0.13"
# async std lib: used by migration crate
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
# our general web framework
axum = "^0.5.1"
# read dotenv files in main.rs
dotenv = "0.15.0"
async-graphql-axum = "4.0.13"
async-graphql = { version = "4.0.13", features = ["chrono"] }
# generated local entities
entity = { path = "entity" }
# generated local migrations
migration = { path = "migration" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
jsonwebtoken = "8"
chrono = "0.4.19"
axum-auth = "0.3.0"
fireauth = "0.1.5"
# database connection and orm
sea-orm = { version = "0.9.2", features = ["runtime-tokio-native-tls", "sqlx-postgres"] }
async-std = "1.12.0"
# migrate database before startup
sea-orm-migration = "0.9.2"
# asnyc runtime: used by main.rs
tokio = { version = "1.0", features = ["full"] }

[dependencies]

tokio = { workspace = true }
axum = { workspace = true }
dotenv = { workspace = true }
async-graphql-axum = { workspace = true }
async-graphql = { workspace = true }
async-graphql-axum = { workspace = true }
async-std = { workspace = true }
axum = {workspace = true}
dotenv = { workspace = true }
entity = { workspace = true }
migration = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
jsonwebtoken = { workspace = true }
chrono = { workspace = true }
axum-auth = { workspace = true }
fireauth = { workspace = true }
sea-orm = { workspace = true }
async-std = { workspace = true }
sea-orm-migration = { workspace = true }
tokio = { workspace = true }
Expand Up @@ -5,7 +5,7 @@ COPY entity entity
COPY migration migration
COPY Cargo.toml Cargo.toml
RUN cargo build --release
COPY ./src ./src
COPY src ./src
COPY entity/src entity/src
COPY migration/src migration/src
RUN rm -f target/release/deps/{{ underscore_app_name }}*
Expand Down
File renamed without changes.
Expand Up @@ -9,6 +9,4 @@ name = "entity"
path = "src/lib.rs"

[dependencies]
serde = { workspace = true }
async-graphql = { workspace = true }
sea-orm = { workspace = true }
sea-orm = { workspace = true }
1 change: 1 addition & 0 deletions resources/templates/new/entity/src/lib.rs
@@ -0,0 +1 @@

@@ -1,5 +1,5 @@
use sea_orm::DatabaseConnection;
use dotenv::dotenv;
use sea_orm::DatabaseConnection;

pub struct Database {
pub connection: DatabaseConnection,
Expand All @@ -18,4 +18,4 @@ impl Database {
pub fn get_connection(&self) -> &DatabaseConnection {
&self.connection
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,7 +1,6 @@
mod db;
mod graphql;

use std::env;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
use axum::{
Expand All @@ -11,6 +10,7 @@ use axum::{
Router,
};
use graphql::schema::{build_schema, ZappSchema};
use std::env;

#[cfg(debug_assertions)]
use dotenv::dotenv;
Expand Down Expand Up @@ -45,4 +45,4 @@ async fn main() {
.serve(app.into_make_service())
.await
.unwrap();
}
}
13 changes: 3 additions & 10 deletions src/docker/process.rs
Expand Up @@ -2,10 +2,9 @@ use crate::style_print::*;
use std::process::Command;
use std::str;


pub fn process_psql_docker() {
create_docker_network();
process_docker_psql("zapp-psql");
process_docker_psql();
}

pub fn process_docker_build(project_id: &str, service_name: &str, gcr_region: &str) {
Expand Down Expand Up @@ -38,25 +37,19 @@ pub fn process_docker_restart() {
let _output2 = Command::new("zapp").args(&["docker", "psql"]).output();
}

fn process_docker_psql(service_name: &str) {
let underscored_name = service_name.to_string().replace("-", "_");
let container_name = String::from(service_name) + "-psql";
let db_name = String::from("POSTGRES_DB=") + &underscored_name + "_db";
fn process_docker_psql() {

let output = Command::new("docker")
.args(&[
"run",
"--rm",
"-d",
"--name",
&container_name,
"-p",
"5432:5432",
"-e",
"POSTGRES_USER=postgres",
"-e",
"POSTGRES_PASSWORD=postgres",
"-e",
&db_name,
"--network=zapp",
"postgres:14.3-alpine",
])
Expand Down
4 changes: 2 additions & 2 deletions src/g/entity/creation.rs
Expand Up @@ -22,7 +22,7 @@ pub(super) fn create_entity(model: &str, entity_src_dir: &Path) {

fn create_model_tokens(model_str: &str) -> TokenStream {
let model = format_ident!("{}", model_str);
let cap_model = format_ident!("{}", to_upper_camel(model_str));
let _cap_model = format_ident!("{}", to_upper_camel(model_str));

quote! {
use async_graphql::*;
Expand All @@ -31,7 +31,7 @@ fn create_model_tokens(model_str: &str) -> TokenStream {

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize, SimpleObject)]
#[sea_orm(table_name = #model)]
#[graphql(concrete(name = "#cap_model", params()))]
#[graphql(concrete(name = "#_cap_model", params()))]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
Expand Down
5 changes: 0 additions & 5 deletions src/init/process.rs
@@ -1,6 +1,5 @@
use super::actions_yml::*;
use crate::style_print::*;
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::fs;
use std::fs::File;
Expand All @@ -10,10 +9,6 @@ use std::path::Path;
use std::process::Command;
use std::str;

fn regex(re_str: &str) -> Regex {
Regex::new(re_str).unwrap()
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GcpConfig {
pub project_id: String,
Expand Down
2 changes: 0 additions & 2 deletions src/main.rs
Expand Up @@ -221,8 +221,6 @@ fn main() {
}
}



pub fn get_gcp() -> GcpConfig {
let file_name = "gcp_config.json";
let f = File::open(file_name).unwrap();
Expand Down
13 changes: 6 additions & 7 deletions src/new/generation/entity_dir/mod.rs
@@ -1,20 +1,19 @@
mod src_dir;

use crate::new::generation::create_and_write_file;
use crate::new::generation::entity_dir::src_dir::populate_src_dir;
use crate::template_file;
use std::fs;
use std::io::Write;
use std::path::Path;

pub(super) fn populate_entity_dir(gen_path: &Path, app_name: &str) {
let entity_dir = gen_path.join("entity");
fs::create_dir(&entity_dir).unwrap();

emit_cargo_toml(&entity_dir, &app_name);
populate_src_dir(&entity_dir, &app_name);
}

fn emit_cargo_toml(gen_path: &Path, app_name: &str) {
let filename = gen_path.join("Cargo.toml");
let cargo_toml = include_str!("../../resources/entity/Cargo.toml");
create_and_write_file(&filename, &cargo_toml);
template_file!(
"../../../../resources/templates/new/entity/Cargo.toml",
&entity_dir.join("Cargo.toml")
);
}
16 changes: 7 additions & 9 deletions src/new/generation/entity_dir/src_dir/mod.rs
@@ -1,16 +1,14 @@
use crate::new::generation::create_and_write_file;
use crate::template_file;
use std::fs;
use std::io::Write;
use std::path::Path;

pub(super) fn populate_src_dir(gen_path: &Path, app_name: &str) {
pub(super) fn populate_src_dir(gen_path: &Path, _app_name: &str) {
let src_dir = gen_path.join("src");
fs::create_dir(&src_dir).unwrap();

emit_lib_rs(&src_dir, &app_name);
}

fn emit_lib_rs(gen_path: &Path, app_name: &&str) {
let filename = gen_path.join("lib.rs");
let lib_rs = include_str!("../../../resources/entity/src/lib.rs");
create_and_write_file(&filename, lib_rs);
template_file!(
"../../../../../resources/templates/new/entity/src/lib.rs",
&src_dir.join("lib.rs")
);
}

0 comments on commit 7cd4c2e

Please sign in to comment.