Skip to content

Commit be3e516

Browse files
committed
Add generated schema, validation, and clearer Luna branding
1 parent 1639362 commit be3e516

25 files changed

Lines changed: 800 additions & 103 deletions

File tree

Cargo.lock

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Luna
66

7-
> WIP: Library for Universal Networking Assets
7+
> WIP: Lightweight Universal Networked Assets
88
99
[![Latest release)](https://img.shields.io/github/v/release/LinwoodDev/Luna?color=1CC637&style=for-the-badge&logo=github&logoColor=1CC637)](https://github.com/LinwoodDev/Luna/releases)
1010
[![GitHub License badge](https://img.shields.io/github/license/LinwoodDev/Luna?color=1CC637&style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOTIiIGhlaWdodD0iMTkyIiBmaWxsPSIjZWJiNzMzIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiI%2BPHJlY3Qgd2lkdGg9IjI1NiIgaGVpZ2h0PSIyNTYiIGZpbGw9Im5vbmUiPjwvcmVjdD48cmVjdCB4PSIzMiIgeT0iNDgiIHdpZHRoPSIxOTIiIGhlaWdodD0iMTYwIiByeD0iOCIgc3Ryb2tlLXdpZHRoPSIxNiIgc3Ryb2tlPSIjZWJiNzMzIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGZpbGw9Im5vbmUiPjwvcmVjdD48bGluZSB4MT0iNzYiIHkxPSI5NiIgeDI9IjE4MCIgeTI9Ijk2IiBmaWxsPSJub25lIiBzdHJva2U9IiNlYmI3MzMiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSIxNiI%2BPC9saW5lPjxsaW5lIHgxPSI3NiIgeTE9IjEyOCIgeDI9IjE4MCIgeTI9IjEyOCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjZWJiNzMzIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iMTYiPjwvbGluZT48bGluZSB4MT0iNzYiIHkxPSIxNjAiIHgyPSIxODAiIHkyPSIxNjAiIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ViYjczMyIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjE2Ij48L2xpbmU%2BPC9zdmc%2B)](https://github.com/LinwoodDev/Luna/blob/main/LICENSE)
@@ -28,8 +28,9 @@
2828

2929
**This project is still in development and not ready for production use. Please join the matrix or discord server for updates!**
3030

31-
Luna is a build system to enable hosting a static library system for assets.
32-
It is designed to be flexible with a universal API to allow any app to use it.
31+
Luna stands for **Lightweight Universal Networked Assets**.
32+
33+
It is a static asset registry generator: you store asset metadata in TOML, Luna builds a versioned JSON index and an optional browsable documentation website. Apps can consume the index without a backend, login system, or custom server.
3334
Read more in the [documentation](https://luna.linwood.dev/docs/v1/intro).
3435

3536
## Official Apps
@@ -48,6 +49,8 @@ The API is not yet stable, but the CLI is usable.
4849

4950
Current todos:
5051

52+
- [x] Repository validation (`luna check` / `luna validate`)
53+
- [x] JSON Schema output (`luna schema`)
5154
- [x] Implement a bundling system to host assets in the docs
5255
- [x] Avatars
5356
- [x] Asset items
@@ -69,13 +72,15 @@ You can use Luna in your GitHub Actions workflow to generate your site.
6972
```yaml
7073
steps:
7174
- uses: actions/checkout@v6
72-
- uses: LinwoodDev/Luna@develop
75+
- uses: LinwoodDev/Luna@v0.1.0
7376
with:
7477
command: 'build'
7578
path: 'output/docs'
7679
index_path: 'output/index.json'
7780
```
7881
82+
During development you can pin `@main` or `@develop`, but release tags are the recommended input for reproducible builds.
83+
7984
If you only want to generate the index or docs separately, you can use the `generate` or `docs` commands.
8085

8186
### Custom docs templates and public files

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ branding:
66
color: 'green'
77
inputs:
88
command:
9-
description: 'Command to run (generate, docs, build, index, get)'
9+
description: 'Command to run (generate, docs, build, check, schema, index, get)'
1010
required: false
1111
default: 'generate'
1212
path:
@@ -18,6 +18,12 @@ inputs:
1818
page_size:
1919
description: 'Page size (only for docs command)'
2020
required: false
21+
bundle:
22+
description: 'Bundling strategy for docs/build (none, images, all)'
23+
required: false
24+
custom_root:
25+
description: 'Custom docs root containing templates, components, layouts, and public files'
26+
required: false
2127
args:
2228
description: 'Raw arguments to pass to the CLI (overrides other inputs)'
2329
required: false

api/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ edition = "2024"
88
[dependencies]
99
serde = { version = "1", features = ["derive"] }
1010
serde_json = "1"
11+
schemars = { version = "1", features = ["derive"] }
1112
toml = "1"

api/src/models/asset.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use crate::models::Named;
2+
use schemars::JsonSchema;
23
use serde::{Deserialize, Serialize};
34
use toml::value::Datetime;
45

56
// Path: content/{author}/{name}/asset.toml
6-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
7+
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Default)]
78
pub struct Asset {
89
pub author: String,
910
pub name: String,
@@ -21,18 +22,19 @@ pub struct Asset {
2122
pub categories: Vec<String>,
2223
}
2324

24-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
25+
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Default)]
2526
pub struct Version {
2627
pub name: String,
2728
pub changes: String,
29+
#[schemars(with = "Option<String>")]
2830
pub published: Option<Datetime>,
2931
pub download_url: String,
3032
pub sha256: String,
3133
pub blake3: Option<String>,
3234
}
3335

3436
// Path: content/{author}/author.toml
35-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
37+
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Default)]
3638
pub struct Author {
3739
pub name: String,
3840
pub display_name: Option<String>,

api/src/models/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
pub mod asset;
2+
pub mod schema;
3+
pub mod validation;
24

35
use std::collections::HashMap;
46

57
use asset::*;
8+
use schemars::JsonSchema;
69
use serde::{Deserialize, Serialize};
710

811
const FILE_VERSION: u8 = 1;
@@ -11,7 +14,7 @@ pub trait Named {
1114
fn name(&self) -> &str;
1215
}
1316

14-
#[derive(Debug, Serialize, Deserialize, Clone)]
17+
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
1518
pub struct RepositoryData {
1619
pub assets: Vec<Asset>,
1720
pub authors: Vec<Author>,
@@ -37,7 +40,7 @@ impl Named for RepositoryData {
3740
}
3841
}
3942

40-
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
43+
#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone, Default)]
4144
pub struct RepositoryInfo {
4245
pub name: String,
4346
pub summary: Option<String>,
@@ -71,4 +74,8 @@ impl RepositoryData {
7174
pub fn to_index(&self) -> serde_json::Result<String> {
7275
serde_json::to_string(&self)
7376
}
77+
78+
pub fn validate(&self) -> Result<(), validation::ValidationErrors> {
79+
validation::validate_repository(self)
80+
}
7481
}

api/src/models/schema.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use serde_json::{Value, json};
2+
3+
use super::RepositoryData;
4+
5+
pub const INDEX_SCHEMA_URL: &str = "https://luna.linwood.dev/schemas/index-v1.schema.json";
6+
7+
pub fn index_schema() -> Value {
8+
let mut schema = json!(schemars::schema_for!(RepositoryData));
9+
if let Some(object) = schema.as_object_mut() {
10+
object.insert("$id".to_string(), json!(INDEX_SCHEMA_URL));
11+
object.insert("title".to_string(), json!("Luna index v1"));
12+
}
13+
if let Some(file_version) = schema
14+
.pointer_mut("/properties/file_version")
15+
.and_then(Value::as_object_mut)
16+
{
17+
file_version.insert("const".to_string(), json!(1));
18+
}
19+
schema
20+
}
21+
22+
pub fn index_schema_pretty() -> serde_json::Result<String> {
23+
serde_json::to_string_pretty(&index_schema())
24+
}

0 commit comments

Comments
 (0)