Skip to content

Commit

Permalink
MVP
Browse files Browse the repository at this point in the history
  • Loading branch information
DobromirM committed Sep 8, 2023
1 parent 2661947 commit 983c190
Show file tree
Hide file tree
Showing 11 changed files with 502 additions and 13 deletions.
105 changes: 99 additions & 6 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ edition = "2021"

[dependencies]
clap = { version = "4.3.19", features = ["derive"] }
boilerplate = "1.0.0"
76 changes: 69 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,84 @@
use std::fs;
use clap::Parser;
use boilerplate;
use boilerplate::Boilerplate;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Name of the project
#[arg(short, long)]
name: String,
#[arg(short, long, default_value = "test")]
plane: String,
#[arg(short, long, default_value_t = 9001)]
/// Port of the Swim application
#[arg(long, default_value_t = 9001)]
port: u16,
#[arg(short, long, default_value = "4.0.1")]
version: String,
/// Version of the Swim application
#[arg(long, default_value = "4.0.1")]
swim_version: String,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "settings.gradle")]
struct SettingsGradle<'a> {
name: &'a String,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "build.gradle")]
struct BuildGradle<'a, 'b> {
name: &'a String,
swim_version: &'b String,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "MainPlane.java")]
struct MainPlaneJava<'a> {
name: &'a String,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "module-info.java")]
struct ModuleInfoJava<'a> {
name: &'a String,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "server.recon")]
struct ServerRecon<'a> {
name: &'a String,
port: u16,
}

#[derive(Boilerplate)]
#[boilerplate(filename = "gradlew")]
struct Gradlew;

#[derive(Boilerplate)]
#[boilerplate(filename = "gradlew.bat")]
struct GradlewBat;


#[derive(Boilerplate)]
#[boilerplate(filename = "test/.gitignore")]
struct Gitignore;

fn main() {
let args = Args::parse();

println!("Hello {}!", args.name)
println!("Name: {}", args.name);
println!("Port: {}", args.port);
println!("Swim version: {}", args.swim_version);

fs::create_dir(&args.name).unwrap();
fs::create_dir_all(format!("{0}/src/main/java/{0}", args.name)).unwrap();
fs::create_dir_all(format!("{0}/src/main/resources", args.name)).unwrap();

fs::write(format!("{0}/{SETTINGS_GRADLE}", args.name), SettingsGradle { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/build.gradle", args.name), BuildGradle { name: &args.name, swim_version: &args.swim_version }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/.gitignore", args.name), Gitignore.to_string()).expect("Unable to write file");
fs::write(format!("{0}/gradlew", args.name), Gradlew.to_string()).expect("Unable to write file");
fs::write(format!("{0}/gradlew.bat", args.name), GradlewBat.to_string()).expect("Unable to write file");

fs::write(format!("{0}/src/main/java/{0}/MainPlane.java", args.name), MainPlaneJava { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/src/main/java/module-info.java", args.name), ModuleInfoJava { name: &args.name }.to_string()).expect("Unable to write file");
fs::write(format!("{0}/src/main/resources/server.recon", args.name), ServerRecon { name: &args.name, port: args.port }.to_string()).expect("Unable to write file");
}
4 changes: 4 additions & 0 deletions templates/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.gradle
gradle
build
16 changes: 16 additions & 0 deletions templates/MainPlane.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package {{self.name}};

import swim.api.plane.AbstractPlane;
import swim.kernel.Kernel;
import swim.server.ServerLoader;

public class MainPlane extends AbstractPlane {

public static void main(String[] args) {
final Kernel kernel = ServerLoader.loadServer();
System.out.println("Starting server...");
kernel.start();
System.out.println("Running server...");
kernel.run();
}
}
13 changes: 13 additions & 0 deletions templates/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apply plugin: 'application'

version = '0.0.1'
mainClassName = '{{self.name}}.MainPlane'
ext.moduleName = '{{self.name}}'

repositories {
mavenCentral()
}

dependencies {
implementation group: 'org.swimos', name: 'swim-server', version: '{{self.swim_version}}'
}
Loading

0 comments on commit 983c190

Please sign in to comment.