Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions src/generator/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import * as fs from 'fs';
import * as nunjucks from 'nunjucks';
import * as path from 'path';
import {promisify} from 'util';
import Q from 'p-queue';

const rootPath = path.join(__dirname, '../../..');
const srcPath = path.join(rootPath, 'src');
Expand All @@ -35,11 +34,11 @@ export const gfs = {
};

/**
* Iterate over each API directory, and use the `compodoc` tool to generate
* reference API documentation in the `docs` folder. This folder is ignored
* in git, so a publish must be done with `npm run publish-docs`.
* Generate reference documentation for all built APIs with JSDoc in the
* `docs` folder. This folder is ignored in git, so a publish must be done with
* `npm run publish-docs`.
*
* To use this, run `npm run generate-docs`.
* To use this, run `npm run docs`.
*/
export async function main() {
if (!gfs.exists(docsPath)) {
Expand All @@ -51,25 +50,13 @@ export async function main() {
});
const contents = nunjucks.render(templatePath, {apis: dirs});
await gfs.writeFile(indexPath, contents);
const q = new Q({concurrency: 10});
console.log(`Generating docs for ${dirs.length} APIs...`);
let i = 0;
const promises = dirs.map(dir => {
return q
.add(() =>
gfs.execa(process.execPath, [
'--max-old-space-size=4096',
'./node_modules/.bin/jsdoc',
'-c',
'.jsdoc.js',
]),
)
.then(() => {
i++;
console.log(`[${i}/${dirs.length}] ${dir}`);
});
});
await Promise.all(promises);
await gfs.execa(process.execPath, [
'--max-old-space-size=4096',
'./node_modules/.bin/jsdoc',
'-c',
'.jsdoc.js',
]);
}

if (require.main === module) {
Expand Down
12 changes: 11 additions & 1 deletion test/test.docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ describe(__filename, () => {
afterEach(() => sandbox.restore());

it('should generate docs', async () => {
sandbox.stub(docs.gfs, 'exists').returns(true);
const writeStub = sandbox.stub(docs.gfs, 'writeFile').resolves();
const execStub = sandbox.stub(docs.gfs, 'execa').resolves();
await docs.main();
assert.ok(writeStub.called);
assert.ok(execStub);
assert.strictEqual(execStub.callCount, 1);
assert.deepStrictEqual(execStub.firstCall.args, [
process.execPath,
[
'--max-old-space-size=4096',
'./node_modules/.bin/jsdoc',
'-c',
'.jsdoc.js',
],
]);
});
});
Loading