Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new project file name, default.project.json #120

Merged
merged 4 commits into from
Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Rojo Changelog

## [Unreleased]
* Changed default project file name from `roblox-project.json` to `default.project.json` ([#120](https://github.com/LPGhatguy/rojo/pull/120))
* The old file name will still be supported until 0.5.0 is fully released.
* Added warning when loading project files that don't end in `.project.json`
* This new extension enables Rojo to distinguish project files from random JSON files, which is necessary to support nested projects.
* Added new (empty) diagnostic page served from the server
* Added better error messages for when a file is missing that's referenced by a Rojo project
* Added support for visualization endpoints returning GraphViz source when Dot is not available
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions server/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());

let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
project.check_compatibility();

info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
Expand Down
1 change: 1 addition & 0 deletions server/src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());

let project = Arc::new(Project::load_fuzzy(&options.fuzzy_project_path)?);
project.check_compatibility();

info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
Expand Down
1 change: 1 addition & 0 deletions server/src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn upload(options: &UploadOptions) -> Result<(), UploadError> {
info!("Looking for project at {}", options.fuzzy_project_path.display());

let project = Project::load_fuzzy(&options.fuzzy_project_path)?;
project.check_compatibility();

info!("Found project at {}", project.file_location.display());
info!("Using project {:#?}", project);
Expand Down
37 changes: 32 additions & 5 deletions server/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ use std::{
path::{Path, PathBuf},
};

use log::warn;
use failure::Fail;
use maplit::hashmap;
use rbx_tree::RbxValue;
use serde_derive::{Serialize, Deserialize};

pub static PROJECT_FILENAME: &'static str = "roblox-project.json";
pub static PROJECT_FILENAME: &'static str = "default.project.json";
pub static COMPAT_PROJECT_FILENAME: &'static str = "roblox-project.json";

// Methods used for Serde's default value system, which doesn't support using
// value literals directly, only functions that return values.
Expand Down Expand Up @@ -362,11 +364,17 @@ impl Project {
} else if location_metadata.is_dir() {
let with_file = start_location.join(PROJECT_FILENAME);

if let Ok(with_file_metadata) = fs::metadata(&with_file) {
if with_file_metadata.is_file() {
if let Ok(file_metadata) = fs::metadata(&with_file) {
if file_metadata.is_file() {
return Some(with_file);
} else {
return None;
}
}

let with_compat_file = start_location.join(COMPAT_PROJECT_FILENAME);

if let Ok(file_metadata) = fs::metadata(&with_compat_file) {
if file_metadata.is_file() {
return Some(with_compat_file);
}
}
}
Expand Down Expand Up @@ -405,6 +413,25 @@ impl Project {
Ok(())
}

/// Checks if there are any compatibility issues with this project file and
/// warns the user if there are any.
pub fn check_compatibility(&self) {
let file_name = self.file_location
.file_name().unwrap()
.to_str().expect("Project file path was not valid Unicode!");

if file_name == COMPAT_PROJECT_FILENAME {
warn!("Rojo's default project file name changed in 0.5.0-alpha3.");
warn!("Support for the old project file name will be dropped before 0.5.0 releases.");
warn!("Your project file is named {}", COMPAT_PROJECT_FILENAME);
warn!("Rename your project file to {}", PROJECT_FILENAME);
} else if !file_name.ends_with(".project.json") {
warn!("Starting in Rojo 0.5.0-alpha3, it's recommended to give all project files the");
warn!(".project.json extension. This helps Rojo differentiate project file from");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...helps Rojo differentiate project files from"

warn!("other JSON files!");
}
}

fn to_source_project(&self) -> SourceProject {
SourceProject {
name: self.name.clone(),
Expand Down
8 changes: 4 additions & 4 deletions server/tests/read_projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ lazy_static! {

#[test]
fn empty() {
let project_file_location = TEST_PROJECTS_ROOT.join("empty/roblox-project.json");
let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");
let project = Project::load_exact(&project_file_location).unwrap();

assert_eq!(project.name, "empty");
}

#[test]
fn empty_fuzzy_file() {
let project_file_location = TEST_PROJECTS_ROOT.join("empty/roblox-project.json");
let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");
let project = Project::load_fuzzy(&project_file_location).unwrap();

assert_eq!(project.name, "empty");
Expand All @@ -45,7 +45,7 @@ fn empty_fuzzy_folder() {

#[test]
fn single_sync_point() {
let project_file_location = TEST_PROJECTS_ROOT.join("single-sync-point/roblox-project.json");
let project_file_location = TEST_PROJECTS_ROOT.join("single-sync-point/default.project.json");
let project = Project::load_exact(&project_file_location).unwrap();

let expected_project = {
Expand Down Expand Up @@ -100,7 +100,7 @@ fn single_sync_point() {

#[test]
fn test_model() {
let project_file_location = TEST_PROJECTS_ROOT.join("test-model/roblox-project.json");
let project_file_location = TEST_PROJECTS_ROOT.join("test-model/default.project.json");
let project = Project::load_exact(&project_file_location).unwrap();

assert_eq!(project.name, "test-model");
Expand Down