Skip to content

Commit

Permalink
Merge pull request #8 from w-henderson/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes in development server
  • Loading branch information
w-henderson authored Apr 19, 2023
2 parents a9545c6 + b2077aa commit 7cc02ec
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 28 deletions.
4 changes: 2 additions & 2 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 stuart-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stuart_core"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
homepage = "https://github.com/w-henderson/Stuart"
Expand Down
4 changes: 2 additions & 2 deletions stuart-core/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Node {
plugins: Option<&dyn Manager>,
) -> Result<Self, Error> {
let dir = dir.as_ref();
let content = read_dir(&dir)
let content = read_dir(dir)
.map_err(|_| Error::Fs(FsError::NotFound(dir.to_string_lossy().to_string())))?;

let children = content
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Node {
) -> Result<Self, Error> {
let file = file.as_ref();
let name = file.file_name().unwrap().to_string_lossy().to_string();
let contents = read(&file).map_err(|_| Error::Fs(FsError::Read))?;
let contents = read(file).map_err(|_| Error::Fs(FsError::Read))?;

let parsed_contents = if parse {
let extension = file.extension().map(|e| e.to_string_lossy().to_string());
Expand Down
13 changes: 4 additions & 9 deletions stuart-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,11 @@ impl Stuart {
}

/// Attempts to build the project.
///
/// If the input directory has not yet been loaded into memory, this will happen now.
pub fn build(&mut self, stuart_env: String) -> Result<(), Error> {
if self.input.is_none() {
self.input = Some(match self.plugins {
Some(ref plugins) => Node::new_with_plugins(&self.dir, true, plugins.as_ref())?,
None => Node::new(&self.dir, true)?,
});
}
self.input = Some(match self.plugins {
Some(ref plugins) => Node::new_with_plugins(&self.dir, true, plugins.as_ref())?,
None => Node::new(&self.dir, true)?,
});

let vars = {
let mut env = std::env::vars().collect::<Vec<_>>();
Expand All @@ -151,7 +147,6 @@ impl Stuart {

self.base = Some(base);
self.output = Some(self.build_node(self.input.as_ref().unwrap(), env)?);
self.input = None;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion stuart-core/src/parse/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn parse_markdown(

let markdown = input
.lines()
.skip(lines_to_skip as usize)
.skip(lines_to_skip)
.collect::<Vec<_>>()
.join("\n");

Expand Down
6 changes: 2 additions & 4 deletions stuart-core/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ impl Testcase {
assert_eq!(
std::str::from_utf8(contents)
.unwrap()
.replace('\n', "")
.replace('\r', ""),
.replace(['\n', '\r'], ""),
std::str::from_utf8(expected_contents)
.unwrap()
.replace('\n', "")
.replace('\r', "")
.replace(['\n', '\r'], "")
);
}
_ => panic!("Not both files"),
Expand Down
4 changes: 2 additions & 2 deletions stuart/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stuart"
version = "0.2.3"
version = "0.2.4"
edition = "2021"
license = "MIT"
homepage = "https://github.com/w-henderson/Stuart"
Expand All @@ -15,7 +15,7 @@ name = "stuart"
path = "src/main.rs"

[dependencies]
stuart_core = { version = "^0.2.3", path = "../stuart-core" }
stuart_core = { version = "^0.2.4", path = "../stuart-core" }

clap = "^3.2"
toml = "^0.5"
Expand Down
2 changes: 1 addition & 1 deletion stuart/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl StuartContext {
log!("Exporting", "metadata to `metadata.json`");

let metadata_path = self.project_dir.join("metadata.json");
self.stuart.save_metadata(&metadata_path)?;
self.stuart.save_metadata(metadata_path)?;
}

let post_build_start = Instant::now();
Expand Down
10 changes: 5 additions & 5 deletions stuart/src/config/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::process::Command;
/// Gets the user's name from Git.
pub fn get_user_name() -> Option<String> {
let output = Command::new("git")
.args(&["config", "--get", "user.name"])
.args(["config", "--get", "user.name"])
.output()
.ok()?;

Expand All @@ -21,7 +21,7 @@ pub fn get_user_name() -> Option<String> {
/// Gets the user's email from Git.
pub fn get_user_email() -> Option<String> {
let output = Command::new("git")
.args(&["config", "--get", "user.email"])
.args(["config", "--get", "user.email"])
.output()
.ok()?;

Expand All @@ -46,7 +46,7 @@ pub fn init_repository(path: &str) -> bool {
/// Checks whether a remote repository exists at the given URL.
pub fn exists(url: &str) -> bool {
Command::new("git")
.args(&["ls-remote", url])
.args(["ls-remote", url])
.output()
.map(|output| output.status.success())
.unwrap_or(false)
Expand All @@ -57,7 +57,7 @@ pub fn exists(url: &str) -> bool {
/// Returns `true` if the clone was successful, `false` otherwise.
pub fn clone(url: &str, path: &str) -> bool {
Command::new("git")
.args(&["clone", url, path, "--depth", "1"])
.args(["clone", url, path, "--depth", "1"])
.output()
.map(|output| output.status.success())
.unwrap_or(false)
Expand All @@ -68,7 +68,7 @@ pub fn clone(url: &str, path: &str) -> bool {
/// Returns `true` if the pull was successful, `false` otherwise.
pub fn pull(path: &str) -> bool {
Command::new("git")
.args(&["-C", path, "pull"])
.args(["-C", path, "pull"])
.output()
.map(|output| output.status.success())
.unwrap_or(false)
Expand Down
2 changes: 1 addition & 1 deletion stuart/src/plugins/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn build_cargo_project(root: impl AsRef<Path>) -> Result<PathBuf, ScriptErro
let manifest = root.as_ref().join("Cargo.toml");

let output = Command::new("cargo")
.args(&["build", "--release", "--manifest-path"])
.args(["build", "--release", "--manifest-path"])
.arg(&manifest)
.output()
.map_err(|_| ScriptError::CouldNotExecute("<build script>".to_string()))?;
Expand Down

0 comments on commit 7cc02ec

Please sign in to comment.