mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +03:00
jsdoc: scripts for generating node.js documentation
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
7
doxy/node/generators/jsdoc/conf.json
Normal file
7
doxy/node/generators/jsdoc/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"templates": {
|
||||
"default": {
|
||||
"outputSourceFiles": false
|
||||
}
|
||||
}
|
||||
}
|
88
doxy/node/generators/jsdoc/generator.js
Normal file
88
doxy/node/generators/jsdoc/generator.js
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate JSDoc-style documentation
|
||||
function generateDocs(specjs) {
|
||||
var docs = GENERATE_MODULE(specjs.MODULE);
|
||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.CLASSES, function(memo, classSpec, parentClass) {
|
||||
return _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec, parentClass);
|
||||
}, memo);
|
||||
}, docs);
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// comment wrapper around entire spec
|
||||
function GENERATE_DOC(text) {
|
||||
return '/**\n' + text + ' */\n';
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(module) {
|
||||
return GENERATE_DOC('@module ' + module + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate method spec with parent module/class
|
||||
function GENERATE_METHOD(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@method ' + name + '\n'
|
||||
+ '@instance\n'
|
||||
+ (parent ? ('@memberof ' + parent + '\n') : '')
|
||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
||||
return '@param {' + paramSpec.type + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
||||
}, '')
|
||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + spec.return.type + '} ' + spec.return.description + '\n') : ''));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec) {
|
||||
return GENERATE_DOC(spec.description + '\n\n'
|
||||
+ '@var ' + name + '\n'
|
||||
+ '@type Enum(' + spec.type + ')\n'
|
||||
+ '@instance\n');
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
// generate link spec
|
||||
function GENERATE_LINK(text) {
|
||||
return '{@link ' + text + '}';
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
110
doxy/node/generators/ternjs/generator.js
Normal file
110
doxy/node/generators/ternjs/generator.js
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate json for ternjs input
|
||||
function generateDocs(specjs) {
|
||||
var docs = GENERATE_MODULE(specjs.MODULE);
|
||||
GENERATE_TYPE = (function(enums) {
|
||||
return function(type) {
|
||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
||||
}
|
||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
||||
_.each(specjs.ENUMS, function(enumSpec, enumName) {
|
||||
_.extend(docs[specjs.MODULE], GENERATE_ENUM(enumName, enumSpec));
|
||||
});
|
||||
_.each(specjs.METHODS, function(methodSpec, methodName) {
|
||||
_.extend(docs[specjs.MODULE], GENERATE_METHOD(methodName, methodSpec));
|
||||
});
|
||||
_.each(specjs.CLASSES, function(classSpec, parentClass) {
|
||||
var constructor = classSpec.methods[parentClass];
|
||||
_.extend(docs[specjs.MODULE], GENERATE_METHOD(parentClass, constructor ? constructor : { params: {}, return: {}, description: '' } ));
|
||||
_.each(classSpec.enums, function(enumSpec, enumName) {
|
||||
_.extend(docs[specjs.MODULE][parentClass], GENERATE_ENUM(enumName, enumSpec));
|
||||
});
|
||||
docs[specjs.MODULE][parentClass].prototype = {};
|
||||
_.each(_.omit(classSpec.methods, parentClass), function(methodSpec, methodName) {
|
||||
_.extend(docs[specjs.MODULE][parentClass].prototype, GENERATE_METHOD(methodName, methodSpec));
|
||||
});
|
||||
_.each(classSpec.variables, function(variableSpec, variableName) {
|
||||
_.extend(docs[specjs.MODULE][parentClass].prototype, GENERATE_VARIABLE(variableName, variableSpec));
|
||||
});
|
||||
});
|
||||
return JSON.stringify(docs, null, 2);
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(module) {
|
||||
var docs = { '!name': module + 'library' };
|
||||
docs[module] = {};
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
// generate method spec
|
||||
function GENERATE_METHOD(name, spec) {
|
||||
var doc = {};
|
||||
doc[name] = {
|
||||
'!type': 'fn(' + GENERATE_PARAMS(spec.params) + ')' + GENERATE_RETURN(spec.return),
|
||||
'!doc': spec.description
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
// generate parameter signatures for method
|
||||
function GENERATE_PARAMS(spec) {
|
||||
return _.map(spec, function(paramSpec, paramName) {
|
||||
return paramName + ': ' + paramSpec.type;
|
||||
}).join(', ');
|
||||
}
|
||||
|
||||
|
||||
// generate return signature for method
|
||||
function GENERATE_RETURN(spec) {
|
||||
return (_.isEmpty(spec) ? '' : (' -> ' + spec.type));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec) {
|
||||
var doc = {};
|
||||
doc[name] = 'Enum ' + spec.type ;
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
// generate variable spec
|
||||
function GENERATE_VARIABLE(name, spec) {
|
||||
var doc = {};
|
||||
doc[name]= spec.type ;
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
8
doxy/node/generators/yuidoc/conf.json
Normal file
8
doxy/node/generators/yuidoc/conf.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "UPM",
|
||||
"description": "The UPM API: High Level Sensor Library for Intel IoT Devices Using MRAA",
|
||||
"logo": "http://upload.wikimedia.org/wikipedia/commons/8/8c/Transparent.png",
|
||||
"options": {
|
||||
"outdir": "./html/node"
|
||||
}
|
||||
}
|
117
doxy/node/generators/yuidoc/generator.js
vendored
Normal file
117
doxy/node/generators/yuidoc/generator.js
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Author: Heidi Pan <heidi.pan@intel.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// dependencies
|
||||
var _ = require('lodash');
|
||||
|
||||
|
||||
// generate YuiDocs-style documentation
|
||||
function generateDocs(specjs) {
|
||||
var docs = GENERATE_MODULE(specjs.MODULE);
|
||||
GENERATE_TYPE = (function(enums) {
|
||||
return function(type) {
|
||||
return (_.contains(enums, type) ? ('Enum ' + type) : type);
|
||||
}
|
||||
})(_.keys(specjs.ENUMS_BY_GROUP));
|
||||
docs = _.reduce(specjs.METHODS, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.ENUMS, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec);
|
||||
}, docs);
|
||||
docs = _.reduce(specjs.CLASSES, function(memo, classSpec, parentClass) {
|
||||
return memo
|
||||
+ GENERATE_CLASS(parentClass, classSpec.description)
|
||||
+ _.reduce(classSpec.methods, function(memo, methodSpec, methodName) {
|
||||
return memo += GENERATE_METHOD(methodName, methodSpec, parentClass);
|
||||
}, '')
|
||||
+ _.reduce(classSpec.variables, function(memo, variableSpec, variableName) {
|
||||
return memo += GENERATE_VAR(variableName, variableSpec, parentClass);
|
||||
}, '')
|
||||
+ _.reduce(classSpec.enums, function(memo, enumSpec, enumName) {
|
||||
return memo += GENERATE_ENUM(enumName, enumSpec, parentClass);
|
||||
}, '');
|
||||
}, docs);
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// comment wrapper around entire spec
|
||||
function GENERATE_DOC(text) {
|
||||
return '/**\n' + text + ' */\n';
|
||||
}
|
||||
|
||||
|
||||
// generate module spec
|
||||
function GENERATE_MODULE(module) {
|
||||
return GENERATE_DOC('@module ' + module + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate class spec
|
||||
function GENERATE_CLASS(name, description) {
|
||||
return GENERATE_DOC(description + '\n'
|
||||
+ '@class ' + name + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate method spec with parent module/class
|
||||
function GENERATE_METHOD(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@method ' + name + '\n'
|
||||
+ (parent ? ('@for ' + parent + '\n') : '@for common\n')
|
||||
+ _.reduce(spec.params, function(memo, paramSpec, paramName) {
|
||||
return memo + '@param {' + GENERATE_TYPE(paramSpec.type) + '} ' + paramName + ' ' + paramSpec.description + '\n';
|
||||
}, '')
|
||||
+ ( !_.isEmpty(spec.return) ? ('@return {' + GENERATE_TYPE(spec.return.type) + '} ' + spec.return.description + '\n') : ''));
|
||||
}
|
||||
|
||||
|
||||
// generate enum spec
|
||||
function GENERATE_ENUM(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@property ' + name + '\n'
|
||||
+ '@type Enum ' + spec.type + '\n'
|
||||
+ '@for ' + (parent ? parent : 'common') + '\n');
|
||||
}
|
||||
|
||||
|
||||
// generate variable specs
|
||||
function GENERATE_VAR(name, spec, parent) {
|
||||
return GENERATE_DOC(spec.description + '\n'
|
||||
+ '@property ' + name + '\n'
|
||||
+ '@type ' + spec.type + '\n'
|
||||
+ '@for ' + parent + '\n');
|
||||
}
|
||||
|
||||
|
||||
// TODO
|
||||
// generate link spec
|
||||
function GENERATE_LINK(text) {
|
||||
return '{{#crossLink "' + text + '"}}{{/crossLink}}';
|
||||
}
|
||||
|
||||
|
||||
module.exports = generateDocs;
|
Reference in New Issue
Block a user