Skip to content

Commit f11bb50

Browse files
committed
fix: allow for non-existent pages directory
1 parent 61e6957 commit f11bb50

File tree

4 files changed

+90
-6
lines changed

4 files changed

+90
-6
lines changed

src/extracter.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@ export default class Extracter {
119119
extractPages(): Dictionary<string> {
120120
let dir = this.pagesDir;
121121
debug(`Extracting pages for ${ this.dir } from ${ dir }`);
122-
let files = walk(dir, { directories: false });
123-
return files.reduce((pages: Dictionary<string>, file: string) => {
124-
debug(`Found a page: ${ file }`);
125-
pages[file] = read(path.join(dir, file), 'utf-8');
126-
return pages;
127-
}, <Dictionary<string>>{});
122+
if (exists(dir)) {
123+
let files = walk(dir, { directories: false });
124+
return files.reduce((pages: Dictionary<string>, file: string) => {
125+
debug(`Found a page: ${ file }`);
126+
pages[file] = read(path.join(dir, file), 'utf-8');
127+
return pages;
128+
}, <Dictionary<string>>{});
129+
}
130+
return {};
128131
}
129132

130133
extractApi(): API {

test/base.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import test from 'ava';
2+
import * as path from 'path';
3+
import { Extracter } from '../dist/index';
4+
import output from './helpers/output-expectation';
5+
6+
test('allow non-existent pages directory', async (t) => {
7+
let extracter = new Extracter({
8+
dir: path.join(__dirname, 'fixtures', 'missing-pages-dir'),
9+
pagesDir: 'guides',
10+
sourceDirs: [ 'src' ],
11+
projectName: 'javascript-project',
12+
projectVersion: '1.0.0'
13+
});
14+
let result = extracter.extract();
15+
t.deepEqual(result, Object.assign(output('js'), { pages: {} }));
16+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* He's such a good boi!
3+
*
4+
* No srsly. such good
5+
*
6+
* @class Dog
7+
* @constructor
8+
*/
9+
export default class Dog {
10+
11+
/**
12+
* What's the dog's current mood?
13+
*
14+
* @property mood
15+
* @type string
16+
*/
17+
mood = 'happy';
18+
19+
/**
20+
* Make some noise
21+
*
22+
* @method bark
23+
* @param volume {number} How loud?
24+
* @public
25+
* @foo bar
26+
*/
27+
bark(volume) {
28+
29+
}
30+
31+
/**
32+
* Checks if this.goodBoi is true, and if so, requests a belly rub.
33+
* Returns true if belly rub was successful.
34+
*
35+
* @method requestBellyRub
36+
* @returns {boolean} Was the belly rub successful?
37+
* @protected
38+
*/
39+
requestBellyRub() {
40+
41+
}
42+
43+
// Custom tags, private
44+
/**
45+
* Digs a hole in blankets or dirt
46+
*
47+
* @method burrow
48+
* @isGoodBoi true
49+
* @private
50+
*/
51+
burrow() {
52+
53+
}
54+
55+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Free function
2+
/**
3+
* Pet the good boi!
4+
*
5+
* @method pet
6+
* @public
7+
*/
8+
export function pet() {
9+
10+
}

0 commit comments

Comments
 (0)