Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
chore: add json schema to website
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 10, 2023
1 parent ea55f7c commit bb71dee
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
19 changes: 14 additions & 5 deletions crates/rome_service/src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
//! The configuration is divided by "tool", and then it's possible to further customise it
//! by language. The language might further options divided by tool.

use crate::{DynRef, WorkspaceError};
use crate::{DynRef, WorkspaceError, VERSION};
use bpaf::Bpaf;
use rome_fs::{FileSystem, OpenOptions};
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::fs::DirBuilder;
use std::io::ErrorKind;
use std::num::NonZeroU64;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -347,11 +348,19 @@ pub fn create_config(
}
})?;

dbg!(VERSION);
// we now check if rome is installed inside `node_modules` and if so, we
let schema_path = Path::new("./node_modules/rome/configuration_schema.json");
let options = OpenOptions::default().read(true);
if fs.open_with_options(schema_path, options).is_ok() {
configuration.schema = schema_path.to_str().map(String::from);
if VERSION == "0.0.0" {
let schema_path = Path::new("./node_modules/rome/configuration_schema.json");
let options = OpenOptions::default().read(true);
if fs.open_with_options(schema_path, options).is_ok() {
configuration.schema = schema_path.to_str().map(String::from);
}
} else {
configuration.schema = Some(format!(
"https://docs.rome.tools/schemas/{}/schema.json",
VERSION
));
}

let contents = serde_json::to_string_pretty(&configuration).map_err(|_| {
Expand Down
11 changes: 11 additions & 0 deletions website/src/pages/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ You can specify a relative path to the schema of the `rome` npm package if `rome
}
```

If you have problems with resolving the physical file, you can use the one published in this site:


<CodeBlockHeader filename="rome.json" />

```json
{
"$schema": "https://docs.rome.tools/schemas/12.1.0/schema.json"
}
```

## `files`

### `files.maxSize`
Expand Down
16 changes: 16 additions & 0 deletions website/src/pages/schemas/12.1.0/schema.json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Run `ROME_VERSION=<version number> cargo codegen-website
// to generate a new schema
import {readFileSync} from "fs";
import {join, resolve} from "path"

export function get() {
const schemaPath = resolve(join("..", "npm", "rome", "configuration_schema.json"));
const schema = readFileSync(schemaPath, "utf8")

return new Response(schema, {
status: 200,
headers: {
"content-type": "application/json"
}
})
}
2 changes: 1 addition & 1 deletion xtask/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ rome_service = { path = "../../crates/rome_service", features = ["schemars"], op

[features]
configuration = ["rome_analyze", "rome_js_analyze", "rome_js_syntax", "pulldown-cmark"]
website = []
website = ["rome_service"]
schema = ["schemars", "serde_json", "rome_rowan", "rome_service", "rome_js_syntax", "rome_js_factory", "rome_js_formatter", "rome_json_formatter", "rome_json_parser", "rome_diagnostics"]
30 changes: 30 additions & 0 deletions xtask/codegen/src/generate_website.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rome_service::VERSION;
use std::fs;
use xtask::{project_root, Result};

Expand All @@ -9,7 +10,36 @@ description: Notes about the Rome's VSCode extension
---
"#;

const SCHEMA_TEMPLATE: &str = r#"// Run `ROME_VERSION=<version number> cargo codegen-website
// to generate a new schema
import {readFileSync} from "fs";
import {join, resolve} from "path"
export function get() {
const schemaPath = resolve(join("..", "npm", "rome", "configuration_schema.json"));
const schema = readFileSync(schemaPath, "utf8")
return new Response(schema, {
status: 200,
headers: {
"content-type": "application/json"
}
})
}"#;

/// Generates
pub fn generate_website() -> Result<()> {
if VERSION != "0.0.0" {
let schema_root_folder = project_root().join("website/src/pages/schemas");
let schema_version_folder = schema_root_folder.join(VERSION);
let schema_js_file = schema_version_folder.join("schema.json.js");
if schema_version_folder.exists() {
fs::remove_file(schema_js_file.clone())?;
fs::remove_dir(schema_version_folder.clone())?;
}
fs::create_dir(schema_version_folder.clone())?;
fs::write(schema_js_file.clone(), SCHEMA_TEMPLATE)?;
}
fs::remove_file(project_root().join("website/src/pages/vscode.mdx")).ok();
let readme = fs::read_to_string(project_root().join("editors/vscode/README.md"))?;

Expand Down

0 comments on commit bb71dee

Please sign in to comment.