Skip to content

Commit

Permalink
add basic readme.md generator for easier manager
Browse files Browse the repository at this point in the history
  • Loading branch information
conmaster2112 committed Oct 4, 2024
1 parent 93d3806 commit 81f84a9
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
npm ci
- name: Check Build Commit
run: |
node .
npm run check-for-update
57 changes: 57 additions & 0 deletions DOCUMENTATION/__MAIN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Bedrock Documentation Generator

## Overview
This repository generates documentation for different versions of Bedrock. The generated docs are stored in the `./docs` directory. Before fetching any data, ensure that the data is generated in the specific branch by checking the `exist.json` file in the root directory. This file includes the build version, engine version, and flags indicating the types of generated data.

## Checking Generated Data
The `exist.json` file is crucial for determining if the necessary data has been generated for a specific branch. This file must be fetched first to verify the existence of the repository and the availability of the required data. It contains:
- **version**: The version of the documentation (e.g., x.x.x or x.x.x.x).
- **build-version**: The version of BDS used to generate the documentation.
- **flags**: An array indicating the types of content generated. This array may include additional data generated by some flags that are not specified here.

Example of `exist.json`:
```json
{
"version": "",
"build-version": "",
"flags": []
}
```

## Supported Branches
You can target specific versions via the following branches:
- **Latest Stable**: `stable`
- **Latest Preview**: `preview`
- **Specific Stable**: `stable-x.x.x` (e.g., `stable-1.20.10`)

