Tightened project discovery behavior

This commit is contained in:
Lucien Greathouse
2019-11-02 23:36:28 -07:00
parent 7c71708de7
commit 3a538f98ed
3 changed files with 23 additions and 26 deletions

View File

@@ -14,6 +14,9 @@
* Added support for automatically finding Roblox Studio's auth cookie for `rojo upload` on Windows. * Added support for automatically finding Roblox Studio's auth cookie for `rojo upload` on Windows.
* Added support for building, serving and uploading sources that aren't Rojo projects. * Added support for building, serving and uploading sources that aren't Rojo projects.
* Improved feedback from `rojo serve`. * Improved feedback from `rojo serve`.
* Removed support for legacy `roblox-project.json` projects, deprecated in an early Rojo 0.5.0 alpha.
* Rojo no longer traverses directories upwards looking for project files.
* Though undocumented, Rojo 0.5.x will search for a project file contained in any ancestor folders. This feature was removed to better support other 0.6.x features.
### Roblox Studio Plugin ### Roblox Studio Plugin
* Added "connecting" state to improve experience when live syncing. * Added "connecting" state to improve experience when live syncing.

View File

@@ -432,31 +432,33 @@ impl Project {
Ok(project_path) Ok(project_path)
} }
fn locate(start_location: &Path) -> Option<PathBuf> { /// Attempt to locate a project represented by the given path.
// TODO: Check for specific error kinds, convert 'not found' to Result. ///
let location_metadata = fs::metadata(start_location).ok()?; /// This will find a project if the path refers to a `.project.json` file,
/// or is a folder that contains a `default.project.json` file.
fn locate(path: &Path) -> Option<PathBuf> {
let meta = fs::metadata(path).ok()?;
// If this is a file, assume it's the config the user was looking for. if meta.is_file() {
if location_metadata.is_file() { if Project::is_project_file(path) {
if Project::is_project_file(start_location) { Some(path.to_path_buf())
return Some(start_location.to_path_buf());
} else { } else {
return None; None
} }
} else { } else {
let with_file = start_location.join(PROJECT_FILENAME); let child_path = path.join(PROJECT_FILENAME);
let child_meta = fs::metadata(&child_path).ok()?;
if let Ok(file_metadata) = fs::metadata(&with_file) { if child_meta.is_file() {
if file_metadata.is_file() { Some(child_path)
return Some(with_file); } else {
} // This is a folder with the same name as a Rojo default project
// file.
//
// That's pretty weird, but we can roll with it.
None
} }
} }
match start_location.parent() {
Some(parent_location) => Self::locate(parent_location),
None => None,
}
} }
fn load_from_str( fn load_from_str(

View File

@@ -16,14 +16,6 @@ lazy_static! {
{ Path::new(env!("CARGO_MANIFEST_DIR")).join("test-projects") }; { Path::new(env!("CARGO_MANIFEST_DIR")).join("test-projects") };
} }
#[test]
fn empty() {
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] #[test]
fn empty_fuzzy_file() { fn empty_fuzzy_file() {
let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json"); let project_file_location = TEST_PROJECTS_ROOT.join("empty/default.project.json");