-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_plugin_template_files.rs
58 lines (48 loc) · 2.2 KB
/
create_plugin_template_files.rs
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 minijinja::{context, Environment};
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut env = Environment::new();
let settings_prefix = format!(
"_plugin__{plugin_name}__{major}_{minor}_{patch}__",
plugin_name = env!("CARGO_PKG_NAME").to_string(),
major = env!("CARGO_PKG_VERSION_MAJOR").to_string(),
minor = env!("CARGO_PKG_VERSION_MINOR").to_string(),
patch = env!("CARGO_PKG_VERSION_PATCH").to_string(),
);
let plugin_json_jinja = fs::read_to_string("templates/plugin.json.jinja")?;
env.add_template("plugin.json", plugin_json_jinja.as_str())?;
let package_json_jinja = fs::read_to_string("templates/package.json.jinja")?;
env.add_template("package.json", package_json_jinja.as_str())?;
let constants_py_jinja = fs::read_to_string("templates/constants.py.jinja")?;
env.add_template("constants.py", constants_py_jinja.as_str())?;
env.get_template("plugin.json")?.render_to_write(
context! {
name => env!("CARGO_PKG_NAME").to_string(),
author => env!("CARGO_PKG_AUTHORS").to_string(),
version => env!("CARGO_PKG_VERSION").to_string(),
description => env!("CARGO_PKG_DESCRIPTION").to_string(),
},
&mut fs::File::create("valve/plugin.json")?,
)?;
env.get_template("package.json")?.render_to_write(
context! {
author => env!("CARGO_PKG_AUTHORS").to_string(),
homepage => env!("CARGO_PKG_HOMEPAGE").to_string(),
repository => env!("CARGO_PKG_REPOSITORY").to_string(),
name => env!("CARGO_PKG_NAME").to_string(),
package_id => env!("CARGO_PKG_NAME").to_string(),
version => env!("CARGO_PKG_VERSION").to_string(),
description => env!("CARGO_PKG_DESCRIPTION").to_string(),
},
&mut fs::File::create("valve/package.json")?,
)?;
env.get_template("constants.py")?.render_to_write(
context! {
name => env!("CARGO_PKG_NAME").to_string(),
version => env!("CARGO_PKG_VERSION").to_string(),
settings_prefix => settings_prefix,
},
&mut fs::File::create("valve/constants.py")?,
)?;
Ok(())
}