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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
//! installer config
pub mod homebrew;
pub mod msi;
pub mod npm;
pub mod pkg;
pub mod powershell;
pub mod shell;
use super::*;
use homebrew::*;
use msi::*;
use npm::*;
use pkg::*;
use powershell::*;
use shell::*;
/// workspace installer config (final)
#[derive(Debug, Default, Clone)]
pub struct WorkspaceInstallerConfig {
/// Whether to install an updater program alongside the software
pub updater: bool,
/// Whether to always use the latest version instead of a known-good version
pub always_use_latest_updater: bool,
}
/// package installer config (final)
#[derive(Debug, Default, Clone)]
pub struct AppInstallerConfig {
/// homebrew installer
pub homebrew: Option<HomebrewInstallerConfig>,
/// msi installer
pub msi: Option<MsiInstallerConfig>,
/// npm installer
pub npm: Option<NpmInstallerConfig>,
/// powershell installer
pub powershell: Option<PowershellInstallerConfig>,
/// shell installer
pub shell: Option<ShellInstallerConfig>,
/// shell installer
pub pkg: Option<PkgInstallerConfig>,
}
/// installer config (inheritance not yet applied)
#[derive(Debug, Clone)]
pub struct InstallerConfigInheritable {
/// inheritable fields
pub common: CommonInstallerConfig,
/// homebrew installer
pub homebrew: Option<HomebrewInstallerLayer>,
/// msi installer
pub msi: Option<MsiInstallerLayer>,
/// npm installer
pub npm: Option<NpmInstallerLayer>,
/// powershell installer
pub powershell: Option<PowershellInstallerLayer>,
/// shell installer
pub shell: Option<ShellInstallerLayer>,
/// pkg installer
pub pkg: Option<PkgInstallerLayer>,
/// Whether to install an updater program alongside the software
pub updater: bool,
/// Whether to always use the latest version instead of a fixed version
pub always_use_latest_updater: bool,
}
/// installer config (raw from file)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct InstallerLayer {
/// inheritable fields
#[serde(flatten)]
pub common: CommonInstallerLayer,
/// homebrew installer
pub homebrew: Option<BoolOr<HomebrewInstallerLayer>>,
/// msi installer
pub msi: Option<BoolOr<MsiInstallerLayer>>,
/// npm installer
pub npm: Option<BoolOr<NpmInstallerLayer>>,
/// powershell installer
pub powershell: Option<BoolOr<PowershellInstallerLayer>>,
/// shell installer
pub shell: Option<BoolOr<ShellInstallerLayer>>,
/// pkg installer
pub pkg: Option<BoolOr<PkgInstallerLayer>>,
/// Whether to install an updater program alongside the software
#[serde(skip_serializing_if = "Option::is_none")]
pub updater: Option<bool>,
/// Whether to always use the latest updater version instead of a fixed version
#[serde(skip_serializing_if = "Option::is_none")]
pub always_use_latest_updater: Option<bool>,
}
impl InstallerConfigInheritable {
/// defaults for a workspace
pub fn defaults_for_workspace(_workspaces: &WorkspaceGraph) -> Self {
Self::defaults()
}
/// defaults for a package
pub fn defaults_for_package(_workspaces: &WorkspaceGraph, _pkg_idx: PackageIdx) -> Self {
Self::defaults()
}
/// defaults
pub fn defaults() -> Self {
Self {
common: CommonInstallerConfig::defaults(),
homebrew: None,
msi: None,
npm: None,
powershell: None,
shell: None,
pkg: None,
updater: false,
always_use_latest_updater: false,
}
}
/// apply inheritance to and get final workspace config
pub fn apply_inheritance_for_workspace(
self,
_workspaces: &WorkspaceGraph,
) -> WorkspaceInstallerConfig {
let Self {
// global
updater,
always_use_latest_updater,
// local-only
common: _,
homebrew: _,
msi: _,
npm: _,
powershell: _,
shell: _,
pkg: _,
} = self;
WorkspaceInstallerConfig {
updater,
always_use_latest_updater,
}
}
/// apply inheritance to get final package config
pub fn apply_inheritance_for_package(
self,
workspaces: &WorkspaceGraph,
pkg_idx: PackageIdx,
) -> AppInstallerConfig {
let Self {
common,
homebrew,
msi,
npm,
powershell,
shell,
pkg,
// global-only
updater: _,
always_use_latest_updater: _,
} = self;
let homebrew = homebrew.map(|homebrew| {
let mut default =
HomebrewInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(homebrew);
default
});
let msi = msi.map(|msi| {
let mut default =
MsiInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(msi);
default
});
let npm = npm.map(|npm| {
let mut default =
NpmInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(npm);
default
});
let powershell = powershell.map(|powershell| {
let mut default =
PowershellInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(powershell);
default
});
let shell = shell.map(|shell| {
let mut default =
ShellInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(shell);
default
});
let pkg = pkg.map(|pkg| {
let mut default =
PkgInstallerConfig::defaults_for_package(workspaces, pkg_idx, &common);
default.apply_layer(pkg);
default
});
AppInstallerConfig {
homebrew,
msi,
npm,
powershell,
shell,
pkg,
}
}
}
impl ApplyLayer for InstallerConfigInheritable {
type Layer = InstallerLayer;
fn apply_layer(
&mut self,
Self::Layer {
common,
homebrew,
msi,
npm,
powershell,
shell,
pkg,
updater,
always_use_latest_updater,
}: Self::Layer,
) {
self.common.apply_layer(common);
self.homebrew.apply_bool_layer(homebrew);
self.msi.apply_bool_layer(msi);
self.npm.apply_bool_layer(npm);
self.powershell.apply_bool_layer(powershell);
self.shell.apply_bool_layer(shell);
self.pkg.apply_bool_layer(pkg);
self.updater.apply_val(updater);
self.always_use_latest_updater
.apply_val(always_use_latest_updater);
}
}
/// inheritable installer fields (raw from file)
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct CommonInstallerLayer {
/// The strategy to use for selecting a path to install things at:
///
/// * `CARGO_HOME`: (default) install as if cargo did
/// (try `$CARGO_HOME/bin/`, but if `$CARGO_HOME` isn't set use `$HOME/.cargo/bin/`)
/// * `~/some/subdir/`: install to the given subdir of the user's `$HOME`
/// * `$SOME_VAR/some/subdir`: install to the given subdir of the dir defined by `$SOME_VAR`
///
/// All of these error out if the required env-vars aren't set. In the future this may
/// allow for the input to be an array of options to try in sequence.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, with = "opt_string_or_vec")]
pub install_path: Option<Vec<InstallPathStrategy>>,
/// Custom success message for installers
///
/// When an shell or powershell installer succeeds at installing your app it
/// will out put a message to the user. This config allows a user to specify
/// a custom message as opposed to the default.
#[serde(skip_serializing_if = "Option::is_none")]
pub install_success_msg: Option<String>,
/// Whether installers should install libraries from the release archive
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default, with = "opt_string_or_vec")]
pub install_libraries: Option<Vec<LibraryStyle>>,
/// Aliases to install binaries as
#[serde(skip_serializing_if = "Option::is_none")]
pub bin_aliases: Option<SortedMap<String, Vec<String>>>,
}
/// inheritable installer fields (final)
#[derive(Debug, Default, Clone)]
pub struct CommonInstallerConfig {
/// The strategy to use for selecting a path to install things at:
///
/// * `CARGO_HOME`: (default) install as if cargo did
/// (try `$CARGO_HOME/bin/`, but if `$CARGO_HOME` isn't set use `$HOME/.cargo/bin/`)
/// * `~/some/subdir/`: install to the given subdir of the user's `$HOME`
/// * `$SOME_VAR/some/subdir`: install to the given subdir of the dir defined by `$SOME_VAR`
///
/// All of these error out if the required env-vars aren't set. In the future this may
/// allow for the input to be an array of options to try in sequence.
pub install_path: Vec<InstallPathStrategy>,
/// Custom success message for installers
///
/// When an shell or powershell installer succeeds at installing your app it
/// will out put a message to the user. This config allows a user to specify
/// a custom message as opposed to the default.
pub install_success_msg: String,
/// Whether installers should install libraries from the release archive
pub install_libraries: Vec<LibraryStyle>,
/// Aliases to install binaries as
pub bin_aliases: SortedMap<String, Vec<String>>,
/// Whether to install an updater program alongside the software
pub install_updater: bool,
}
impl CommonInstallerConfig {
/// defaults
pub fn defaults() -> Self {
Self {
install_path: InstallPathStrategy::default_list(),
install_success_msg: "everything's installed!".to_owned(),
install_libraries: Default::default(),
bin_aliases: Default::default(),
install_updater: false,
}
}
}
impl ApplyLayer for CommonInstallerConfig {
type Layer = CommonInstallerLayer;
fn apply_layer(
&mut self,
Self::Layer {
install_path,
install_success_msg,
install_libraries,
bin_aliases,
}: Self::Layer,
) {
self.install_path.apply_val(install_path);
self.install_success_msg.apply_val(install_success_msg);
self.install_libraries.apply_val(install_libraries);
self.bin_aliases.apply_val(bin_aliases);
}
}
impl ApplyLayer for CommonInstallerLayer {
type Layer = CommonInstallerLayer;
fn apply_layer(
&mut self,
Self::Layer {
install_path,
install_success_msg,
install_libraries,
bin_aliases,
}: Self::Layer,
) {
self.install_path.apply_opt(install_path);
self.install_success_msg.apply_opt(install_success_msg);
self.install_libraries.apply_opt(install_libraries);
self.bin_aliases.apply_opt(bin_aliases);
}
}