Add fmt-project subcommand

This commit is contained in:
Lucien Greathouse
2021-05-20 15:41:08 -04:00
parent 5a0a8f5077
commit df1aced95d
4 changed files with 35 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
* Added the `gameId` and `placeId` optional properties to project files.
* When connecting from the Rojo Roblox Studio plugin, Rojo will set the game and place ID of the current place to these values, if set.
* This is equivalent to running `game:SetUniverseId(...)` and `game:SetPlaceId(...)` from the command bar in Studio.
* Added the `fmt-project` subcommand for formatting Rojo project files.
* Added "EXPERIMENTAL!" label to two-way sync toggle in Rojo's Roblox Studio plugin.
* Fixed `Name` and `Parent` properties being allowed in Rojo projects. ([#413][pr-413])
* Fixed "Open Scripts Externally" feature crashing Studio. ([#369][issue-369])

View File

@@ -11,6 +11,7 @@ fn run(global: GlobalOptions, subcommand: Subcommand) -> anyhow::Result<()> {
Subcommand::Serve(serve_options) => cli::serve(global, serve_options)?,
Subcommand::Build(build_options) => cli::build(build_options)?,
Subcommand::Upload(upload_options) => cli::upload(upload_options)?,
Subcommand::FmtProject(fmt_options) => fmt_options.run()?,
Subcommand::Doc => cli::doc()?,
Subcommand::Plugin(plugin_options) => cli::plugin(plugin_options)?,
}

29
src/cli/fmt_project.rs Normal file
View File

@@ -0,0 +1,29 @@
use std::path::PathBuf;
use anyhow::Context;
use structopt::StructOpt;
use crate::project::Project;
/// Reformat a Rojo project using the standard JSON formatting rules.
#[derive(Debug, StructOpt)]
pub struct FmtProjectCommand {
/// Path to the project to format. Defaults to the current directory.
#[structopt(default_value = "")]
pub project: PathBuf,
}
impl FmtProjectCommand {
pub fn run(self) -> anyhow::Result<()> {
let project = Project::load_fuzzy(&self.project)?
.context("A project file is required to run 'rojo fmt-project'")?;
let serialized = serde_json::to_string_pretty(&project)
.context("could not re-encode project file as JSON")?;
fs_err::write(&project.file_location, &serialized)
.context("could not write back to project file")?;
Ok(())
}
}

View File

@@ -2,6 +2,7 @@
mod build;
mod doc;
mod fmt_project;
mod init;
mod plugin;
mod serve;
@@ -22,6 +23,7 @@ use thiserror::Error;
pub use self::build::*;
pub use self::doc::*;
pub use self::fmt_project::FmtProjectCommand;
pub use self::init::*;
pub use self::plugin::*;
pub use self::serve::*;
@@ -112,6 +114,8 @@ pub enum Subcommand {
/// Generates a place or model file out of the project and uploads it to Roblox.
Upload(UploadCommand),
FmtProject(FmtProjectCommand),
/// Open Rojo's documentation in your browser.
Doc,