Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: use 'pretty' option when generating json
  • Loading branch information
cAttte authored and Gerrit0 committed Apr 10, 2021
1 parent b3c856e commit d5930e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions bin/typedoc
Expand Up @@ -66,7 +66,8 @@ async function run(app) {
}
const json = app.options.getValue("json");
if (json) {
await app.generateJson(project, json);
const pretty = app.options.getValue("pretty");
await app.generateJson(project, json, pretty);
}

if (!out && !json) {
Expand All @@ -87,7 +88,8 @@ async function run(app) {
}
const json = app.options.getValue("json");
if (json) {
await app.generateJson(project, json);
const pretty = app.options.getValue("pretty");
await app.generateJson(project, json, pretty);
}

if (!out && !json) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/rebuild_specs.js
Expand Up @@ -107,7 +107,7 @@ async function rebuildRendererTest() {
app.options.setValue("entryPoints", app.expandInputFiles([src]));
const project = app.convert();
await app.generateDocs(project, out);
await app.generateJson(project, path.join(out, "specs.json"));
await app.generateJson(project, path.join(out, "specs.json"), true);

/**
* Avoiding sync methods here is... difficult.
Expand Down
12 changes: 8 additions & 4 deletions src/lib/application.ts
Expand Up @@ -387,12 +387,14 @@ export class Application extends ChildableComponent<
/**
* Run the converter for the given set of files and write the reflections to a json file.
*
* @param out The path and file name of the target file.
* @returns TRUE if the json file could be written successfully, otherwise FALSE.
* @param out The path and file name of the target file.
* @param format Whether the JSON data should be formatted with tabs.
* @returns Whether the JSON file could be written successfully.
*/
public async generateJson(
project: ProjectReflection,
out: string
out: string,
format = true
): Promise<void> {
out = Path.resolve(out);
const eventData = {
Expand All @@ -403,7 +405,9 @@ export class Application extends ChildableComponent<
begin: eventData,
end: eventData,
});
await FS.promises.writeFile(out, JSON.stringify(ser, null, "\t"));

const space = format ? "\t" : "";
await FS.promises.writeFile(out, JSON.stringify(ser, null, space));
this.logger.success("JSON written to %s", out);
}

Expand Down

0 comments on commit d5930e0

Please sign in to comment.