Skip to content

Commit

Permalink
add support for api-data.json file output (#1427)
Browse files Browse the repository at this point in the history
  • Loading branch information
gemal committed Aug 9, 2023
1 parent 4fd34e8 commit aae6fe9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bin/apidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ program

.option('-o, --output <output>', 'Output dirname.', 'doc/')

.option('--write-json', 'Will create api-data.json file with parsed API info.', false)

.option('--parse-filters <parse-filters...>', 'Optional user defined filters. Format name=filename', [])

.option('--parse-languages <parse-languages...>', 'Optional user defined languages. Format name=filename', [])
Expand Down Expand Up @@ -131,6 +133,7 @@ const options = {
filterBy: argv.filterBy,
logFormat: argv.logFormat,
warnError: argv.warnError,
writeJson: argv.writeJson,
};

if (options.debug) {
Expand Down
7 changes: 7 additions & 0 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class Writer {
this.log.verbose('Copying fonts to: ' + assetsPath);
this.fs.copySync(this.path.join(this.opt.template, 'fonts'), assetsPath);

// save the parsed api file
if (this.opt.writeJson) {
const jsonFile = this.path.join(assetsPath, 'api-data.json');
this.log.verbose('Saving parsed API to: ' + jsonFile);
this.fs.writeFileSync(jsonFile, this.api.data);
}

// CSS from dependencies
this.log.verbose('Copying bootstrap css to: ' + assetsPath);
this.fs.copySync(this.findAsset('bootstrap/dist/css/bootstrap.min.css'), this.path.join(assetsPath, 'bootstrap.min.css'));
Expand Down
3 changes: 2 additions & 1 deletion test/apidoc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ function testFullExample (config) {

// create
it('should create example in ' + outputPath, async function () {
const cmd = 'node ./bin/apidoc ' + (config ? '-c ' + config : '') + ' -i ' + 'example -o ' + outputPath + ' -q -d';
const cmd = 'node ./bin/apidoc ' + (config ? '-c ' + config : '') + ' --write-json -i ' + 'example -o ' + outputPath + ' -q -d';
const { stdout, stderr } = await exec(cmd);
}).timeout(80000);

// check we actually created output files
it('should find created files', done => {
const outputFiles = [
'assets/main.bundle.js',
'assets/api-data.json',
'index.html',
];

Expand Down

0 comments on commit aae6fe9

Please sign in to comment.