-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from creepersaur/init-files-dir
Init files dir
- Loading branch information
Showing
7 changed files
with
221 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use colored::Colorize; | ||
|
||
use super::filesystem as fs; | ||
|
||
pub fn initialize(args: Vec<String>) { | ||
let mut root = "game"; | ||
if args.len() > 2 { | ||
if args[2] == "src" { | ||
root = "src"; | ||
} | ||
} | ||
|
||
fs::create_file( | ||
&"creeper.toml", | ||
&format!(r#" | ||
# Your root/src directory. | ||
root = "{root}" | ||
# The port to host the sever at. | ||
port = 8080 | ||
# Enable two_way_sync on the following (array) | ||
two_way_sync = [ | ||
"ServerStorage", | ||
"ServerScriptService" | ||
] | ||
# Should include descendants when syncing back? | ||
two_way_descendants = true | ||
"#,) | ||
); | ||
|
||
fs::build_dir(format!("{root}/ServerScriptService/server")); | ||
fs::build_dir(format!("{root}/StarterPlayerScripts/client")); | ||
fs::build_dir(format!("{root}/ReplicatedStorage/shared")); | ||
|
||
fs::create_file( | ||
&format!("{root}/ServerScriptService/server/hello.server.luau"), | ||
&r#"print("Hello from CreeperCLI! (server)")"# | ||
); | ||
|
||
fs::create_file( | ||
&"sourcemap.json", | ||
&r#"["Will be replaced when the plugin connects."]"# | ||
); | ||
|
||
fs::create_file( | ||
&"default.project.json", | ||
&r#"["Will be replaced when the plugin connects."]"# | ||
); | ||
|
||
println!("{} 👍", "Successfully initialized CreeperCLI project!".green()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,33 @@ | ||
use colored::Colorize; | ||
use lazy_static::lazy_static; | ||
use std::{env, io::stdin, path::Path, sync::Mutex}; | ||
use filesystem::get_cwd; | ||
use server::run_server; | ||
use std::mem::drop; | ||
use colored::Colorize; | ||
use std::{env, path::PathBuf, sync::Mutex}; | ||
|
||
mod sourcemap; | ||
mod filesystem; | ||
mod get; | ||
mod post; | ||
mod server; | ||
mod settings; | ||
mod update; | ||
mod run_server; | ||
mod init; | ||
|
||
lazy_static! { | ||
// pub static ref DIRECTORIES: Mutex<Table> = Mutex::new(Table::new()); | ||
pub static ref ROOT: Mutex<String> = Mutex::new("game".to_string()); | ||
pub static ref CWD: PathBuf = filesystem::get_cwd(); | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
let cwd = get_cwd(); | ||
|
||
let args: Vec<String> = env::args().collect(); | ||
if args.len() > 1 && args[1] == "update" { | ||
update::update_cli().expect("Failed to update CreeperCLI."); | ||
return Ok(()) | ||
} | ||
|
||
let mut port: u16 = 8080; | ||
|
||
if let Ok(settings) = settings::get_settings(&cwd) { | ||
for (name, value) in settings.iter() { | ||
match name.to_lowercase().as_str() { | ||
"port" => port = value.as_integer().unwrap_or(8080) as u16, | ||
"root" => { | ||
let mut data = match ROOT.lock() { | ||
Ok(guard) => guard, | ||
Err(poisoned) => poisoned.into_inner(), // Recover from poisoned mutex | ||
}; | ||
*data = value.as_str().unwrap_or("game").to_string(); | ||
drop(data); | ||
}, | ||
_ => {} | ||
} | ||
if args.len() > 1 { | ||
match args[1].as_str() { | ||
"update" => update::update_cli().expect("Failed to update CreeperCLI."), | ||
"init" => init::initialize(args), | ||
_ => println!("{} Could not find command `{}`.", "[NO_COMMAND]".red(), args[1]) | ||
} | ||
} else { | ||
run_server::start().await | ||
} | ||
|
||
let root = match ROOT.lock() { | ||
Ok(guard) => guard, | ||
Err(poisoned) => poisoned.into_inner() | ||
}; | ||
let game_dir = format!("{}//{}", &cwd, *root); | ||
|
||
let path = Path::new(game_dir.as_str()); | ||
if !(path.exists() && path.is_dir()) { | ||
println!( | ||
"{} {} {}", | ||
"YOU MUST HAVE A".red(), | ||
format!("`{}`",root).purple(), | ||
"DIRECTORY IN THE WORKING DIRECTORY.".red() | ||
); | ||
stdin() | ||
.read_line(&mut String::new()) | ||
.expect("Failed to read_line."); | ||
return Ok(()); | ||
} | ||
|
||
drop(root); | ||
|
||
println!( | ||
"{} {}", | ||
"Running server at:".bold().green(), | ||
format!("http://localhost:{}", port).purple() | ||
); | ||
Ok(run_server(port).await.expect("Failed to run server!")) | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.