-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add default smaugignore file * Fix error reporting on build. Fix new in . * Add docs command. Closes #42 * Fix clippy * Version bump
- Loading branch information
Matt Pruitt
authored
May 29, 2021
1 parent
44190ab
commit c528d8e
Showing
18 changed files
with
950 additions
and
820 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,6 +1,6 @@ | ||
# Maintainer: Logan Koester <[email protected]> | ||
pkgname=smaug | ||
pkgver=0.3.0 | ||
pkgver=0.3.1 | ||
pkgrel=1 | ||
pkgdesc="A tool to manage your DragonRuby Game Toolkit projects" | ||
arch=('x86_64') | ||
|
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 |
---|---|---|
|
@@ -35,21 +35,26 @@ scoop install smaug | |
# Usage | ||
|
||
``` | ||
smaug 0.1.0 | ||
smaug 0.3.1 | ||
Matt Pruitt <[email protected]> | ||
Create games and share packages with the DragonRuby community | ||
USAGE: | ||
smaug [FLAGS] [SUBCOMMAND] | ||
smaug.exe [FLAGS] <SUBCOMMAND> | ||
FLAGS: | ||
-h, --help Prints help information | ||
--json Returns JSON | ||
-q, --quiet Silence all output | ||
-v, --verbose Displays more information | ||
-V, --version Prints version information | ||
SUBCOMMANDS: | ||
add Add a dependency to Smaug.toml | ||
bind Create bindings for c extensions (Pro only) | ||
build Builds your DragonRuby project. | ||
config Displays your current project's Smaug configuration | ||
docs Opens DragonRuby docs in your web browser | ||
dragonruby Manages your local DragonRuby installation. | ||
help Prints this message or the help of the given subcommand(s) | ||
init Initializes an existing project as a Smaug project. | ||
|
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
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,56 @@ | ||
use crate::command::Command; | ||
use crate::command::CommandResult; | ||
use clap::ArgMatches; | ||
use derive_more::Display; | ||
use derive_more::Error; | ||
use log::*; | ||
use serde::Serialize; | ||
use smaug::dragonruby; | ||
use std::env; | ||
use std::path::Path; | ||
|
||
#[derive(Debug, Serialize, Display)] | ||
#[display(fmt = "Opened docs in your web browser.")] | ||
pub struct Docs; | ||
|
||
#[derive(Debug, Display, Error, Serialize)] | ||
pub enum Error { | ||
#[display( | ||
fmt = "Could not find the configured version of DragonRuby. Install it with `smaug dragonruby install`" | ||
)] | ||
ConfiguredDragonRubyNotFound, | ||
#[display(fmt = "Couldn't open your web browser.")] | ||
OpenError, | ||
} | ||
|
||
impl Command for Docs { | ||
fn run(&self, matches: &ArgMatches) -> CommandResult { | ||
trace!("Docs Command"); | ||
|
||
let current_directory = env::current_dir().unwrap(); | ||
let directory: &str = matches | ||
.value_of("path") | ||
.unwrap_or_else(|| current_directory.to_str().unwrap()); | ||
debug!("Directory: {}", directory); | ||
let path = Path::new(directory); | ||
let path = std::fs::canonicalize(&path).expect("Could not find path"); | ||
|
||
let config_path = path.join("Smaug.toml"); | ||
|
||
let dragonruby = match smaug::config::load(&config_path) { | ||
Ok(config) => dragonruby::configured_version(&config), | ||
Err(..) => dragonruby::latest().ok(), | ||
}; | ||
|
||
match dragonruby { | ||
None => Err(Box::new(Error::ConfiguredDragonRubyNotFound)), | ||
Some(dragonruby) => { | ||
let docs = dragonruby.path.join(dragonruby::dragonruby_docs_path()); | ||
match open::that(docs) { | ||
Ok(_) => Ok(Box::new(Docs {})), | ||
Err(_) => Err(Box::new(Error::OpenError)), | ||
} | ||
} | ||
} | ||
} | ||
} |
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,89 +1,93 @@ | ||
use crate::command::Command; | ||
use crate::command::CommandResult; | ||
use clap::ArgMatches; | ||
use derive_more::Display; | ||
use derive_more::Error; | ||
use log::*; | ||
use serde::Serialize; | ||
use std::env; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
use tinytemplate::TinyTemplate; | ||
|
||
#[derive(Serialize)] | ||
struct ProjectConfig { | ||
version: String, | ||
edition: String, | ||
name: String, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Init; | ||
|
||
#[derive(Debug, Serialize, Display)] | ||
#[display(fmt = "Initialized your DragonRuby project")] | ||
pub struct InitResult { | ||
path: PathBuf, | ||
} | ||
|
||
#[derive(Debug, Display, Error, Serialize)] | ||
enum Error { | ||
#[display(fmt = "DragonRuby is not installed. See smaug dragonruby help install for details.")] | ||
DragonRubyNotFound, | ||
} | ||
|
||
static TEMPLATE: &str = include_str!("../../templates/Project.toml.template"); | ||
|
||
impl Command for Init { | ||
fn run(&self, matches: &ArgMatches) -> CommandResult { | ||
trace!("Init Command"); | ||
|
||
let latest = smaug::dragonruby::latest(); | ||
if let Err(..) = latest { | ||
return Err(Box::new(Error::DragonRubyNotFound {})); | ||
} | ||
let latest = latest.unwrap(); | ||
|
||
debug!("Latest DragonRuby: {}", latest); | ||
|
||
let current_directory = env::current_dir().unwrap(); | ||
let directory: &str = matches | ||
.value_of("PATH") | ||
.unwrap_or_else(|| current_directory.to_str().unwrap()); | ||
debug!("Directory: {}", directory); | ||
let path = Path::new(directory); | ||
|
||
let mut tt = TinyTemplate::new(); | ||
tt.add_template("Project.toml", TEMPLATE) | ||
.expect("couldn't add template."); | ||
|
||
let version = latest.version; | ||
let edition = match version.edition { | ||
smaug::dragonruby::Edition::Standard => "standard", | ||
smaug::dragonruby::Edition::Pro => "pro", | ||
}; | ||
|
||
let context = ProjectConfig { | ||
name: path | ||
.file_name() | ||
.expect("directory has no file name.") | ||
.to_string_lossy() | ||
.to_string(), | ||
version: format!("{}.{}", version.version.major, version.version.minor), | ||
edition: edition.to_string(), | ||
}; | ||
|
||
let rendered = tt | ||
.render("Project.toml", &context) | ||
.expect("Could not render Project.toml"); | ||
|
||
let config_path = path.join("Smaug.toml"); | ||
|
||
trace!("Writing configuration to {}", config_path.display()); | ||
std::fs::write(config_path, rendered).expect("Could not write file"); | ||
|
||
Ok(Box::new(InitResult { | ||
path: path.to_path_buf(), | ||
})) | ||
} | ||
} | ||
use crate::command::Command; | ||
use crate::command::CommandResult; | ||
use clap::ArgMatches; | ||
use derive_more::Display; | ||
use derive_more::Error; | ||
use log::*; | ||
use serde::Serialize; | ||
use std::env; | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
use tinytemplate::TinyTemplate; | ||
|
||
#[derive(Serialize)] | ||
struct ProjectConfig { | ||
version: String, | ||
edition: String, | ||
name: String, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct Init; | ||
|
||
#[derive(Debug, Serialize, Display)] | ||
#[display(fmt = "Initialized your DragonRuby project")] | ||
pub struct InitResult { | ||
path: PathBuf, | ||
} | ||
|
||
#[derive(Debug, Display, Error, Serialize)] | ||
enum Error { | ||
#[display(fmt = "DragonRuby is not installed. See smaug dragonruby help install for details.")] | ||
DragonRubyNotFound, | ||
} | ||
|
||
static TEMPLATE: &str = include_str!("../../templates/Project.toml.template"); | ||
|
||
impl Command for Init { | ||
fn run(&self, matches: &ArgMatches) -> CommandResult { | ||
trace!("Init Command"); | ||
|
||
let latest = smaug::dragonruby::latest(); | ||
if let Err(..) = latest { | ||
return Err(Box::new(Error::DragonRubyNotFound {})); | ||
} | ||
let latest = latest.unwrap(); | ||
|
||
debug!("Latest DragonRuby: {}", latest); | ||
|
||
let current_directory = env::current_dir().unwrap(); | ||
let directory: &str = matches | ||
.value_of("PATH") | ||
.unwrap_or_else(|| current_directory.to_str().unwrap()); | ||
debug!("Directory: {}", directory); | ||
let path = Path::new(directory).canonicalize().unwrap(); | ||
|
||
let mut tt = TinyTemplate::new(); | ||
tt.add_template("Project.toml", TEMPLATE) | ||
.expect("couldn't add template."); | ||
|
||
let version = latest.version; | ||
let edition = match version.edition { | ||
smaug::dragonruby::Edition::Standard => "standard", | ||
smaug::dragonruby::Edition::Pro => "pro", | ||
}; | ||
|
||
let context = ProjectConfig { | ||
name: path | ||
.file_name() | ||
.expect("directory has no file name.") | ||
.to_string_lossy() | ||
.to_string(), | ||
version: format!("{}.{}", version.version.major, version.version.minor), | ||
edition: edition.to_string(), | ||
}; | ||
|
||
let rendered = tt | ||
.render("Project.toml", &context) | ||
.expect("Could not render Project.toml"); | ||
|
||
let config_path = path.join("Smaug.toml"); | ||
|
||
trace!("Writing configuration to {}", config_path.display()); | ||
std::fs::write(config_path, rendered).expect("Could not write file"); | ||
|
||
let smaugignore = include_str!("../../templates/smaugignore.template"); | ||
let smaugignore_path = path.join(".smaugignore"); | ||
trace!("Writing .smaugignore to {}", smaugignore_path.display()); | ||
|
||
std::fs::write(smaugignore_path, smaugignore).expect("Couldn't write .smaugignore."); | ||
|
||
Ok(Box::new(InitResult { path })) | ||
} | ||
} |
Oops, something went wrong.