From c0ed302df5ee7097b311bbfd11995f5280f6bd19 Mon Sep 17 00:00:00 2001 From: tisawyer Date: Tue, 11 Apr 2017 10:22:47 -0700 Subject: [PATCH] Add support for Typedoc json output --- README.md | 12 ++++++++++++ index.js | 55 ++++++++++++++++++++++++++++++++++++---------------- package.json | 2 +- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a3ffae0..f978a8a 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,18 @@ With the default configuration, the above example would produce the docs under t Relative paths can also be specified as the out parameter. For example out: '../docs', would produce the docs under the following path: ./docs. +Output to a json file is also supported by setting the 'json' property instead of the 'out' property in your configuration. For example: + +``` +plugins: [ + new TypedocWebpackPlugin({ + name: 'Contoso' + mode: 'file', + json: './docs.json' + }) +] +``` + __Input__ Specifying input for the plugin can be done in multiple ways diff --git a/index.js b/index.js index cc9c4b4..7eab024 100644 --- a/index.js +++ b/index.js @@ -37,17 +37,21 @@ function TypedocWebpackPlugin(options, input) { this.startTime = Date.now(); this.prevTimestamps = {}; this.defaultTypedocOptions = { - out: './docs', - module: 'commonjs', - target: 'es5', - exclude: '**/node_modules/**/*.*', - experimentalDecorators: true, - excludeExternals: true + module: 'commonjs', + target: 'es5', + exclude: '**/node_modules/**/*.*', + experimentalDecorators: true, + excludeExternals: true }; // merge user options into default options and assign merge(this.defaultTypedocOptions, options); - this.typeDocOptions = this.defaultTypedocOptions; + this.typeDocOptions = this.defaultTypedocOptions; + + //only set default output directory if neither out or json properties are set + if (!this.typeDocOptions.out && !this.typeDocOptions.json) { + this.typeDocOptions.out = "./docs" + } } /* @@ -76,24 +80,41 @@ TypedocWebpackPlugin.prototype.apply = function(compiler) { // if typescript files have been changed or we cannot determine what files have been changed run typedoc build if(tsFileEdited || changedFiles.length === 0) { - // If an absolute path set in self.typeDocOptions.out, use that - // else if the output path is specified in webpack config and out is relative - // output typedocs relative to that path + // If an absolute path set in self.typeDocOptions.out or self.typeDocOptions.json, use that + // else if the output path is specified in webpack config and out is relative, output typedocs relative to that path var typedocOptions = clone(self.typeDocOptions); - if(path.isAbsolute(self.typeDocOptions.out)){ - typedocOptions.out = self.typeDocOptions.out; - }else if(compiler.options.output && compiler.options.output.path) { - typedocOptions.out = path.join(compiler.options.output.path, self.typeDocOptions.out); + // output can be either json or directory + if(self.typeDocOptions.json) { + if(path.isAbsolute(self.typeDocOptions.json)) { + typedocOptions.json = self.typeDocOptions.json; + } + else if(compiler.options.output && compiler.options.output.path) { + typedocOptions.json = path.join(compiler.options.output.path, self.typeDocOptions.json); + } + } + else { + if(path.isAbsolute(self.typeDocOptions.out)) { + typedocOptions.out = self.typeDocOptions.out; + } + else if(compiler.options.output && compiler.options.output.path) { + typedocOptions.out = path.join(compiler.options.output.path, self.typeDocOptions.out); + } } var typedocApp = new typedoc.Application(typedocOptions); var src = typedocApp.expandInputFiles(self.inputFiles); var project = typedocApp.convert(src); - + if (project) { - console.log('Generating updated typedocs'); - typedocApp.generateDocs(project, typedocOptions.out); + if(typedocOptions.json) { + console.log('Generating typedoc json'); + typedocApp.generateJson(project, typedocOptions.json); + } + else { + console.log('Generating updated typedocs'); + typedocApp.generateDocs(project, typedocOptions.out); + } } } else { diff --git a/package.json b/package.json index 674e844..bc3afb3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typedoc-webpack-plugin", "author": "Microsoft Corp.", "homepage": "https://github.com/Microsoft/Typedoc-Webpack-Plugin", - "version": "1.1.3", + "version": "1.1.4", "license": "MIT", "description": "Runs typedoc compilation as a webpack plugin", "keywords": [