Skip to content

Commit 730a4a5

Browse files
committed
fix: fixup tests
1 parent 53be3c2 commit 730a4a5

File tree

21 files changed

+3572
-606
lines changed

21 files changed

+3572
-606
lines changed

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"name": "documenter",
2+
"name": "@denali-js/documenter",
33
"version": "1.0.0",
44
"description": "Generate docs data from a Javascript or Typescript project",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc",
9-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"build": "npm run clean && tsc",
9+
"clean": "rm -rf dist",
10+
"test": "ava"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -19,23 +20,23 @@
1920
},
2021
"homepage": "https://github.com/denali-js/documenter#readme",
2122
"devDependencies": {
22-
"tslint": "^5.7.0",
23-
"typescript": "^2.4.2"
23+
"ava": "^0.25.0",
24+
"tslint": "^5.9.1",
25+
"typescript": "^2.7.1"
2426
},
2527
"dependencies": {
2628
"@types/debug": "^0.0.30",
27-
"@types/glob": "^5.0.32",
28-
"@types/lodash": "^4.14.74",
29-
"@types/node": "^8.0.26",
29+
"@types/glob": "^5.0.35",
30+
"@types/lodash": "^4.14.102",
31+
"@types/node": "^8.9.1",
3032
"@types/tmp": "^0.0.33",
3133
"broccoli-plugin": "^1.3.0",
32-
"debug": "^3.0.1",
34+
"debug": "^3.1.0",
3335
"glob": "^7.1.2",
34-
"lodash": "^4.17.4",
35-
"read-pkg": "^2.0.0",
36-
"require-dir": "^0.3.2",
36+
"lodash": "^4.17.5",
37+
"read-pkg": "^3.0.0",
3738
"tmp": "^0.0.33",
38-
"typedoc": "^0.8.0",
39+
"typedoc": "^0.10.0",
3940
"walk-sync": "^0.3.2",
4041
"yuidocjs": "^0.10.2"
4142
}

src/extracter.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import * as path from 'path';
22
import { existsSync as exists, readFileSync as read } from 'fs';
33
import { defaults, Dictionary } from 'lodash';
44
import * as walk from 'walk-sync';
5-
import * as requireDir from 'require-dir';
65
import { sync as glob } from 'glob';
76
import API from './api';
7+
import TypescriptSourceExtracter from './source-extracters/typescript';
8+
import JavascriptSourceExtracter from './source-extracters/javascript';
89
import * as createDebug from 'debug';
910

1011
const debug = createDebug('documenter:extracter');
11-
const extractersDir = path.join(__dirname, 'extracters');
12+
const sourceExtracters = {
13+
'typescript': TypescriptSourceExtracter,
14+
'javascript': JavascriptSourceExtracter
15+
};
1216

1317
export interface ExtracterOptions {
1418
/**
@@ -76,12 +80,24 @@ export default class Extracter {
7680
*/
7781
sourceDirs: string[];
7882

79-
extracters = <Dictionary<{ default: ExtracterMethod }>>requireDir(extractersDir);
80-
8183
constructor(options: ExtracterOptions) {
8284
defaults(options, this.defaultOptions(options.dir));
8385
debug(`Configuring for ${ options.dir }`);
84-
Object.assign(this, options);
86+
this.dir = options.dir;
87+
this.pagesDir = options.pagesDir || 'docs';
88+
this.sourceDirs = options.sourceDirs || [ 'src' ];
89+
this.projectName = options.projectName;
90+
this.projectVersion = options.projectVersion;
91+
92+
if (!path.isAbsolute(this.pagesDir)) {
93+
this.pagesDir = path.join(this.dir, this.pagesDir);
94+
}
95+
this.sourceDirs = this.sourceDirs.map((d) => {
96+
if (!path.isAbsolute(d)) {
97+
return path.join(this.dir, d);
98+
}
99+
return d;
100+
});
85101
}
86102

87103
/**
@@ -118,10 +134,11 @@ export default class Extracter {
118134
if (!sourceType) {
119135
throw new Error('Cannot extract API docs from this directory: unknown source type. Source must be Typescript or JavaScript');
120136
}
121-
return this.extracters[sourceType].default.call(null, this);
137+
let sourceExtracter = new sourceExtracters[sourceType](this);
138+
return sourceExtracter.extract();
122139
}
123140

124-
detectSourceType(): string | null {
141+
detectSourceType(): 'typescript' | 'javascript' | null {
125142
// Typescript
126143
if (exists(path.join(this.dir, 'tsconfig.json'))) {
127144
return 'typescript';

src/extracters/javascript.ts

Lines changed: 0 additions & 211 deletions
This file was deleted.

0 commit comments

Comments
 (0)