Skip to content

Commit e2a222a

Browse files
authored
new: Support JSON/YAML schema plugins. (#636)
1 parent a91d064 commit e2a222a

File tree

15 files changed

+255
-38
lines changed

15 files changed

+255
-38
lines changed

.prototools

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[plugins]
2+
# moon-test = "file://./crates/cli/tests/fixtures/moon-schema.yaml"
23
moon-test = "https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
34
wasm-test = "file://./plugins/target/wasm32-wasi/debug/proto_wasm_test.wasm"
45

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
- [Node](https://github.com/moonrepo/tools/blob/master/tools/node/CHANGELOG.md)
99
- [Python](https://github.com/moonrepo/tools/blob/master/tools/python/CHANGELOG.md)
1010
- [Rust](https://github.com/moonrepo/tools/blob/master/tools/rust/CHANGELOG.md)
11-
- [TOML schema](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md)
11+
- [Schema (TOML, JSON, YAML)](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md)
12+
13+
## Unreleased
14+
15+
#### 🚀 Updates
16+
17+
- Added support for JSON and YAML based configurations for non-WASM schema based plugins. This is an alternative to TOML, but supports all the same settings.
1218

1319
## 0.41.5
1420

@@ -28,7 +34,7 @@
2834

2935
#### 🧩 Plugins
3036

31-
- Updated `internal_schema_plugin` (TOML) to v0.15.1.
37+
- Updated `schema_tool` (TOML) to v0.15.1.
3238
- Added `{versionMajor}`, `{versionMajorMinor}`, `{versionYear}`, `{versionYearMonth}`, `{versionPrerelease}`, and `{versionBuild}` tokens.
3339

3440
#### ⚙️ Internal

Cargo.lock

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/src/commands/plugin/search.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ pub async fn search(session: ProtoSession, args: SearchPluginArgs) -> AppResult
7171
PluginAuthor::Object(author) => &author.name,
7272
}),
7373
Cell::new(match plugin.format {
74+
PluginFormat::Json => "JSON",
7475
PluginFormat::Toml => "TOML",
7576
PluginFormat::Wasm => "WASM",
77+
PluginFormat::Yaml => "YAML",
7678
}),
7779
Cell::new(&plugin.description),
7880
Cell::new(plugin.locator.to_string())
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"bin": "moon-test",
3+
"name": "moon-test",
4+
"type": "cli",
5+
"platform": {
6+
"linux": {
7+
"downloadFile": "moon-{arch}-unknown-linux-{libc}"
8+
},
9+
"macos": {
10+
"downloadFile": "moon-{arch}-apple-darwin"
11+
},
12+
"windows": {
13+
"downloadFile": "moon-{arch}-pc-windows-msvc.exe"
14+
}
15+
},
16+
"install": {
17+
"downloadUrl": "https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}",
18+
"unpack": false
19+
},
20+
"resolve": {
21+
"gitUrl": "https://github.com/moonrepo/moon"
22+
}
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
bin: "moon-test"
2+
name: "moon-test"
3+
type: "cli"
4+
5+
platform:
6+
linux:
7+
downloadFile: "moon-{arch}-unknown-linux-{libc}"
8+
macos:
9+
downloadFile: "moon-{arch}-apple-darwin"
10+
windows:
11+
downloadFile: "moon-{arch}-pc-windows-msvc.exe"
12+
13+
install:
14+
downloadUrl: "https://github.com/moonrepo/moon/releases/download/v{version}/{download_file}"
15+
unpack: false
16+
17+
resolve:
18+
gitUrl: "https://github.com/moonrepo/moon"

crates/cli/tests/plugins_test.rs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod plugins {
5757
use super::*;
5858

5959
#[tokio::test(flavor = "multi_thread")]
60-
async fn downloads_and_installs_plugin_from_file() {
60+
async fn downloads_and_installs_toml_plugin_from_file() {
6161
run_tests(|env| {
6262
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
6363

@@ -73,6 +73,40 @@ mod plugins {
7373
.await;
7474
}
7575

76+
#[tokio::test(flavor = "multi_thread")]
77+
async fn downloads_and_installs_json_plugin_from_file() {
78+
run_tests(|env| {
79+
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
80+
81+
load_tool_from_locator(
82+
Id::raw("moon"),
83+
env.to_owned(),
84+
PluginLocator::File(Box::new(FileLocator {
85+
file: "./tests/fixtures/moon-schema.json".into(),
86+
path: Some(root_dir.join("./tests/fixtures/moon-schema.json")),
87+
})),
88+
)
89+
})
90+
.await;
91+
}
92+
93+
#[tokio::test(flavor = "multi_thread")]
94+
async fn downloads_and_installs_yaml_plugin_from_file() {
95+
run_tests(|env| {
96+
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
97+
98+
load_tool_from_locator(
99+
Id::raw("moon"),
100+
env.to_owned(),
101+
PluginLocator::File(Box::new(FileLocator {
102+
file: "./tests/fixtures/moon-schema.yaml".into(),
103+
path: Some(root_dir.join("./tests/fixtures/moon-schema.yaml")),
104+
})),
105+
)
106+
})
107+
.await;
108+
}
109+
76110
#[tokio::test]
77111
#[should_panic(expected = "does not exist")]
78112
async fn errors_for_missing_file() {
@@ -333,7 +367,33 @@ mod plugins {
333367

334368
#[test]
335369
fn supports_toml_schema() {
336-
let sandbox = create_empty_proto_sandbox_with_tools();
370+
let sandbox = create_empty_proto_sandbox_with_tools("toml");
371+
372+
sandbox
373+
.run_bin(|cmd| {
374+
cmd.arg("install").arg("moon-test");
375+
})
376+
.success();
377+
378+
// Doesn't create shims
379+
}
380+
381+
#[test]
382+
fn supports_json_schema() {
383+
let sandbox = create_empty_proto_sandbox_with_tools("json");
384+
385+
sandbox
386+
.run_bin(|cmd| {
387+
cmd.arg("install").arg("moon-test");
388+
})
389+
.success();
390+
391+
// Doesn't create shims
392+
}
393+
394+
#[test]
395+
fn supports_yaml_schema() {
396+
let sandbox = create_empty_proto_sandbox_with_tools("yaml");
337397

338398
sandbox
339399
.run_bin(|cmd| {

crates/cli/tests/utils.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,23 @@ pub fn create_empty_proto_sandbox() -> ProtoSandbox {
5959
ProtoSandbox::new(starbase_sandbox::create_empty_sandbox())
6060
}
6161

62-
pub fn create_empty_proto_sandbox_with_tools() -> ProtoSandbox {
62+
pub fn create_empty_proto_sandbox_with_tools(ext: &str) -> ProtoSandbox {
6363
let sandbox = create_empty_proto_sandbox();
64+
let schema_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
65+
.join("./tests/fixtures")
66+
.join(format!("moon-schema.{ext}"));
6467

6568
sandbox.create_file(
6669
".prototools",
67-
r#"
70+
format!(
71+
r#"
6872
moon-test = "1.0.0"
6973
7074
[plugins]
71-
moon-test = "https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
75+
moon-test = "file://{}"
7276
"#,
77+
schema_path.to_string_lossy().replace("\\", "/")
78+
),
7379
);
7480

7581
sandbox

crates/core/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ warpgate = { version = "0.18.0", path = "../warpgate", features = [
1919
"schematic",
2020
] }
2121
clap = { workspace = true, optional = true }
22+
convert_case = "0.6.0"
2223
indexmap = { workspace = true }
2324
miette = { workspace = true }
2425
minisign-verify = "0.2.2"
@@ -41,7 +42,7 @@ sha2 = { workspace = true }
4142
shell-words = { workspace = true }
4243
starbase_archive = { workspace = true }
4344
starbase_styles = { workspace = true }
44-
starbase_utils = { workspace = true, features = ["fs-lock"] }
45+
starbase_utils = { workspace = true, features = ["fs-lock", "yaml"] }
4546
thiserror = { workspace = true }
4647
tracing = { workspace = true }
4748
url = { version = "2.5.2", features = ["serde"] }

crates/core/src/registry/data.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ use warpgate::{Id, PluginLocator};
77
#[derive(Debug, Deserialize, Serialize, Schematic)]
88
#[serde(rename_all = "lowercase")]
99
pub enum PluginFormat {
10+
Json,
1011
Toml,
1112
Wasm,
13+
Yaml,
1214
}
1315

1416
/// Information about a person.

0 commit comments

Comments
 (0)