Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
WIP templater
Browse files Browse the repository at this point in the history
NathanFlurry committed Dec 26, 2023
1 parent abed13e commit a9ba467
Showing 10 changed files with 163 additions and 5 deletions.
24 changes: 19 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/unrealengine,node,unity,godot
# Edit at https://www.toptal.com/developers/gitignore?templates=unrealengine,node,unity,godot
# Created by https://www.toptal.com/developers/gitignore/api/node,godot,unity,unrealengine,rust
# Edit at https://www.toptal.com/developers/gitignore?templates=node,godot,unity,unrealengine,rust

### Godot ###
# Godot 4+ specific ignores
@@ -158,6 +158,22 @@ dist
# SvelteKit build / generate output
.svelte-kit

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

### Unity ###
# This .gitignore file should be placed at the root of your Unity project directory
#
@@ -202,7 +218,6 @@ ExportedObj/
*.pidb
*.booproj
*.svd
*.pdb
*.mdb
*.opendb
*.VC.db
@@ -318,5 +333,4 @@ Build/Android/res/*/*
Plugins/**/Binaries/*
Plugins/**/Intermediate/*

# End of https://www.toptal.com/developers/gitignore/api/unrealengine,node,unity,godot

# End of https://www.toptal.com/developers/gitignore/api/node,godot,unity,unrealengine,rust
1 change: 1 addition & 0 deletions .prettierignore
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Contributing

## Templating README files

```
./scripts/template.sh
```

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Rivet Examples

💾 **Important** To download the assets to run these games, use [Git LFS](https://git-lfs.com/): `git lfs pull`

14 changes: 14 additions & 0 deletions lib/templater/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "example-templater"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.76"
semver = { version = "1.0.20", features = ["serde"] }
serde = { version = "1.0.193", features = ["derive"] }
tera = "1.19.1"
toml = "0.8.8"
walkdir = "2.4.0"
54 changes: 54 additions & 0 deletions lib/templater/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use anyhow::{Context, Result};
use semver::Version as SemVer;
use serde::{Deserialize, Serialize};
use std::{fs, path::Path};
use tera::Tera;

#[derive(Debug, Serialize, Deserialize)]
struct Config {
meta: ConfigMeta,
}

#[derive(Debug, Serialize, Deserialize)]
struct ConfigMeta {
engine_version: Option<SemVer>,
language: String,
rendering: String,
features: Vec<String>,
}

fn main() -> Result<()> {
let mut tera = Tera::default();
tera.add_raw_template("README.md", include_str!("../tpl/README.md.tera"))?;

for entry in walkdir::WalkDir::new(".") {
let entry = entry?;
if entry.file_name() == "example.toml" {
template_dir(&tera, entry.path().parent().context("path.parent")?)?;
}
}

Ok(())
}

fn template_dir(tera: &Tera, path: &Path) -> Result<()> {
// Read config
let config: Config = toml::from_str(&fs::read_to_string(path.join("example.toml"))?)?;

// Template Tera
let mut context = tera::Context::new();
context.insert("config", &config);

// Write README
let readme_content = tera.render("README.md", &context)?;
fs::write(path.join("README.md"), readme_content)?;

fs::write(path.join("LICENSE"), include_str!("../../../LICENSE"))?;

fs::write(path.join("LICENSE"), include_str!("../../../LICENSE"))?;

// TODO: Write .gitignore
// TODO: Write LICENSE

Ok(())
}
29 changes: 29 additions & 0 deletions lib/templater/tpl/README.md.tera
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# {{ config.title }}

{% if config.preview %}
![Preview](./media/preview.gif)
{% endif %}

[Visit Tutorial](https://rivet.gg/learn/godot/{{ config.tutorial_id | default(value="xxxx") }})

| {% for meta in meta %} {{ key }} |{% endfor %}
| {% for meta in meta %} --- |{% endfor %}
| {% for meta in meta %} {{ value }} |{% endfor %}

**Rivet Features**

{% for feature in config.features %}
- {{ feature }}
{% endfor %}

## Developing Locally

1. Download repo (gotta cater to the git noobs)
2. Open project
3. Login to Rivet in plugin & create game
4. Click run

## Deploying

[Deploying games with Godot](https://rivet.gg/docs/{{ config.deploying_id | default(value="xxxx") }})

24 changes: 24 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
trailingComma: 'none',
tabWidth: 2,
useTabs: false,
singleQuote: true,
printWidth: 110,
endOfLine: 'lf',
arrowParens: 'avoid',
bracketSpacing: true,
jsxBracketSameLine: true,
jsxSingleQuote: true,
overrides: [
{
files: '*.yaml',
options: {
tabWidth: 2,
useTabs: false
}
}
],
tailwindFunctions: ['clsx'],
plugins: [require('prettier-plugin-tailwindcss')]
};

5 changes: 5 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -euf

npx prettier@3 --write .

5 changes: 5 additions & 0 deletions scripts/template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -euf

cargo run --manifest-path lib/templater/Cargo.toml

0 comments on commit a9ba467

Please sign in to comment.