From 5b244357e0542122a2eea6fc51c09920d307e188 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Nov 2016 18:03:42 -0800 Subject: [PATCH] Add jsdoc readme and plugin --- scripts/jsdoc/.gitignore | 1 + scripts/jsdoc/README.md | 13 ++++++++++++ scripts/jsdoc/config.json | 8 +++++++ scripts/jsdoc/plugins/hifi.js | 40 +++++++++++++++++++++++++++++++++++ scripts/jsdoc/root.js | 11 ++++++++++ 5 files changed, 73 insertions(+) create mode 100644 scripts/jsdoc/.gitignore create mode 100644 scripts/jsdoc/README.md create mode 100644 scripts/jsdoc/config.json create mode 100644 scripts/jsdoc/plugins/hifi.js create mode 100644 scripts/jsdoc/root.js diff --git a/scripts/jsdoc/.gitignore b/scripts/jsdoc/.gitignore new file mode 100644 index 0000000000..c585e19389 --- /dev/null +++ b/scripts/jsdoc/.gitignore @@ -0,0 +1 @@ +out \ No newline at end of file diff --git a/scripts/jsdoc/README.md b/scripts/jsdoc/README.md new file mode 100644 index 0000000000..c43f95cabe --- /dev/null +++ b/scripts/jsdoc/README.md @@ -0,0 +1,13 @@ +#JavaScript Documentation Generation + +##Prerequisites + +* Install node.js +* Install jsdoc via npm. `npm install jsdoc -g` + +To generate html documentation for the High Fidelity JavaScript API + +`cd scripts/jsdoc` +`jsdoc . -c config.json` + +The out folder should contain index.html diff --git a/scripts/jsdoc/config.json b/scripts/jsdoc/config.json new file mode 100644 index 0000000000..0fb833d015 --- /dev/null +++ b/scripts/jsdoc/config.json @@ -0,0 +1,8 @@ +{ + "templates": { + "default": { + "outputSourceFiles": false + } + }, + "plugins": ["plugins/hifi"] +} diff --git a/scripts/jsdoc/plugins/hifi.js b/scripts/jsdoc/plugins/hifi.js new file mode 100644 index 0000000000..fde4183db8 --- /dev/null +++ b/scripts/jsdoc/plugins/hifi.js @@ -0,0 +1,40 @@ +function endsWith(path, exts) { + var result = false; + exts.forEach(function(ext) { + if (path.endsWith(ext)) { + result = true; + } + }); + return result; +} + +exports.handlers = { + beforeParse: function(e) { + console.log("Scanning hifi source for jsdoc comments..."); + + // directories to scan for jsdoc comments + var dirList = [ + '../../interface/src', + '../../libraries/script-engine/src', + '../../libraries/networking/src', + '../../libraries/animation/src' + ]; + var exts = ['.h', '.cpp']; + + const fs = require('fs'); + dirList.forEach(function (dir) { + var files = fs.readdirSync(dir) + files.forEach(function (file) { + var path = dir + "/" + file; + if (fs.lstatSync(path).isFile() && endsWith(path, exts)) { + var data = fs.readFileSync(path, "utf8"); + var reg = /(\/\*\*jsdoc(.|[\r\n])*?\*\/)/gm; + var matches = data.match(reg); + if (matches) { + e.source += matches.map(function (s) { return s.replace('/**jsdoc', '/**'); }).join('\n'); + } + } + }); + }); + } +}; diff --git a/scripts/jsdoc/root.js b/scripts/jsdoc/root.js new file mode 100644 index 0000000000..097403f723 --- /dev/null +++ b/scripts/jsdoc/root.js @@ -0,0 +1,11 @@ +// +// root.js +// +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Root of High Fidelity generated java script documentation +// +