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
use serde::{Deserialize, Serialize};
use crate::support::Visitable;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schema", schemars(deny_unknown_fields))]
#[serde(rename_all = "camelCase")]
/// Information of a client-side JavaScript script (ECMA 5.1).
/// All attributes, except Path, are mandatory.
pub struct Script {
/// The name of the script, should correspond to it's scope, two or
/// three levels.
pub name: String,
/// The mode of the script.
pub mode: ScriptMode,
/// The version of the script: <Major/>.<Minor/>.<Build/>.<Release/>
///
/// <Major/> starts at 1 and will be incremented on major changes.
///
/// <Minor/> starts at 0 and will be incremented on minor changes.
///
/// <Build/> starts at 0 and will be incremented on small changes.
///
/// <Release/> starts at 1 for non-final release and 100 for final ones.
///
/// Release numbers bigger than 100 mark bug fixes/patches.
pub version: String,
/// The operation mode. For client-side scripts it must be true.
pub run_time: bool,
/// Optional path to the JavaScript file, fallback: Name + ".js"
pub path: Option<String>,
}
impl Visitable for Script {
fn visit_with(&mut self, visitor: &mut dyn crate::support::Visitor) {
visitor.visit_script(self);
let original_path = self.path.clone().unwrap_or(format!("{}.js", self.name));
let mut provide_path = original_path.clone();
visitor.visit_path(&mut provide_path);
if provide_path != original_path {
self.path = Some(provide_path);
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum ScriptMode {
Interactor,
}