electron-cli 0.3.0-alpha.10 → 0.3.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/project.rs CHANGED
@@ -15,6 +15,7 @@ pub struct ProjectSnapshot {
15
15
  pub package_json: Option<Utf8PathBuf>,
16
16
  pub name: Option<String>,
17
17
  pub version: Option<String>,
18
+ pub repository: Option<String>,
18
19
  pub license: Option<String>,
19
20
  pub main: Option<String>,
20
21
  pub package_manager: Option<String>,
@@ -129,6 +130,7 @@ pub fn inspect(cwd: &Path) -> Result<ProjectSnapshot> {
129
130
  .and_then(|package| package.get("version"))
130
131
  .and_then(Value::as_str)
131
132
  .map(ToOwned::to_owned),
133
+ repository: package_json.as_ref().and_then(repository_value),
132
134
  license: package_json
133
135
  .as_ref()
134
136
  .and_then(|package| package.get("license"))
@@ -151,6 +153,17 @@ pub fn inspect(cwd: &Path) -> Result<ProjectSnapshot> {
151
153
  })
152
154
  }
153
155
 
156
+ fn repository_value(package: &Value) -> Option<String> {
157
+ match package.get("repository") {
158
+ Some(Value::String(repository)) => Some(repository.clone()),
159
+ Some(Value::Object(repository)) => repository
160
+ .get("url")
161
+ .and_then(Value::as_str)
162
+ .map(ToOwned::to_owned),
163
+ _ => None,
164
+ }
165
+ }
166
+
154
167
  fn string_map(value: Option<&Value>) -> BTreeMap<String, String> {
155
168
  value
156
169
  .and_then(Value::as_object)
@@ -267,6 +280,25 @@ mod tests {
267
280
  assert!(!map.contains_key("bad"));
268
281
  }
269
282
 
283
+ #[test]
284
+ fn inspects_repository_url() {
285
+ let root = unique_temp_dir("repository");
286
+ fs::write(
287
+ root.join("package.json"),
288
+ r#"{"name":"repo-app","repository":{"type":"git","url":"git+https://github.com/Ikana/electron-cli.git"}}"#,
289
+ )
290
+ .expect("package.json should be written");
291
+
292
+ let snapshot = inspect(&root).expect("project should inspect");
293
+
294
+ assert_eq!(
295
+ snapshot.repository.as_deref(),
296
+ Some("git+https://github.com/Ikana/electron-cli.git")
297
+ );
298
+
299
+ let _ = fs::remove_dir_all(root);
300
+ }
301
+
270
302
  #[test]
271
303
  fn builds_electron_signals() {
272
304
  let mut scripts = BTreeMap::new();
@@ -323,4 +355,17 @@ mod tests {
323
355
  .signals
324
356
  .contains(&"electron command found in package scripts".to_string()));
325
357
  }
358
+
359
+ fn unique_temp_dir(label: &str) -> PathBuf {
360
+ let nanos = std::time::SystemTime::now()
361
+ .duration_since(std::time::UNIX_EPOCH)
362
+ .expect("clock should be after epoch")
363
+ .as_nanos();
364
+ let path = std::env::temp_dir().join(format!(
365
+ "electron-cli-project-{label}-{}-{nanos}",
366
+ std::process::id()
367
+ ));
368
+ fs::create_dir_all(&path).expect("temp dir should be created");
369
+ path
370
+ }
326
371
  }