Add support for Typedoc json output

This commit is contained in:
tisawyer 2017-04-11 10:22:47 -07:00
Родитель 6b94de3e9b
Коммит c0ed302df5
3 изменённых файлов: 51 добавлений и 18 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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": [