diff --git a/.gitignore b/.gitignore index 54b52f6..c9fe027 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target /tests +/tmp diff --git a/Makefile b/Makefile index bd90def..819ecdb 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,4 @@ fix: build: cargo build cp target/debug/skeleton bin/skeleton + cp target/debug/skeleton tmp/skeleton diff --git a/bin/skeleton b/bin/skeleton index 0c63dfb..d4babc7 100755 Binary files a/bin/skeleton and b/bin/skeleton differ diff --git a/src/help.rs b/src/help.rs index a2bdba2..267c8b9 100644 --- a/src/help.rs +++ b/src/help.rs @@ -21,12 +21,14 @@ pub fn help_command() { eprintln!(); eprintln!("OPTIONS:"); eprintln!(" rails : Ruby on Rails"); + eprintln!(" react : React+Vite"); eprintln!(" next : Next.js"); eprintln!(" rust : Rust, Axum and SQLx"); eprintln!(" python : Python, FastAPI and SQLAlchemy"); eprintln!(" flutter: Flutter"); eprintln!(); eprintln!("ARGS:"); + eprintln!(" new : create new project."); eprintln!(" init : initialize project."); eprintln!(" help : help."); } diff --git a/src/main.rs b/src/main.rs index 9a97ad1..9dbfd72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ mod help; mod nextjs; mod python; mod rails; +mod react; mod rust; fn main() { @@ -25,6 +26,7 @@ fn main() { let _current_path = env::current_dir().unwrap(); let main_command = args[1].clone(); let sub_command = args[2].clone(); + let options_command = ext_cmd(&args); /* println!("current path is {}", current_path.display()); @@ -34,10 +36,18 @@ fn main() { match main_command.as_str() { "rails" => match sub_command.as_str() { + "new" => rails::new_rails(&options_command), + "api" => rails::api_rails(&options_command), "init" => rails::init_rails(), "help" => rails::help_rails(), _ => not_found(&sub_command), }, + "react" => match sub_command.as_str() { + "new" => react::new_react(), + "init" => react::init_react(), + "help" => react::help_react(), + _ => not_found(&sub_command), + }, "next" => match sub_command.as_str() { "init" => nextjs::init_next(), "help" => nextjs::help_next(), @@ -67,3 +77,10 @@ fn not_found(text: &str) { println!("! {} is not found.", text); println!("! example: skeleton help"); } + +fn ext_cmd(args: &[String]) -> String { + match args.get(3) { + Some(arg) => arg.to_string(), + None => "".to_string(), + } +} diff --git a/src/nextjs.rs b/src/nextjs.rs index 8443748..261fda1 100644 --- a/src/nextjs.rs +++ b/src/nextjs.rs @@ -104,11 +104,7 @@ pub fn init_next() { // add .gitignore println!("+ append .gitignore"); let path = Path::new(".gitignore"); - let mut file = OpenOptions::new() - .write(true) - .append(true) - .open(path) - .unwrap(); + let mut file = OpenOptions::new().append(true).open(path).unwrap(); writeln!(file, ".env").unwrap(); diff --git a/src/rails.rs b/src/rails.rs index cdd2a3b..6ceba2a 100644 --- a/src/rails.rs +++ b/src/rails.rs @@ -1,6 +1,7 @@ use std::fs::OpenOptions; -use std::io::Write; +use std::io::{self, Write}; use std::path::Path; +use std::process::Command; pub fn init_rails() { println!("= init rails"); @@ -11,11 +12,7 @@ pub fn init_rails() { return println!("! Gemfile is not found."); } - let mut file = OpenOptions::new() - .write(true) - .append(true) - .open(path) - .unwrap(); + let mut file = OpenOptions::new().append(true).open(path).unwrap(); writeln!( file, @@ -27,8 +24,51 @@ pub fn init_rails() { println!("= init rails finished."); } +// +// # 新しいRailsアプリの作成(WebApp) +// $ rails new {project-app-name} -d postgresql -T -B -a propshaft -c tailwind +pub fn new_rails(name: &str) { + println!("= rails new {}", name); + + let mut bundle = Command::new("rails"); + bundle + .arg("new") + .arg(name) + .args(["-d", "postgresql"]) + .arg("-T") + .arg("-B") + .args(["-a", "propshaft"]) + .args(["-c", "tailwind"]); + let output = bundle.output().expect("failed to execute rails command"); + + io::stdout().write_all(&output.stdout).unwrap(); + println!("= rails new project created."); +} + +// +// # 新しいRailsアプリの作成(APIモード) +// $ rails new {project-app-name} --api -d postgresql -T -B +pub fn api_rails(name: &str) { + println!("= rails new {} --api", name); + + let mut bundle = Command::new("rails"); + bundle + .arg("new") + .arg(name) + .arg("--api") + .args(["-d", "postgresql"]) + .arg("-T") + .arg("-B"); + let output = bundle.output().expect("failed to execute rails command"); + + io::stdout().write_all(&output.stdout).unwrap(); + println!("= rails api project created."); +} + pub fn help_rails() { println!("? help rails commands"); println!(" rails init"); println!(" rails help"); + println!(" rails new project-name"); + println!(" rails api project-name"); } diff --git a/src/react.rs b/src/react.rs new file mode 100644 index 0000000..0cb0d7a --- /dev/null +++ b/src/react.rs @@ -0,0 +1,12 @@ +pub fn new_react() { + println!("= new react"); +} + +pub fn init_react() { + println!("= init react"); +} + +pub fn help_react() { + println!(" react init"); + println!(" react new"); +}