## Flags
Flags in the `exist.json` file indicate the types of content generated for that branch. Before fetching any files, check for the appropriate flag to ensure the data exists. Read specific flags in sections about [Current Generator Flags](#current-flags).

## Targeting Files
To fetch the documentation files, use the following URL format:
```
https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/{branch}/docs/script_modules/@minecraft/{module_name}_{module_version}.json
```
Replace `{branch}` with the appropriate branch name (`stable`, `preview`, or `stable-x.x.x`), and `{module_name}` and `{module_version}` with the specific module name and version.

## Examples
### Preview Version
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/preview/docs/script_modules/@minecraft/server_1.7.0-beta.json`;
```

### Stable Version
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable/docs/script_modules/@minecraft/server_1.2.0.json`;
```

### Specific Stable Version
```js
const engine_version = "1.20.10";
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable-${engine_version}/docs/script_modules/@minecraft/server_1.2.0.json`;
```

## Contribution
We welcome contributions from the community! Here are the steps to get started:
1. **Fork the Repository**: You can't properly debug the repo without a full fork.
2. **Allow Actions on Your Fork**: Ensure that GitHub Actions are enabled on your fork to run tests and other automated processes.
29 changes: 29 additions & 0 deletions DOCUMENTATION/gen.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//@ts-nocheck
import { read, writeFileSync } from "node:fs";
import { GENERATORS_FLAGS } from "../src/flags/index.js";
import { dirname, resolve } from "node:path";
import { readFile } from "node:fs/promises";

export const MAIN_DATA = await readFile(resolve(import.meta.dirname, "./__MAIN.md"));
let flagsInfo = "";
const newline = "\n\r";

for (const generator of GENERATORS_FLAGS) {
let flagText = `### \`FLAG:${generator.flagId}\` Documentation${newline}`;
flagText += `> ${(generator.description??(
console.log("No generator metadata description for: " + generator.flagId),
"NO DESCRIPTION"
))}`.replaceAll(/(\r\n|\r|\n)(\s+|)/g, newline + "> ");
flagsInfo += flagText + newline;
}
let readme = `${MAIN_DATA}
## Current Flags
When you download files before that, you should check what content is available using the flag,
these flags determine what is currently available, if the given flag is not there then the given
information under this flag would not be generated or supported. always check that the given flag is available.
${GENERATORS_FLAGS.map(e=>` - \`${e.flagId}\``).join(newline)}
${flagsInfo}
`;
export const GENERAL_README = readme;
if(import.meta.filename == process.argv[1]) writeFileSync("./README.md", readme);
124 changes: 74 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,76 @@
# Bedrock Documentation Generator
## Available branches
You can target to specific version via each of branches, all generated docs are stored in `.\docs`. If you want to get version what the docs were generated from you can fetch for file in root directory called exist.json `.\exist.json`, this file has two types of version, the build version and engine version:
```json
{
"version":"", //x.x.x or x.x.x.x depends on preview or stable
"build-version":"", //x.x.x.x version of BDS generated with
"flags": [ //Example of flags
"generated_types",
"script_module_list",
"module_mapping",
"block_data2"
]
}
```
# Bedrock Documentation Generator

## Overview
This repository generates documentation for different versions of Bedrock. The generated docs are stored in the `./docs` directory. Before fetching any data, ensure that the data is generated in the specific branch by checking the `exist.json` file in the root directory. This file includes the build version, engine version, and flags indicating the types of generated data.

## Checking Generated Data
The `exist.json` file is crucial for determining if the necessary data has been generated for a specific branch. This file must be fetched first to verify the existence of the repository and the availability of the required data. It contains:
- **version**: The version of the documentation (e.g., x.x.x or x.x.x.x).
- **build-version**: The version of BDS used to generate the documentation.
- **flags**: An array indicating the types of content generated. This array may include additional data generated by some flags that are not specified here.

Example of `exist.json`:
```json
{
"version": "",
"build-version": "",
"flags": []
}
```

## Supported Branches
You can target specific versions via the following branches:
- **Latest Stable**: `stable`
- **Latest Preview**: `preview`
- **Specific Stable**: `stable-x.x.x` (e.g., `stable-1.20.10`)

## Flags
Flags in the `exist.json` file indicate the types of content generated for that branch. Before fetching any files, check for the appropriate flag to ensure the data exists. Read specific flags in sections about [Current Generator Flags](#current-flags).

## Targeting Files
To fetch the documentation files, use the following URL format:
```
https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/{branch}/docs/script_modules/@minecraft/{module_name}_{module_version}.json
```
Replace `{branch}` with the appropriate branch name (`stable`, `preview`, or `stable-x.x.x`), and `{module_name}` and `{module_version}` with the specific module name and version.

## Examples
### Preview Version
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/preview/docs/script_modules/@minecraft/server_1.7.0-beta.json`;
```

### Stable Version
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable/docs/script_modules/@minecraft/server_1.2.0.json`;
```

### Specific Stable Version
```js
const engine_version = "1.20.10";
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable-${engine_version}/docs/script_modules/@minecraft/server_1.2.0.json`;
```

## Contribution
We welcome contributions from the community! Here are the steps to get started:
1. **Fork the Repository**: You can't properly debug the repo without a full fork.
2. **Allow Actions on Your Fork**: Ensure that GitHub Actions are enabled on your fork to run tests and other automated processes.

Supported branches:
- **The Latest Stable** id: `stable`
- **The Latest Preview** id: `preview`
- **Specifc Stable** id `stable-x.x.x`
- `stable-1.20.10`
## Current Flags
When you download files before that, you should check what content is available using the flag,
these flags determine what is currently available, if the given flag is not there then the given
information under this flag would not be generated or supported. always check that the given flag is available.
- `METADATA`
- `SCRIPT_MODULES_MAPPING`
- `SCRIPT_DECLARATIONS`
- `BLOCKS_DATA`

### Flasgs
When you download files before that, you should check what content is available using the flag, these flags determine what is currently available, if the given flag is not there then the given information under this flag would not be generated or supported. always check that the given flag is available.
- `generated_types` - Generated Types availabled
- `script_module_list` - List of modules avaliabled in `exist.json`
- `module_mapping` - Modules mapping avaliable in `exist.json`
- `block_data2` - Block Generated hashes available in `./data/` folder

