Skip to content

Commit

Permalink
Default smaugignore (#43)
Browse files Browse the repository at this point in the history
* 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
Show file tree
Hide file tree
Showing 18 changed files with 950 additions and 820 deletions.
2 changes: 1 addition & 1 deletion .SRCINFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkgbase = smaug
pkgdesc = A tool to manage your DragonRuby Game Toolkit projects
pkgver = 0.3.0
pkgver = 0.3.1
pkgrel = 1
url = https://smaug.dev/
arch = x86_64
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Add `config` command to show your current Smaug configuration
* Respect `.smaugignore` file when building projects or installing packages
* Add `docs` command to open the configured DragonRuby version's docs in your web browser.

# Version 0.3.0

Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion PKGBUILD
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')
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ smaug = { path = "../smaug" }
clap = "3.0.0-beta.2"
derive_more = "0.99.11"
log = "0.4"
open = "1.7.0"
question = "0.2.2"
reqwest = { version = "0.11", features = ["blocking", "json"] }
rm_rf = "0.6.1"
Expand Down
1 change: 1 addition & 0 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod add;
pub mod bind;
pub mod build;
pub mod config;
pub mod docs;
pub mod dragonruby;
pub mod init;
pub mod install;
Expand Down
16 changes: 12 additions & 4 deletions cli/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum Error {
ConfigError { path: PathBuf },
#[display(fmt = "Could not find file at {}", "path.display()")]
FileNotFound { path: PathBuf },
#[display(fmt = "Building {} failed", "project_name")]
BuildError { project_name: String },
}

impl Command for Build {
Expand Down Expand Up @@ -105,7 +107,7 @@ impl Command for Build {
process::Stdio::inherit()
};

process::Command::new(bin)
let result = process::Command::new(bin)
.current_dir(bin_dir.to_str().unwrap())
.arg("--only-package")
.args(dragonruby_options)
Expand Down Expand Up @@ -138,9 +140,15 @@ impl Command for Build {
.expect("couldn't copy exceptions");
}

Ok(Box::new(BuildResult {
project_name: config.project.unwrap().name,
}))
if result.success() {
Ok(Box::new(BuildResult {
project_name: config.project.unwrap().name,
}))
} else {
Err(Box::new(Error::BuildError {
project_name: config.project.unwrap().name,
}))
}
}
}
}
Expand Down
56 changes: 56 additions & 0 deletions cli/src/commands/docs.rs
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)),
}
}
}
}
}
182 changes: 93 additions & 89 deletions cli/src/commands/init.rs
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 }))
}
}
Loading

0 comments on commit c528d8e

Please sign in to comment.