1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use std::collections::BTreeMap;
use std::path::Path;
use anyhow::Context;
use semver::Version;
use serde::{Deserialize, Serialize};
use crate::package_id::PackageId;
use crate::package_name::PackageName;
use crate::package_req::PackageReq;
pub const MANIFEST_FILE_NAME: &str = "wally.toml";
/// The contents of a `wally.toml` file, which defines a package.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Manifest {
pub package: Package,
#[serde(default)]
pub place: PlaceInfo,
#[serde(default)]
pub dependencies: BTreeMap<String, PackageReq>,
#[serde(default)]
pub server_dependencies: BTreeMap<String, PackageReq>,
#[serde(default)]
pub dev_dependencies: BTreeMap<String, PackageReq>,
}
impl Manifest {
/// Load a manifest from a project directory containing a `wally.toml` file.
pub fn load(dir: &Path) -> anyhow::Result<Self> {
let file_path = dir.join(MANIFEST_FILE_NAME);
let content = fs_err::read_to_string(&file_path)?;
let manifest: Manifest = toml::from_str(&content)
.with_context(|| format!("failed to parse manifest at path {}", file_path.display()))?;
Ok(manifest)
}
pub fn from_slice(slice: &[u8]) -> anyhow::Result<Self> {
let manifest: Manifest =
toml::from_slice(slice).with_context(|| format!("failed to parse manifest"))?;
Ok(manifest)
}
pub fn package_id(&self) -> PackageId {
PackageId::new(self.package.name.clone(), self.package.version.clone())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Package {
/// The scope and name of the package.
///
/// Example: `lpghatguy/asink`.
pub name: PackageName,
/// The current version of the package.
///
/// Example: `1.0.0`
pub version: Version,
/// The registry that this package should pull its dependencies from.
///
/// Example: `https://github.com/UpliftGames/wally-test-index`
pub registry: String,
/// The realms (`shared`, `server`, etc) that this package can be used in.
///
/// Packages in the `shared` realm can only depend on other `shared`
/// packages. Packages in the `server` realm can depend on any other
/// package.
///
/// Example: `shared`, `server`
pub realm: Realm,
/// A short description of the package.
///
/// Example: `A game about adopting things.`
pub description: Option<String>,
/// An SPDX license specifier for the package.
///
/// Example: `MIT OR Apache-2.0`
pub license: Option<String>,
/// A list of the package's authors.
///
/// Example: ["Biff Lumfer <biff@playadopt.me>"]
#[serde(default)]
pub authors: Vec<String>,
/// A list of paths to include in the package. Glob patterns are supported.
///
/// By default all directories and files are included except files generated
/// by wally and hidden files/directories. If include is specified then only
/// files matching patterns in the include list will be included.
///
/// If include is unspecified and a .gitignore file exists then those patterns
/// will be respected and wally will also ignore those files.
///
/// Example: ["/src", "*.lua"]
#[serde(default)]
pub include: Vec<String>,
/// A list of paths to exclude from the package. Glob patterns are supported.
///
/// By default files generated by wally and hidden files/directories will be
/// excluded. If a .gitignore file exists and include is unspecified then
/// those patterns will be respected and wally will also ignore those files.
/// Patterns in exclude will be excluded in addition to those patterns in the
/// .gitignore.
///
/// Example: ["/Packages", "/node_modules"]
#[serde(default)]
pub exclude: Vec<String>,
/// Indicates whether the package can be published or not.
///
/// Example: true
#[serde(default)]
pub private: bool,
}
// Metadata we require when this manifest will be used to generate package folders
// This information can be present in any package but is only used in the root package
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct PlaceInfo {
/// Where the shared packages folder is located in the Roblox Datamodel
///
/// Example: `game.ReplicatedStorage.Packages`
#[serde(default)]
pub shared_packages: Option<String>,
/// Where the server packages folder is located in the Roblox Datamodel
///
/// Example: `game.ServerScriptStorage.Packages`
#[serde(default)]
pub server_packages: Option<String>,
}
impl Default for PlaceInfo {
fn default() -> Self {
Self {
shared_packages: None,
server_packages: None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Realm {
Server,
Shared,
Dev,
}
impl Realm {
pub fn is_dependency_valid(dep_type: Self, dep_realm: Self) -> bool {
use Realm::*;
matches!(
(dep_type, dep_realm),
(Server, _) | (Shared, Shared) | (Dev, _)
)
}
}