## Targeting Files
- **Targeting Preview Version**
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/preview/docs/script_modules/@minecraft/${module_name}_${module_version}.json`;
```
```js
`.../preview/docs/script_modules/@minecraft/server_1.7.0-beta.json`;
```
- Targeting Stable Version
```js
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable/docs/script_modules/@minecraft/${module_name}_${module_version}.json`;
```
```js
`.../stable/docs/script_modules/@minecraft/server_1.2.0.json`;
```
- **Targeting Specific Stable Version** engine_version `1.XX.XX` format
```js
const engine_version = "x.x.x";
`https://raw.githubusercontent.com/Bedrock-APIs/bds-docs/stable-${engine_version}/docs/script_modules/@minecraft/${module_name}_${module_version}.json`;
```
```js
`.../stable-1.20.10/docs/script_modules/@minecraft/server_1.2.0.json`;
```
### `FLAG:METADATA` Documentation
> This generator is moving BDS generated docs to **./metadata** and removes version from all JSON modules so github doesn't generates usless diff for every version change.
### `FLAG:SCRIPT_MODULES_MAPPING` Documentation
> This flag generator creates a detailed mapping of script modules from the documentation files. It reads and processes JSON files to gather metadata about various script modules. This information is then organized and added to main the `./exist.json` file, ensuring that all relevant data about script modules, such as names, UUIDs, and versions, is accurately captured
### `FLAG:SCRIPT_DECLARATIONS` Documentation
> The SCRIPT_DECLARATIONS flag generator creates TypeScript declaration files from JSON metadata about script modules. It processes JSON files, transforming their content into .d.ts files, which are then stored in the ./script-declarations directory. This ensures that all script modules have accurate TypeScript declarations, making it easier for developers to work with the generated documentation. The process involves reading the JSON files, transforming their content, and writing the output to the appropriate directory, ensuring that all tasks are completed successfully.
### `FLAG:BLOCKS_DATA` Documentation
> The BLOCKS_DATA flag generator creates JSON files containing detailed information about block states and blocks from vanilla data modules. It processes JSON files, extracting block properties and data items, and generates two output files: block_states.json and blocks.json. This ensures that all block-related data is accurately captured and organized, making it easier for developers to work with the generated documentation. The process involves reading the JSON files, transforming their content, and writing the output to the appropriate directory, ensuring that all tasks are completed successfully.

Expand Down
4 changes: 0 additions & 4 deletions dev.ps1

This file was deleted.

8 changes: 4 additions & 4 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/main.js",
"type": "module",
"scripts": {
"test": "powershell ./dev.ps1"
"check-for-update": "node .",
"gen-docs": "node ./DOCUMENTATION/gen.mjs"
},
"repository": {
"type": "git",
Expand All @@ -23,6 +24,6 @@
},
"devDependencies": {
"@types/node": "^22.7.4",
"typescript": "^5.7.0-dev.20241003"
"typescript": "^5.7.0-dev.20241004"
}
}
3 changes: 0 additions & 3 deletions run.sh

This file was deleted.

1 change: 1 addition & 0 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const LINK_GITHUB_DOMAIN = "https://raw.githubusercontent.com";
/**@type {`${typeof LINK_GITHUB_DOMAIN}/${typeof GITHUB_REPO_NAME}`} */
export const LINK_GITHUB_REPO = `${LINK_GITHUB_DOMAIN}/${GITHUB_REPO_NAME}`;
export const FILE_NAME_GITHUB_REPO_EXISTS = "exist.json";
export const FILE_NAME_GITHUB_README = "README.md";
export const FILE_NAME_BDS_TEST_CONFIG = "test_config.json"
export const FILE_NAME_BDS_BINARY = "bedrock_server"; //In general, .exe is not valid on linux platforms
export const FILE_NAME_GITIGNORE = ".gitignore";
Expand Down
8 changes: 7 additions & 1 deletion src/flags/data/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import { existsSync, mkdirSync } from "node:fs";

const OUTPUT_BLOCK_STATES = "block_states.json";
const OUTPUT_BLOCKS = "blocks.json";
const description = "The BLOCKS_DATA flag generator creates JSON files containing detailed information about block states and blocks from vanilla data modules. It processes JSON files, extracting block properties and data items, and generates two output files: block_states.json and blocks.json. This ensures that all block-related data is accurately captured and organized, making it easier for developers to work with the generated documentation. The process involves reading the JSON files, transforming their content, and writing the output to the appropriate directory, ensuring that all tasks are completed successfully.";
export default {
method: BLOCKS_DATA,
flagId: BLOCKS_DATA.name,
description
};
/**
*
* @param {string} inputDirPath
* @returns {Promise<boolean>}
*/
export async function BLOCKS_DATA(inputDirPath) {
async function BLOCKS_DATA(inputDirPath) {
// Init
const inputDir = resolve(inputDirPath, "docs/vanilladata_modules");
const tasks = [];
Expand Down
43 changes: 17 additions & 26 deletions src/flags/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import { BLOCKS_DATA } from "./data/blocks.js";
import { METADATA } from "./metadata.js";
import { SCRIPT_MODULES_MAPPING } from "./module_maping.js";
import { SCRIPT_DECLARATIONS } from "./script_decleration.js";

/**
* @type {{
* flagId: string, method(inputDir: string):Promise<boolean>
* }[]}
* @type {Promise<{default: {
* flagId: string, method(inputDir: string):Promise<boolean>,
* description?: string
* }}>[]}
*/
export const GENERATOR_FLAGS = [
{
flagId: METADATA.name,
method: METADATA
},
{
flagId: SCRIPT_MODULES_MAPPING.name,
method: SCRIPT_MODULES_MAPPING
},
{
flagId: SCRIPT_DECLARATIONS.name,
method: SCRIPT_DECLARATIONS
},
{
flagId: BLOCKS_DATA.name,
method: BLOCKS_DATA
}
];
export const GENERATORS = [
import("./metadata.js"),
import("./module_maping.js"),
import("./script_decleration.js"),
import("./data/blocks.js")
];
/**
* @type {{
* flagId: string, method(inputDir: string):Promise<boolean>,
* description?: string
* }[]}
*/
export const GENERATORS_FLAGS = (await Promise.all(GENERATORS)).map(e=>e.default);
9 changes: 8 additions & 1 deletion src/flags/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import { readFile, writeFile } from "node:fs/promises";
import { existsSync, mkdirSync } from "node:fs";

const OUTPUT_FOLDER = "./metadata";
const description = `This generator is moving BDS generated docs to **${OUTPUT_FOLDER}** and removes version from all JSON modules so github doesn't generates usless diff for every version change.`;

