From d5930e0a676128a5f8969bbb46983d12d0265980 Mon Sep 17 00:00:00 2001 From: cAttte <26514199+cAttte@users.noreply.github.com> Date: Wed, 7 Apr 2021 00:03:03 -0300 Subject: [PATCH] feat: use 'pretty' option when generating json --- bin/typedoc | 6 ++++-- scripts/rebuild_specs.js | 2 +- src/lib/application.ts | 12 ++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/bin/typedoc b/bin/typedoc index dad5e7ed1..be0dc0a8f 100755 --- a/bin/typedoc +++ b/bin/typedoc @@ -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) { @@ -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) { diff --git a/scripts/rebuild_specs.js b/scripts/rebuild_specs.js index 98956b845..52ecd5099 100644 --- a/scripts/rebuild_specs.js +++ b/scripts/rebuild_specs.js @@ -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. diff --git a/src/lib/application.ts b/src/lib/application.ts index 5f6493154..88ef7c62a 100644 --- a/src/lib/application.ts +++ b/src/lib/application.ts @@ -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 { out = Path.resolve(out); const eventData = { @@ -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); }