Skip to content

Commit 707b4f1

Browse files
lenovouserblakeembrey
authored andcommitted
Enable --gitRevision option (TypeStrong#474)
1 parent f70291e commit 707b4f1

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

Diff for: README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> Documentation generator for TypeScript projects.
44
5-
[![Build Status](https://travis-ci.org/TypeStrong/typedoc.svg?branch=master)](https://travis-ci.org/TypeStrong/typedoc)
5+
[![Build Status](https://travis-ci.org/TypeStrong/typedoc.svg?branch=master)](https://travis-ci.org/TypeStrong/typedoc)
66
[![NPM Version](https://badge.fury.io/js/typedoc.svg)](http://badge.fury.io/js/typedoc)
77
[![Chat on Gitter](https://badges.gitter.im/TypeStrong/typedoc.svg)](https://gitter.im/TypeStrong/typedoc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
88

@@ -62,7 +62,6 @@ in order to change the behaviour of TypeDoc.
6262
Prevent externally resolved TypeScript files from being documented.
6363
* `--excludePrivate`<br>
6464
Prevent private members from being included in the generated documentation.
65-
6665

6766
#### TypeScript compiler
6867
* `--module <commonjs, amd, system or umd>`<br>
@@ -86,6 +85,8 @@ in order to change the behaviour of TypeDoc.
8685
Set the site name for Google Analytics. Defaults to `auto`
8786
* `--entryPoint <fully.qualified.name>`<br>
8887
Specifies the fully qualified name of the root symbol. Defaults to global namespace.
88+
* `--gitRevision <revision|branch>`<br>
89+
Use specified revision or branch instead of the last revision for linking to GitHub source files.
8990

9091
#### Content
9192
* `--includes <path/to/includes>`<br>

Diff for: src/lib/converter/plugins/GitHubPlugin.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {Component, ConverterComponent} from '../components';
66
import {BasePath} from '../utils/base-path';
77
import {Converter} from '../converter';
88
import {Context} from '../context';
9+
import {Option} from '../../utils/component';
10+
import {ParameterType} from '../../utils/options/declaration';
911

1012
// This should be removed when @typings/shelljs typings are updated to the shelljs version being used
1113
declare module 'shelljs' {
@@ -30,7 +32,7 @@ class Repository {
3032
/**
3133
* The name of the branch this repository is on right now.
3234
*/
33-
branch = 'master';
35+
branch: string;
3436

3537
/**
3638
* A list of all files tracked by the repository.
@@ -52,8 +54,9 @@ class Repository {
5254
*
5355
* @param path The root path of the repository.
5456
*/
55-
constructor(path: string) {
57+
constructor(path: string, gitRevision: string) {
5658
this.path = path;
59+
this.branch = gitRevision || 'master';
5760
ShellJS.pushd(path);
5861

5962
let out = <ShellJS.ExecOutputReturnValue> ShellJS.exec('git ls-remote --get-url', {silent: true});
@@ -82,9 +85,11 @@ class Repository {
8285
});
8386
}
8487

85-
out = <ShellJS.ExecOutputReturnValue> ShellJS.exec('git rev-parse --short HEAD', {silent: true});
86-
if (out.code === 0) {
87-
this.branch = out.stdout.replace('\n', '');
88+
if (!gitRevision) {
89+
out = <ShellJS.ExecOutputReturnValue> ShellJS.exec('git rev-parse --short HEAD', {silent: true});
90+
if (out.code === 0) {
91+
this.branch = out.stdout.replace('\n', '');
92+
}
8893
}
8994

9095
ShellJS.popd();
@@ -130,15 +135,15 @@ class Repository {
130135
* @param path The potential repository root.
131136
* @returns A new instance of [[Repository]] or NULL.
132137
*/
133-
static tryCreateRepository(path: string): Repository {
138+
static tryCreateRepository(path: string, gitRevision: string): Repository {
134139
ShellJS.pushd(path);
135140
const out = <ShellJS.ExecOutputReturnValue> ShellJS.exec('git rev-parse --show-toplevel', {silent: true});
136141
ShellJS.popd();
137142

138143
if (out.code !== 0) {
139144
return null;
140145
}
141-
return new Repository(BasePath.normalize(out.stdout.replace('\n', '')));
146+
return new Repository(BasePath.normalize(out.stdout.replace('\n', '')), gitRevision);
142147
}
143148
}
144149

@@ -158,6 +163,13 @@ export class GitHubPlugin extends ConverterComponent {
158163
*/
159164
private ignoredPaths: string[] = [];
160165

166+
@Option({
167+
name: 'gitRevision',
168+
help: 'Use specified revision instead of the last revision for linking to GitHub source files.',
169+
type: ParameterType.String
170+
})
171+
gitRevision: string;
172+
161173
/**
162174
* Create a new GitHubHandler instance.
163175
*
@@ -196,7 +208,7 @@ export class GitHubPlugin extends ConverterComponent {
196208
}
197209

198210
// Try to create a new repository
199-
const repository = Repository.tryCreateRepository(dirName);
211+
const repository = Repository.tryCreateRepository(dirName, this.gitRevision);
200212
if (repository) {
201213
this.repositories[repository.path] = repository;
202214
return repository;

Diff for: src/lib/converter/types/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export {ArrayConverter} from './array';
33
export {BindingArrayConverter} from './binding-array';
44
export {BindingObjectConverter} from './binding-object';
55
export {EnumConverter} from './enum';
6-
export {IntrinsicConverter} from './intrinsic'
6+
export {IntrinsicConverter} from './intrinsic';
77
export {StringLiteralConverter} from './string-literal';
88
export {ReferenceConverter} from './reference';
99
export {ThisConverter} from './this';

Diff for: src/test/renderer/specs/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ <h4 id="theming">Theming</h4>
138138
Set the site name for Google Analytics. Defaults to <code>auto</code></li>
139139
<li><code>--entryPoint &lt;fully.qualified.name&gt;</code><br>
140140
Specifies the fully qualified name of the root symbol. Defaults to global namespace.</li>
141+
<li><code>--gitRevision &lt;revision|branch&gt;</code><br>
142+
Use specified revision or branch instead of the last revision for linking to GitHub source files.</li>
141143
</ul>
142144
<h4 id="content">Content</h4>
143145
<ul>

0 commit comments

Comments
 (0)