Skip to content

Commit

Permalink
Merge pull request #321 from moonbitlang/docs-json-schema
Browse files Browse the repository at this point in the history
docs(zh): JSON schema
  • Loading branch information
Young-Flash authored Sep 19, 2024
2 parents 9e66b14 + cfeb000 commit fc5b289
Show file tree
Hide file tree
Showing 9 changed files with 581 additions and 5 deletions.
8 changes: 7 additions & 1 deletion crates/moon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ pub fn get_compiler_flags(src_dir: &Path, build_flags: &BuildFlags) -> anyhow::R
}

#[test]
fn gen_docs_for_moon_new() {
fn gen_docs_for_moon_help_page() {
let markdown: String = clap_markdown::help_markdown::<MoonBuildSubcommands>();
let markdown = markdown.replace("Default value: `zsh`", "Default value: `<your shell>`");
let markdown = markdown.replace("Default value: `bash`", "Default value: `<your shell>`");
let markdown = markdown.replace(
"Default value: `powershell`",
"Default value: `<your shell>`",
);
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let file_path =
std::path::PathBuf::from(&manifest_dir).join("../../docs/manual-zh/src/commands.md");
Expand Down
8 changes: 7 additions & 1 deletion crates/moonutil/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,5 +475,11 @@ fn validate_mod_json_schema() {
env!("CARGO_MANIFEST_DIR"),
"/../../docs/manual/src/source/mod_json_schema.html"
);
std::fs::write(html_path, content).unwrap();
std::fs::write(html_path, &content).unwrap();

let html_path_zh = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../docs/manual-zh/src/source/mod_json_schema.html"
);
std::fs::write(html_path_zh, content).unwrap();
}
8 changes: 7 additions & 1 deletion crates/moonutil/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,5 +507,11 @@ fn validate_pkg_json_schema() {
env!("CARGO_MANIFEST_DIR"),
"/../../docs/manual/src/source/pkg_json_schema.html"
);
std::fs::write(html_path, content).unwrap();
std::fs::write(html_path, &content).unwrap();

let zh_html_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../docs/manual-zh/src/source/pkg_json_schema.html"
);
std::fs::write(zh_html_path, content).unwrap();
}
1 change: 1 addition & 0 deletions docs/manual-zh/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
- [alert 列表](./package/alerts.md)
- [条件编译](./package/conditional-compilation.md)
- [预构建命令](./package/pre-build.md)
- [JSON Schema](./json_schema.md)
2 changes: 1 addition & 1 deletion docs/manual-zh/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ Discussion:

* `--shell <SHELL>` — The shell to generate completion for

Default value: `zsh`
Default value: `<your shell>`

Possible values: `bash`, `elvish`, `fish`, `powershell`, `zsh`

Expand Down
7 changes: 7 additions & 0 deletions docs/manual-zh/src/json_schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Config JSON Schema

## moon.mod.json
<iframe src="source/mod_json_schema.html" width="100%" height="500px" frameborder="0"></iframe>

## moon.pkg.json
<iframe src="source/pkg_json_schema.html" width="100%" height="500px" frameborder="0"></iframe>
143 changes: 143 additions & 0 deletions docs/manual-zh/src/source/mod_json_schema.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.9.2/jsoneditor.min.css" rel="stylesheet"
type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.9.2/jsoneditor.min.js"></script>

<title>moon.mod.json schema viewer</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f0f0f0;
}

h1 {
color: #333;
}

#schema-container {
max-width: 800px;
margin: 20px auto;
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
</style>
</head>

<body>
<div id="schema-container"></div>

<script>
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "JSON schema for MoonBit moon.mod.json files",
"description": "A module of MoonBit lang",
"type": "object",
"required": [
"name"
],
"properties": {
"alert-list": {
"description": "Alert list setting of the module",
"type": [
"string",
"null"
]
},
"deps": {
"description": "third-party dependencies of the module",
"type": [
"object",
"null"
],
"additionalProperties": {
"type": "string"
}
},
"description": {
"description": "description of this module",
"type": [
"string",
"null"
]
},
"keywords": {
"description": "keywords of this module",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"license": {
"description": "license of this module",
"type": [
"string",
"null"
]
},
"name": {
"description": "name of the module",
"type": "string"
},
"readme": {
"description": "path to module's README file",
"type": [
"string",
"null"
]
},
"repository": {
"description": "url to module's repository",
"type": [
"string",
"null"
]
},
"source": {
"description": "source code directory of this module",
"type": [
"string",
"null"
]
},
"version": {
"description": "version of the module",
"type": [
"string",
"null"
]
},
"warn-list": {
"description": "Warn list setting of the module",
"type": [
"string",
"null"
]
}
}
}
const container = document.getElementById('schema-container');
const options = {
language: 'en',
mode: 'view',
modes: ['code', 'form', 'text', 'tree', 'view'],
onError: function (err) {
console.error(err);
}
};
const editor = new JSONEditor(container, options, schema);
</script>
</body>

</html>
Loading

0 comments on commit fc5b289

Please sign in to comment.