-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move to new crate. * Wrap in feature. * Update actions. * Rename function. * Update report. * Add command.
- Loading branch information
Showing
25 changed files
with
501 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
releases: | ||
"@moonrepo/cli": minor | ||
"@moonrepo/core-linux-arm64-gnu": minor | ||
"@moonrepo/core-linux-arm64-musl": minor | ||
"@moonrepo/core-linux-x64-gnu": minor | ||
"@moonrepo/core-linux-x64-musl": minor | ||
"@moonrepo/core-macos-arm64": minor | ||
"@moonrepo/core-macos-x64": minor | ||
"@moonrepo/core-windows-x64-msvc": minor | ||
'@moonrepo/cli': minor | ||
'@moonrepo/core-linux-arm64-gnu': minor | ||
'@moonrepo/core-linux-arm64-musl': minor | ||
'@moonrepo/core-linux-x64-gnu': minor | ||
'@moonrepo/core-linux-x64-musl': minor | ||
'@moonrepo/core-macos-arm64': minor | ||
'@moonrepo/core-macos-x64': minor | ||
'@moonrepo/core-windows-x64-msvc': minor | ||
'@moonrepo/report': patch | ||
'@moonrepo/types': minor | ||
|
||
declined: | ||
- '@moonrepo/nx-compat' | ||
- '@moonrepo/runtime' | ||
- website |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod sync_codeowners; | ||
mod sync_config_schemas; | ||
mod sync_vcs_hooks; | ||
|
||
pub use sync_codeowners::*; | ||
pub use sync_config_schemas::*; | ||
pub use sync_vcs_hooks::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use moon_app_context::AppContext; | ||
use moon_common::color; | ||
use moon_config::Version; | ||
use moon_config_schema::json_schemas::generate_json_schemas; | ||
use moon_hash::hash_content; | ||
use tracing::{instrument, warn}; | ||
|
||
hash_content!( | ||
pub struct ConfigSchemaHash<'cfg> { | ||
moon_version: &'cfg Version, | ||
} | ||
); | ||
|
||
#[instrument(skip_all)] | ||
pub async fn sync_config_schemas(app_context: &AppContext, force: bool) -> miette::Result<bool> { | ||
let out_dir = app_context.cache_engine.cache_dir.join("schemas"); | ||
|
||
if let Err(error) = if force { | ||
generate_json_schemas(out_dir).map(|_| true) | ||
} else { | ||
app_context | ||
.cache_engine | ||
.execute_if_changed( | ||
"configSchemas.json", | ||
ConfigSchemaHash { | ||
moon_version: &app_context.cli_version, | ||
}, | ||
|| async { generate_json_schemas(out_dir) }, | ||
) | ||
.await | ||
} { | ||
warn!( | ||
"Failed to generate schemas for configuration: {}", | ||
color::muted_light(error.to_string()) | ||
); | ||
|
||
return Ok(false); | ||
} | ||
|
||
Ok(true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::helpers::create_progress_bar; | ||
use crate::session::CliSession; | ||
use clap::Args; | ||
use moon_actions::operations::sync_config_schemas; | ||
use starbase::AppResult; | ||
use tracing::instrument; | ||
|
||
#[derive(Args, Clone, Debug)] | ||
pub struct SyncConfigSchemasArgs { | ||
#[arg(long, help = "Bypass cache and force create schemas")] | ||
force: bool, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub async fn sync(session: CliSession, args: SyncConfigSchemasArgs) -> AppResult { | ||
let done = create_progress_bar("Generating configuration schemas..."); | ||
|
||
let context = session.get_app_context()?; | ||
|
||
sync_config_schemas(&context, args.force).await?; | ||
|
||
done("Successfully generated schemas", true); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod codeowners; | ||
pub mod config_schemas; | ||
pub mod hooks; | ||
pub mod projects; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "moon_config_schema" | ||
version = "0.0.1" | ||
edition = "2021" | ||
license = "MIT" | ||
description = "Config schema generator." | ||
homepage = "https://moonrepo.dev/moon" | ||
repository = "https://github.com/moonrepo/moon" | ||
publish = false | ||
|
||
[dependencies] | ||
moon_config = { path = "../config" } | ||
miette = { workspace = true } | ||
schematic = { workspace = true, features = ["renderer_json_schema", "schema"] } | ||
|
||
[features] | ||
default = [] | ||
typescript = ["schematic/renderer_typescript"] | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use moon_config::*; | ||
use schematic::schema::json_schema::{JsonSchemaOptions, JsonSchemaRenderer}; | ||
use schematic::schema::SchemaGenerator; | ||
use std::path::Path; | ||
|
||
fn create_jsonschema_renderer() -> JsonSchemaRenderer<'static> { | ||
JsonSchemaRenderer::new(JsonSchemaOptions { | ||
markdown_description: true, | ||
mark_struct_fields_required: false, | ||
set_field_name_as_title: true, | ||
..JsonSchemaOptions::default() | ||
}) | ||
} | ||
|
||
fn generate_project(out_dir: &Path) -> miette::Result<()> { | ||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<ProjectConfig>(); | ||
generator.generate(out_dir.join("project.json"), create_jsonschema_renderer()) | ||
} | ||
|
||
fn generate_tasks(out_dir: &Path) -> miette::Result<()> { | ||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<InheritedTasksConfig>(); | ||
generator.generate(out_dir.join("tasks.json"), create_jsonschema_renderer()) | ||
} | ||
|
||
fn generate_template(out_dir: &Path) -> miette::Result<()> { | ||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<TemplateConfig>(); | ||
generator.generate(out_dir.join("template.json"), create_jsonschema_renderer())?; | ||
|
||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<TemplateFrontmatterConfig>(); | ||
generator.generate( | ||
out_dir.join("template-frontmatter.json"), | ||
create_jsonschema_renderer(), | ||
) | ||
} | ||
|
||
fn generate_toolchain(out_dir: &Path) -> miette::Result<()> { | ||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<ToolchainConfig>(); | ||
generator.generate(out_dir.join("toolchain.json"), create_jsonschema_renderer()) | ||
} | ||
|
||
fn generate_workspace(out_dir: &Path) -> miette::Result<()> { | ||
let mut generator = SchemaGenerator::default(); | ||
generator.add::<WorkspaceConfig>(); | ||
generator.generate(out_dir.join("workspace.json"), create_jsonschema_renderer()) | ||
} | ||
|
||
pub fn generate_json_schemas(out_dir: impl AsRef<Path>) -> miette::Result<()> { | ||
let out_dir = out_dir.as_ref(); | ||
|
||
generate_project(out_dir)?; | ||
generate_tasks(out_dir)?; | ||
generate_template(out_dir)?; | ||
generate_toolchain(out_dir)?; | ||
generate_workspace(out_dir)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod json_schemas; | ||
#[cfg(feature = "typescript")] | ||
pub mod typescript_types; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use moon_config_schema::json_schemas::generate_json_schemas; | ||
#[cfg(feature = "typescript")] | ||
use moon_config_schema::typescript_types::generate_typescript_types; | ||
use std::env; | ||
use std::process::Command; | ||
|
||
fn main() { | ||
let cwd = env::current_dir().unwrap(); | ||
|
||
generate_json_schemas(cwd.join("website/static/schemas")).unwrap(); | ||
|
||
#[cfg(feature = "typescript")] | ||
generate_typescript_types(cwd.join("packages/types/src")).unwrap(); | ||
|
||
// Run prettier | ||
let prettier = cwd.join("node_modules/.bin/prettier"); | ||
|
||
if prettier.exists() { | ||
let mut cmd = Command::new(prettier); | ||
cmd.args(["--write", "packages/types"]); | ||
cmd.current_dir(cwd); | ||
cmd.output().unwrap(); | ||
} | ||
} |
Oops, something went wrong.