1 | "use strict";
|
2 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
3 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
4 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
5 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
6 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
7 | };
|
8 | var Application_1;
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | const Path = require("path");
|
11 | const FS = require("fs");
|
12 | const typescript = require("typescript");
|
13 | const index_1 = require("./converter/index");
|
14 | const renderer_1 = require("./output/renderer");
|
15 | const serialization_1 = require("./serialization");
|
16 | const index_2 = require("./models/index");
|
17 | const index_3 = require("./utils/index");
|
18 | const paths_1 = require("./utils/paths");
|
19 | const component_1 = require("./utils/component");
|
20 | const index_4 = require("./utils/options/index");
|
21 | const declaration_1 = require("./utils/options/declaration");
|
22 | let Application = Application_1 = class Application extends component_1.ChildableComponent {
|
23 | constructor(options) {
|
24 | super(component_1.DUMMY_APPLICATION_OWNER);
|
25 | this.logger = new index_3.ConsoleLogger();
|
26 | this.converter = this.addComponent('converter', index_1.Converter);
|
27 | this.serializer = this.addComponent('serializer', serialization_1.Serializer);
|
28 | this.renderer = this.addComponent('renderer', renderer_1.Renderer);
|
29 | this.plugins = this.addComponent('plugins', index_3.PluginHost);
|
30 | this.options = this.addComponent('options', index_4.Options);
|
31 | this.bootstrap(options);
|
32 | }
|
33 | bootstrap(options) {
|
34 | this.options.read(options, index_4.OptionsReadMode.Prefetch);
|
35 | const logger = this.loggerType;
|
36 | if (typeof logger === 'function') {
|
37 | this.logger = new index_3.CallbackLogger(logger);
|
38 | }
|
39 | else if (logger === 'none') {
|
40 | this.logger = new index_3.Logger();
|
41 | }
|
42 | this.plugins.load();
|
43 | return this.options.read(this.options.getRawValues(), index_4.OptionsReadMode.Fetch);
|
44 | }
|
45 | get application() {
|
46 | return this;
|
47 | }
|
48 | get isCLI() {
|
49 | return false;
|
50 | }
|
51 | getTypeScriptPath() {
|
52 | return Path.dirname(require.resolve('typescript'));
|
53 | }
|
54 | getTypeScriptVersion() {
|
55 | const tsPath = this.getTypeScriptPath();
|
56 | const json = JSON.parse(FS.readFileSync(Path.join(tsPath, '..', 'package.json'), 'utf8'));
|
57 | return json.version;
|
58 | }
|
59 | convert(src) {
|
60 | this.logger.writeln('Using TypeScript %s from %s', this.getTypeScriptVersion(), this.getTypeScriptPath());
|
61 | const result = this.converter.convert(src);
|
62 | if (result.errors && result.errors.length) {
|
63 | this.logger.diagnostics(result.errors);
|
64 | if (this.ignoreCompilerErrors) {
|
65 | this.logger.resetErrors();
|
66 | return result.project;
|
67 | }
|
68 | else {
|
69 | return;
|
70 | }
|
71 | }
|
72 | else {
|
73 | return result.project;
|
74 | }
|
75 | }
|
76 | generateDocs(input, out) {
|
77 | const project = input instanceof index_2.ProjectReflection ? input : this.convert(input);
|
78 | if (!project) {
|
79 | return false;
|
80 | }
|
81 | out = Path.resolve(out);
|
82 | this.renderer.render(project, out);
|
83 | if (this.logger.hasErrors()) {
|
84 | this.logger.error('Documentation could not be generated due to the errors above.');
|
85 | }
|
86 | else {
|
87 | this.logger.success('Documentation generated at %s', out);
|
88 | }
|
89 | return true;
|
90 | }
|
91 | generateJson(input, out) {
|
92 | const project = input instanceof index_2.ProjectReflection ? input : this.convert(input);
|
93 | if (!project) {
|
94 | return false;
|
95 | }
|
96 | out = Path.resolve(out);
|
97 | const eventData = { outputDirectory: Path.dirname(out), outputFile: Path.basename(out) };
|
98 | const ser = this.serializer.projectToObject(project, { begin: eventData, end: eventData });
|
99 | index_3.writeFile(out, JSON.stringify(ser, null, '\t'), false);
|
100 | this.logger.success('JSON written to %s', out);
|
101 | return true;
|
102 | }
|
103 | expandInputFiles(inputFiles = []) {
|
104 | let files = [];
|
105 | const exclude = this.exclude ? paths_1.createMinimatch(this.exclude) : [];
|
106 | function isExcluded(fileName) {
|
107 | return exclude.some(mm => mm.match(fileName));
|
108 | }
|
109 | const supportedFileRegex = this.options.getCompilerOptions().allowJs ? /\.[tj]sx?$/ : /\.tsx?$/;
|
110 | function add(file) {
|
111 | if (isExcluded(file.replace(/\\/g, '/'))) {
|
112 | return;
|
113 | }
|
114 | if (FS.statSync(file).isDirectory()) {
|
115 | FS.readdirSync(file).forEach(next => {
|
116 | add(Path.join(file, next));
|
117 | });
|
118 | }
|
119 | else if (supportedFileRegex.test(file)) {
|
120 | files.push(file);
|
121 | }
|
122 | }
|
123 | inputFiles.forEach(file => {
|
124 | add(Path.resolve(file));
|
125 | });
|
126 | return files;
|
127 | }
|
128 | toString() {
|
129 | return [
|
130 | '',
|
131 | 'TypeDoc ' + Application_1.VERSION,
|
132 | 'Using TypeScript ' + this.getTypeScriptVersion() + ' from ' + this.getTypeScriptPath(),
|
133 | ''
|
134 | ].join(typescript.sys.newLine);
|
135 | }
|
136 | };
|
137 | Application.VERSION = '0.15.0-0';
|
138 | __decorate([
|
139 | component_1.Option({
|
140 | name: 'logger',
|
141 | help: "Specify the logger that should be used, 'none' or 'console'",
|
142 | defaultValue: 'console',
|
143 | type: declaration_1.ParameterType.Mixed
|
144 | })
|
145 | ], Application.prototype, "loggerType", void 0);
|
146 | __decorate([
|
147 | component_1.Option({
|
148 | name: 'ignoreCompilerErrors',
|
149 | help: 'Should TypeDoc generate documentation pages even after the compiler has returned errors?',
|
150 | type: declaration_1.ParameterType.Boolean
|
151 | })
|
152 | ], Application.prototype, "ignoreCompilerErrors", void 0);
|
153 | __decorate([
|
154 | component_1.Option({
|
155 | name: 'exclude',
|
156 | help: 'Define patterns for excluded files when specifying paths.',
|
157 | type: declaration_1.ParameterType.Array
|
158 | })
|
159 | ], Application.prototype, "exclude", void 0);
|
160 | Application = Application_1 = __decorate([
|
161 | component_1.Component({ name: 'application', internal: true })
|
162 | ], Application);
|
163 | exports.Application = Application;
|
164 |
|
\ | No newline at end of file |