Skip to content

Commit a36d712

Browse files
Add tsconfig.json support
1 parent d6a0630 commit a36d712

File tree

6 files changed

+170
-2
lines changed

6 files changed

+170
-2
lines changed

lib/utils/options/readers/arguments.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@ var __extends = (this && this.__extends) || function (d, b) {
33
function __() { this.constructor = d; }
44
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
55
};
6+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
8+
switch (arguments.length) {
9+
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
10+
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
11+
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
12+
}
13+
};
14+
var __metadata = (this && this.__metadata) || function (k, v) {
15+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16+
};
617
var ts = require("typescript");
18+
var component_1 = require("../../component");
719
var options_1 = require("../options");
820
var declaration_1 = require("../declaration");
921
var ArgumentsReader = (function (_super) {
@@ -87,6 +99,10 @@ var ArgumentsReader = (function (_super) {
8799
}
88100
this.parseArguments(event, args);
89101
};
102+
ArgumentsReader = __decorate([
103+
component_1.Component({ name: "options:arguments" }),
104+
__metadata('design:paramtypes', [])
105+
], ArgumentsReader);
90106
return ArgumentsReader;
91107
})(options_1.OptionsComponent);
92108
exports.ArgumentsReader = ArgumentsReader;

lib/utils/options/readers/tsconfig.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var __extends = (this && this.__extends) || function (d, b) {
2+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3+
function __() { this.constructor = d; }
4+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
5+
};
6+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
7+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
8+
switch (arguments.length) {
9+
case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
10+
case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
11+
case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
12+
}
13+
};
14+
var __metadata = (this && this.__metadata) || function (k, v) {
15+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
16+
};
17+
var Path = require("path");
18+
var FS = require("fs");
19+
var _ = require("lodash");
20+
var component_1 = require("../../component");
21+
var options_1 = require("../options");
22+
var declaration_1 = require("../declaration");
23+
var TSConfigReader = (function (_super) {
24+
__extends(TSConfigReader, _super);
25+
function TSConfigReader() {
26+
_super.apply(this, arguments);
27+
}
28+
TSConfigReader.prototype.initialize = function () {
29+
this.listenTo(this.owner, options_1.DiscoverEvent.DISCOVER, this.onDiscover, -100);
30+
};
31+
TSConfigReader.prototype.onDiscover = function (event) {
32+
if (TSConfigReader.OPTIONS_KEY in event.data) {
33+
this.load(event, event.data[TSConfigReader.OPTIONS_KEY]);
34+
}
35+
else if (this.application.isCLI) {
36+
var file = Path.resolve('tsconfig.json');
37+
if (FS.existsSync(file)) {
38+
this.load(event, file);
39+
}
40+
}
41+
};
42+
TSConfigReader.prototype.load = function (event, fileName) {
43+
if (!FS.existsSync(fileName)) {
44+
event.addError('The tsconfig file %s does not exist.', fileName);
45+
return;
46+
}
47+
var data = require(fileName);
48+
if ("files" in data && _.isArray(data.files)) {
49+
event.inputFiles = data.files;
50+
}
51+
if ("compilerOptions" in data) {
52+
_.merge(event.data, data.compilerOptions);
53+
}
54+
if ("typedocOptions" in data) {
55+
_.merge(event.data, data.typedocOptions);
56+
}
57+
};
58+
TSConfigReader.OPTIONS_KEY = 'tsconfig';
59+
__decorate([
60+
component_1.Option({
61+
name: TSConfigReader.OPTIONS_KEY,
62+
help: 'Specify a js option file that should be loaded. If not specified TypeDoc will look for \'typedoc.js\' in the current directory.',
63+
type: declaration_1.ParameterType.String,
64+
hint: declaration_1.ParameterHint.File
65+
}),
66+
__metadata('design:type', String)
67+
], TSConfigReader.prototype, "options");
68+
TSConfigReader = __decorate([
69+
component_1.Component({ name: "options:tsconfig" }),
70+
__metadata('design:paramtypes', [])
71+
], TSConfigReader);
72+
return TSConfigReader;
73+
})(options_1.OptionsComponent);
74+
exports.TSConfigReader = TSConfigReader;