export default {
method: METADATA,
flagId: METADATA.name,
description: description
};
/**
*
* @param {string} inputDirPath
* @returns {Promise<boolean>}
*/
export async function METADATA(inputDirPath) {
async function METADATA(inputDirPath) {
// Init
const inputDir = resolve(inputDirPath, "docs");
const tasks = [];
Expand Down
9 changes: 8 additions & 1 deletion src/flags/module_maping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ import { FileTree } from "../functions.js";
import { readFile } from "node:fs/promises";
import { FILE_CONTENT_CURRENT_EXIST } from "../consts.js";

const description = `This flag generator creates a detailed mapping of script modules from the documentation files. It reads and processes JSON files to gather metadata about various script modules. This information is then organized and added to main the \`./exist.json\` file, ensuring that all relevant data about script modules, such as names, UUIDs, and versions, is accurately captured`;

export default {
method: SCRIPT_MODULES_MAPPING,
flagId: SCRIPT_MODULES_MAPPING.name,
description
};
/**
*
* @param {string} inputDirPath
* @returns {Promise<boolean>}
*/
export async function SCRIPT_MODULES_MAPPING(inputDirPath) {
async function SCRIPT_MODULES_MAPPING(inputDirPath) {
// Init
const inputDir = resolve(inputDirPath, "docs/script_modules");
const tasks = [];
Expand Down
Loading

0 comments on commit 81f84a9

Please sign in to comment.