vendor/project/
package.rs1use crate::MESSAGES;
2use colored::Colorize;
3use serde::{Deserialize, Serialize};
4use std::collections::BTreeMap;
5use std::fs;
6
7#[derive(Debug, Deserialize, Serialize)]
8pub struct Info {
9 pub name: String,
10 pub description: String,
11 pub version: String,
12 pub author: String,
13 pub url: String,
14 pub repository: String,
15 pub license: String,
16 pub index: String,
17}
18
19#[derive(Debug, Deserialize, Serialize)]
20pub struct Registry {
21 pub public: bool,
22}
23
24#[derive(Debug, Deserialize, Serialize)]
25pub struct Package {
26 pub info: Info,
27 pub registry: Registry,
28 pub dependencies: BTreeMap<String, String>,
29}
30
31pub fn read() -> Package {
32 let contents = match fs::read_to_string("package.yml") {
33 Ok(content) => content,
34 Err(_) => {
35 eprintln!("{} {}", "✖".red(), MESSAGES.get("read_error").unwrap().bright_red());
36 std::process::exit(1);
37 }
38 };
39
40 let yaml_file: Result<Package, _> = serde_yaml::from_str(&contents);
41 let parsed = match yaml_file {
42 Ok(project) => project,
43 Err(error) => {
44 eprintln!("{}", format!("{}{}", MESSAGES.get("yaml_error").unwrap(), error).red());
45 std::process::exit(1);
46 }
47 };
48
49 return parsed;
50}