Skip to content

Commit

Permalink
Merge pull request #14 from sksat/publish-with-jsonschema
Browse files Browse the repository at this point in the history
build with local jsonschema files
  • Loading branch information
sksat authored Jan 2, 2022
2 parents 58271ab + beb8ee0 commit a12eae5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rdfmt"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

repository = "https://github.com/sksat/rdfmt-rs"
Expand All @@ -9,6 +9,13 @@ readme = "README.md"
description = "Reviewdog Diagnostic Format Rust Library"
license = "MIT"

[features]
default = []
build-with-local-schema = [] # empty feature for build with local jsonschema files(for docs.rs)

[package.metadata.docs.rs]
features = ["build-with-local-schema"]

[dependencies]
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.74"
Expand Down
24 changes: 18 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,30 @@ fn schema_url(file: &str) -> String {

fn download_schema(dir: &str, file: &str) -> Result<(), Box<dyn std::error::Error>> {
let url = schema_url(file);
let schema = reqwest::blocking::get(url)?.text()?;
let mut file = fs::File::create(format!("{}/{}", dir, file))?;
file.write_all(schema.as_bytes())?;

let file = format!("{}/{}", dir, file);
let file = Path::new(&file);

// skip download if file already exists
if !file.exists() {
let schema = reqwest::blocking::get(url)?.text()?;
let mut file = fs::File::create(file)?;
file.write_all(schema.as_bytes())?;
}

Ok(())
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
let out_dir = env::var("OUT_DIR").unwrap();
let schema_dir = format!("{}/json_schema", out_dir);

let local_schema = env::var("CARGO_FEATURE_BUILD_WITH_LOCAL_SCHEMA");
let schema_dir = if local_schema.is_ok() {
"json_schema".to_string()
} else {
format!("{}/json_schema", out_dir)
};

let gen_dir = format!("{}/generated", out_dir);

if Path::new(&schema_dir).exists() {
Expand All @@ -47,8 +61,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//"Suggestion.jsonschema",
];

//download_schema(&schema_dir, "DiagnosticResult.jsonschema")?;

let mut code = String::new();

for file in schema_files {
Expand Down

0 comments on commit a12eae5

Please sign in to comment.