Skip to content

Commit

Permalink
Make collector script format JSON output
Browse files Browse the repository at this point in the history
If we're going to be using it to add additional data not in the source,
it should be human-readable.
  • Loading branch information
Razoric480 committed Feb 2, 2020
1 parent 3666364 commit faf79d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions godot-scripts/Collector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ func get_reference(files := PoolStringArray()) -> Array:
var symbols: Dictionary = workspace.generate_script_api(file)
reference.append(symbols)
return reference


func print_pretty_json(reference: Array) -> String:
return JSON.print(reference, " ")
14 changes: 9 additions & 5 deletions godot-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ You can find more detailed instructions inside the GDScript code itself.

## CLI version ##

An alternative to running the EditorScript is to use a command-line version of the tool found in the root of the repository. It requires `godot` to be in the PATH environment variable.
An alternative to running the EditorScript is to use a command-line version of the tool found in the root of the repository. It requires Godot to be in the PATH environment variable.

- **Windows**

```batch
windows.bat path/to/project project-name
```bash
generate_reference path\to\project project-name
```
- **Unix**
```bash
sh generate_reference.sh path/to/project project-name
```

`project-name` is optional - it will default to "project", and is the folder the distribution will be output into.
- The first parameter should be a path to a directory that contains a `project.godot` file.
- `project-name` is the folder the distribution will be output into

This script will copy the collector CLI script, run godot and quit, run the python module, and output the results into `project-name`.
2 changes: 1 addition & 1 deletion godot-scripts/ReferenceCollector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ func _run() -> void:
var files := PoolStringArray()
for dirpath in directories:
files.append_array(Collector.find_files(dirpath, patterns, is_recursive))
var json := to_json(Collector.get_reference(files))
var json := Collector.print_pretty_json(Collector.get_reference(files))
Collector.save_text(save_path, json)
2 changes: 1 addition & 1 deletion godot-scripts/ReferenceCollectorCLI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func _init() -> void:
var files := PoolStringArray()
for dirpath in directories:
files.append_array(Collector.find_files(dirpath, patterns, is_recursive))
var json := to_json(Collector.get_reference(files))
var json: String = Collector.print_pretty_json(Collector.get_reference(files))
Collector.save_text("res://reference.json", json)

0 comments on commit faf79d9

Please sign in to comment.