lib/utils/options/readers/typedoc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
1717
var Path = require("path");
1818
var FS = require("fs");
1919
var _ = require("lodash");
20+
var component_1 = require("../../component");
2021
var options_1 = require("../options");
2122
var declaration_1 = require("../declaration");
22-
var component_1 = require("../../component");
2323
var TypedocReader = (function (_super) {
2424
__extends(TypedocReader, _super);
2525
function TypedocReader() {
@@ -77,6 +77,10 @@ var TypedocReader = (function (_super) {
7777
}),
7878
__metadata('design:type', String)
7979
], TypedocReader.prototype, "options");
80+
TypedocReader = __decorate([
81+
component_1.Component({ name: "options:typedoc" }),
82+
__metadata('design:paramtypes', [])
83+
], TypedocReader);
8084
return TypedocReader;
8185
})(options_1.OptionsComponent);
8286
exports.TypedocReader = TypedocReader;

src/lib/utils/options/readers/arguments.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as ts from "typescript";
22

3+
import {Component} from "../../component";
34
import {DiscoverEvent, OptionsComponent} from "../options";
45
import {ParameterType} from "../declaration";
56

67

8+
@Component({name:"options:arguments"})
79
export class ArgumentsReader extends OptionsComponent
810
{
911
initialize() {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as Path from "path";
2+
import * as FS from "fs";
3+
import * as _ from "lodash";
4+
5+
import {Component, Option} from "../../component";
6+
import {OptionsComponent, DiscoverEvent} from "../options";
7+
import {ParameterType, ParameterHint} from "../declaration";
8+
9+
10+
@Component({name:"options:tsconfig"})
11+
export class TSConfigReader extends OptionsComponent
12+
{
13+
@Option({
14+
name: TSConfigReader.OPTIONS_KEY,
15+
help: 'Specify a js option file that should be loaded. If not specified TypeDoc will look for \'typedoc.js\' in the current directory.',
16+
type: ParameterType.String,
17+
hint: ParameterHint.File
18+
})
19+
options:string;
20+
21+
/**
22+
* The name of the parameter that specifies the tsconfig file.
23+
*/
24+
private static OPTIONS_KEY:string = 'tsconfig';
25+
26+
27+
28+
initialize() {
29+
this.listenTo(this.owner, DiscoverEvent.DISCOVER, this.onDiscover, -100);
30+
}
31+
32+
33+
onDiscover(event:DiscoverEvent) {
34+
if (TSConfigReader.OPTIONS_KEY in event.data) {
35+
this.load(event, event.data[TSConfigReader.OPTIONS_KEY]);
36+
} else if (this.application.isCLI) {
37+
var file = Path.resolve('tsconfig.json');
38+
if (FS.existsSync(file)) {
39+
this.load(event, file);
40+
}
41+
}
42+
}
43+
44+
45+
/**
46+
* Load the specified tsconfig file.
47+
*
48+
* @param event The event that triggered the loading. Used to store error messages.
49+
* @param fileName The absolute path and file name of the tsconfig file.
50+
*/
51+
load(event:DiscoverEvent, fileName:string) {
52+
if (!FS.existsSync(fileName)) {
53+
event.addError('The tsconfig file %s does not exist.', fileName);
54+
return;
55+
}
56+
57+
var data = require(fileName);
58+
59+
if ("files" in data && _.isArray(data.files)) {
60+
event.inputFiles = data.files;
61+
}
62+
63+
if ("compilerOptions" in data) {
64+
_.merge(event.data, data.compilerOptions);
65+
}
66+
67+
if ("typedocOptions" in data) {
68+
_.merge(event.data, data.typedocOptions);
69+
}
70+
}
71+
}

src/lib/utils/options/readers/typedoc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import * as Path from "path";
22
import * as FS from "fs";
33
import * as _ from "lodash";
44

5+
import {Component, Option} from "../../component";
56
import {OptionsComponent, DiscoverEvent} from "../options";
67
import {ParameterType, ParameterHint} from "../declaration";
7-
import {Option} from "../../component";
88

99

10+
@Component({name:"options:typedoc"})
1011
export class TypedocReader extends OptionsComponent
1112
{
1213
@Option({

0 commit comments

Comments
 (0)