Skip to content

Commit

Permalink
WIP: load oranda.toml as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra committed Sep 5, 2023
1 parent e64fc31 commit 48bac50
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 90 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ members = ["generate-css"]

[dependencies]
ammonia = "3"
axoasset = { version = "0.4.0", features = ["json-serde", "toml-edit"] }
axoasset = { version = "0.4.0", features = ["json-serde", "toml-serde", "toml-edit"] }
axocli = "0.1.0"
axoproject = { version = "0.4.6", default-features = false, features = ["cargo-projects", "npm-projects"] }
axum = "0.6.18"
Expand Down
38 changes: 0 additions & 38 deletions oranda.json

This file was deleted.

29 changes: 29 additions & 0 deletions oranda.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build]
path_prefix = "oranda"

[styles]
theme = "axodark"
favicon = "https://www.axo.dev/favicon.ico"

[marketing]
analytics = { plausible = { domain = "opensource.axo.dev" }}

[marketing.social]
image = "https://www.axo.dev/meta_small.jpeg"
image_alt = "axo"
twitter_account = "@axodotdev"



[components]
changelog = true

[components.artifacts.package_managers.preferred]
npm = "npm install @axodotdev/oranda --save-dev"
cargo = "cargo install oranda --locked --profile=dist"

[components.artifacts.package_managers.additional]
npx = "npx @axodotdev/oranda"
binstall = "cargo binstall oranda"
nix-env = "nix-env -i oranda"
"nix flake" = "nix profile install github:axodotdev/oranda"
112 changes: 61 additions & 51 deletions src/config/oranda_config.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
use axoasset::SourceFile;
use camino::Utf8PathBuf;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::errors::*;

use super::{BuildLayer, ComponentLayer, MarketingLayer, ProjectLayer, StyleLayer, WorkspaceLayer};

/// Configuration for `oranda` (typically stored in oranda.json)
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OrandaLayer {
/// Info about the project/application you're making a site for
///
/// All of these values should automatically be sourced from your Cargo.toml or package.json
/// whenever possible. You should only need to set these if you want to override the value.
pub project: Option<ProjectLayer>,
/// Settings for the build/output of the site
pub build: Option<BuildLayer>,
/// Settings for social/marketing/analytics
pub marketing: Option<MarketingLayer>,
/// Settings for themes/styles of the site
pub styles: Option<StyleLayer>,
/// Additional optional components
pub components: Option<ComponentLayer>,
/// Workspace configuration
pub workspace: Option<WorkspaceLayer>,
/// Field that text-editors can use to fetch the schema for this struct
///
/// We never use this, but we don't want to error out if its set.
#[serde(rename = "$schema")]
pub _schema: Option<String>,
}

impl OrandaLayer {
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
let config_result = SourceFile::load_local(config_path.as_path());

match config_result {
Ok(config) => {
let data: OrandaLayer = config.deserialize_json()?;
Ok(Some(data))
}
Err(_) => {
tracing::debug!("No config found, using default values");
Ok(None)
}
}
}
}
use axoasset::SourceFile;
use camino::Utf8PathBuf;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::errors::*;

use super::{BuildLayer, ComponentLayer, MarketingLayer, ProjectLayer, StyleLayer, WorkspaceLayer};

/// Configuration for `oranda` (typically stored in oranda.json)
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OrandaLayer {
/// Info about the project/application you're making a site for
///
/// All of these values should automatically be sourced from your Cargo.toml or package.json
/// whenever possible. You should only need to set these if you want to override the value.
pub project: Option<ProjectLayer>,
/// Settings for the build/output of the site
pub build: Option<BuildLayer>,
/// Settings for social/marketing/analytics
pub marketing: Option<MarketingLayer>,
/// Settings for themes/styles of the site
pub styles: Option<StyleLayer>,
/// Additional optional components
pub components: Option<ComponentLayer>,
/// Workspace configuration
pub workspace: Option<WorkspaceLayer>,
/// Field that text-editors can use to fetch the schema for this struct
///
/// We never use this, but we don't want to error out if its set.
#[serde(rename = "$schema")]
pub _schema: Option<String>,
}

impl OrandaLayer {
pub fn load(config_path: &Utf8PathBuf) -> Result<Option<OrandaLayer>> {
let mut config_path = config_path.to_owned();
if config_path.extension() == Some("json") {
if config_path.exists() {
let config = SourceFile::load_local(config_path.as_path())?;
return Ok(Some(config.deserialize_json()?));
} else {
// Temporary hack
config_path.set_extension("toml");
}
}
if !config_path.exists() {
tracing::debug!("No config found, using default values");
return Ok(None);
}
if config_path.extension() == Some("toml") {
tracing::warn!("!!!Using toml config!!!!");
let config = SourceFile::load_local(config_path.as_path())?;
return Ok(Some(config.deserialize_toml()?));
}

tracing::debug!("No config found, using default values");
Ok(None)
}
}

0 comments on commit 48bac50

Please sign in to comment.