js doc composer for interop with visual paradigm
This commit is contained in:
@@ -0,0 +1,7 @@
|
|||||||
|
call jsdoc ../backend/app/App.js -t "./diagram-template/" -d "./out/App.h"
|
||||||
|
call jsdoc ../backend/app/Config.js -t "./diagram-template/" -d "./out/Config.h"
|
||||||
|
call jsdoc ../backend/app/Db.js -t "./diagram-template/" -d "./out/Db.h"
|
||||||
|
call jsdoc ../backend/app/bl/GamesManager.js -t "./diagram-template/" -d "./out/bl/GamesManager.h"
|
||||||
|
call jsdoc ../backend/app/bl/RulesManager.js -t "./diagram-template/" -d "./out/bl/RulesManager.h"
|
||||||
|
call jsdoc ../backend/app/bl/GameObjectsManager.js -t "./diagram-template/" -d "./out/bl/GameObjectsManager.h"
|
||||||
|
call jsdoc ../backend/app/bl/ScenariosManager.js -t "./diagram-template/" -d "./out/bl/ScenariosManager.h"
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,13 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
const typeMap = {
|
||||||
|
string: 'std::string',
|
||||||
|
Number: 'int'
|
||||||
|
}
|
||||||
|
|
||||||
function getType(t){
|
function getType(t){
|
||||||
return (t?.type.names[0] || '').replace(/^Array\.\<(.*)\>$/, '$1*')
|
let tp = (t?.type?.names[0] || '').replace(/^Array\.\<(.*)\>$/, '$1*')
|
||||||
|
return typeMap[tp] || tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function graft(childNodes, parentLongname) {
|
function graft(childNodes, parentLongname) {
|
||||||
@@ -9,12 +15,12 @@ function graft(childNodes, parentLongname) {
|
|||||||
childNodes.filter(({memberof}) => memberof === parentLongname)
|
childNodes.filter(({memberof}) => memberof === parentLongname)
|
||||||
.forEach(element => {
|
.forEach(element => {
|
||||||
if (element.kind === 'function') {
|
if (element.kind === 'function') {
|
||||||
result += `${getType(element.returns?.[0]) || 'void'} ${element.name}(${ element.params?.map(p=>
|
result += `/* ${element.description} */ ${getType(element.returns?.[0]) || 'void'} ${element.name}(${ element.params?.map(p=>
|
||||||
`/* ${p.description || ''} */ ${getType(p)} ${p.name}`
|
`/* ${p.description || ''} */ ${getType(p)} ${p.name}`
|
||||||
).join(', ') || ''});\n`;
|
).join(', ') || ''});\n`;
|
||||||
}
|
}
|
||||||
else if (element.kind === 'member') {
|
else if (element.kind === 'member') {
|
||||||
result += `/* ${element.description || ''} */ ${getType(element)} ${element.name};`
|
result += ` /* ${element.description || ''} */ ${getType(element)} ${element.name};\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (element.kind === 'class') {
|
else if (element.kind === 'class') {
|
||||||
@@ -36,20 +42,9 @@ exports.publish = (data, {destination, query}) => {
|
|||||||
data({undocumented: true}).remove();
|
data({undocumented: true}).remove();
|
||||||
docs = data().get(); // <-- an array of Doclet objects
|
docs = data().get(); // <-- an array of Doclet objects
|
||||||
|
|
||||||
fs.promises.writeFile('./result.json', JSON.stringify(docs), {encoding:'utf-8'})
|
fs.promises.writeFile(destination+'.json', JSON.stringify(docs, null, 2), {encoding:'utf-8'})
|
||||||
|
|
||||||
let result = graft(docs);
|
let result = `#include <string>\n\n` + graft(docs);
|
||||||
console.log(result)
|
//console.log(result)
|
||||||
|
fs.promises.writeFile(destination, result, {encoding:'utf-8'});
|
||||||
if (destination === 'console') {
|
|
||||||
if (query && query.format === 'xml') {
|
|
||||||
//console.log( xml.parse('xs:schema', root) );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//console.log( require('jsdoc/util/dumper').dump(root) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log('This template only supports output to the console. Use the option "-d console" when you run JSDoc.');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
node_modules
|
node_modules
|
||||||
/dist
|
/dist
|
||||||
/out
|
/out
|
||||||
|
.docs/out/
|
||||||
/repo
|
/repo
|
||||||
|
|
||||||
#temporary:
|
#temporary:
|
||||||
|
|||||||
@@ -1,19 +1,33 @@
|
|||||||
import path, { dirname } from 'path';
|
import path, { dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main backend application
|
||||||
|
*/
|
||||||
class App{
|
class App{
|
||||||
constructor(){
|
constructor(){
|
||||||
this.root = path.resolve(dirname(fileURLToPath(import.meta.url)) + '/../../');
|
this.root = path.resolve(dirname(fileURLToPath(import.meta.url)) + '/../../');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The plugins used by the application
|
||||||
|
* @type {AppPlugin[]}
|
||||||
|
*/
|
||||||
plugins = [];
|
plugins = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declaration of plugin usage
|
||||||
|
* @param {AppPlugin} plugin The plugin to be used
|
||||||
|
*/
|
||||||
async use(plugin){
|
async use(plugin){
|
||||||
this[plugin.name] = plugin;
|
this[plugin.name] = plugin;
|
||||||
plugin.app = this;
|
plugin.app = this;
|
||||||
this.plugins.push(plugin);
|
this.plugins.push(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the application. All plugins are initialized at this stage
|
||||||
|
*/
|
||||||
async init(){
|
async init(){
|
||||||
for (let p of this.plugins){
|
for (let p of this.plugins){
|
||||||
console.debug('Initializing', p.name)
|
console.debug('Initializing', p.name)
|
||||||
@@ -21,6 +35,10 @@ class App{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports modules as plugins in the app by a given list
|
||||||
|
* @param {Array} modules Modules to be imported
|
||||||
|
*/
|
||||||
async importModules(modules){
|
async importModules(modules){
|
||||||
const mods = {};
|
const mods = {};
|
||||||
for (let m of modules){
|
for (let m of modules){
|
||||||
@@ -32,6 +50,10 @@ class App{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces a plugin
|
||||||
|
* @param {AppPlugin} p Plugin to be replaced
|
||||||
|
*/
|
||||||
async replace(p){
|
async replace(p){
|
||||||
let old = this[p.name];
|
let old = this[p.name];
|
||||||
this.plugins[this.plugins.indexOf(old)] = p;
|
this.plugins[this.plugins.indexOf(old)] = p;
|
||||||
@@ -40,6 +62,9 @@ class App{
|
|||||||
if(p.init) await p.init(this);
|
if(p.init) await p.init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the application. All Plugins are started at this point
|
||||||
|
*/
|
||||||
async start(){
|
async start(){
|
||||||
for (let p of this.plugins){
|
for (let p of this.plugins){
|
||||||
console.debug('Starting', p.name)
|
console.debug('Starting', p.name)
|
||||||
|
|||||||
+25
-1
@@ -1,4 +1,8 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration class
|
||||||
|
*/
|
||||||
class Config{
|
class Config{
|
||||||
name = 'config';
|
name = 'config';
|
||||||
|
|
||||||
@@ -9,15 +13,35 @@ class Config{
|
|||||||
name:'pronature',
|
name:'pronature',
|
||||||
url: "mongodb://127.0.0.1:27017/pronature"
|
url: "mongodb://127.0.0.1:27017/pronature"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class web site options
|
||||||
|
* @alias SiteOptions
|
||||||
|
* @memberof Config
|
||||||
|
*/
|
||||||
site = {
|
site = {
|
||||||
|
/** Host name
|
||||||
|
* @type {string}
|
||||||
|
* @memberof SiteOptions
|
||||||
|
*/
|
||||||
host:'https://localhost:5173',
|
host:'https://localhost:5173',
|
||||||
ssl: true,
|
ssl: true,
|
||||||
port: 3000,
|
port: 3000,
|
||||||
|
/**
|
||||||
|
* @class certificate data
|
||||||
|
* @alias CertificateOptions
|
||||||
|
* @memberof SiteOptions
|
||||||
|
*/
|
||||||
certificate: {
|
certificate: {
|
||||||
|
/**
|
||||||
|
* Certificate key
|
||||||
|
* @type {string}
|
||||||
|
* @memberof CertificateOptions
|
||||||
|
*/
|
||||||
key: './.cert/dev-key.pem',
|
key: './.cert/dev-key.pem',
|
||||||
cert: './.cert/dev-cert.pem',
|
cert: './.cert/dev-cert.pem',
|
||||||
passphrase: 'parola'
|
passphrase: 'parola'
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
am = {
|
am = {
|
||||||
salt : 'P@ssSal7y!!',
|
salt : 'P@ssSal7y!!',
|
||||||
|
|||||||
+3
-3
@@ -30,7 +30,7 @@ class Db {
|
|||||||
* Inserts a record in a db collection
|
* Inserts a record in a db collection
|
||||||
* @param {string} collection The name of the collection
|
* @param {string} collection The name of the collection
|
||||||
* @param {Object} value The object to insert
|
* @param {Object} value The object to insert
|
||||||
* @returns Inserted Id
|
* @returns {ObjectId} Inserted Id
|
||||||
*/
|
*/
|
||||||
async create(collection, value){
|
async create(collection, value){
|
||||||
try {
|
try {
|
||||||
@@ -45,7 +45,7 @@ class Db {
|
|||||||
* @param {string} collection The name of the collection
|
* @param {string} collection The name of the collection
|
||||||
* @param {Object} key Record identifier
|
* @param {Object} key Record identifier
|
||||||
* @param {Object} projection What data to take from the object
|
* @param {Object} projection What data to take from the object
|
||||||
* @returns A record
|
* @returns {Object} A record
|
||||||
*/
|
*/
|
||||||
async get(collection, key, projection){
|
async get(collection, key, projection){
|
||||||
try {
|
try {
|
||||||
@@ -59,7 +59,7 @@ class Db {
|
|||||||
* Performs a database query
|
* Performs a database query
|
||||||
* @param {string} collection Collection name
|
* @param {string} collection Collection name
|
||||||
* @param {Object} query A mongo db query
|
* @param {Object} query A mongo db query
|
||||||
* @returns Array of records
|
* @returns {Object[]} Array of records
|
||||||
*/
|
*/
|
||||||
async list(collection, query){
|
async list(collection, query){
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class GamesManager{
|
|||||||
/**
|
/**
|
||||||
* Reads game definition by ID
|
* Reads game definition by ID
|
||||||
* @param {Number} id game ID
|
* @param {Number} id game ID
|
||||||
* @returns {Game}
|
* @returns {Game} the game
|
||||||
*/
|
*/
|
||||||
this.read = async function(id){
|
this.read = async function(id){
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ class GamesManager{
|
|||||||
/**
|
/**
|
||||||
* Returns a set of games by given criteria
|
* Returns a set of games by given criteria
|
||||||
* @param {Query} query criteria
|
* @param {Query} query criteria
|
||||||
* @returns {Game[]}
|
* @returns {Game[]} Array of games
|
||||||
*/
|
*/
|
||||||
this.list = async function(query){
|
this.list = async function(query){
|
||||||
|
|
||||||
@@ -73,18 +73,15 @@ class GamesManager{
|
|||||||
class Game {
|
class Game {
|
||||||
/**
|
/**
|
||||||
* Game name
|
* Game name
|
||||||
* @type string
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
name = null;
|
name = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game formal description
|
* Game formal description
|
||||||
* @type GameDefinition
|
* @type {GameDefinition}
|
||||||
*/
|
*/
|
||||||
definition = {
|
definition = {
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
levels:[
|
levels:[
|
||||||
{
|
{
|
||||||
name: 'Level 1',
|
name: 'Level 1',
|
||||||
|
|||||||
@@ -73,10 +73,114 @@ class ScenariosManager{
|
|||||||
class Scenario {
|
class Scenario {
|
||||||
/**
|
/**
|
||||||
* Scenario name
|
* Scenario name
|
||||||
* @type string
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
name = null;
|
name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario levels
|
||||||
|
* @type {Level[]}
|
||||||
|
*/
|
||||||
|
levels = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game scenario level
|
||||||
|
*/
|
||||||
|
class Level {
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Active objects
|
||||||
|
* @type {LevelObject[]}
|
||||||
|
*/
|
||||||
|
activeObjects = []
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Game object associated to a level
|
||||||
|
*/
|
||||||
|
class LevelObject {
|
||||||
|
/**
|
||||||
|
* Associated game object
|
||||||
|
* @type {GameObject}
|
||||||
|
*/
|
||||||
|
gameObject = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available actions
|
||||||
|
* @type {GameAction}
|
||||||
|
*/
|
||||||
|
actions = []
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action associated to game object
|
||||||
|
*/
|
||||||
|
class GameAction {
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
description = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associated inventory item
|
||||||
|
* @type {InventoryItem}
|
||||||
|
*/
|
||||||
|
inventoryItem = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Available outcomes from the action
|
||||||
|
* @type {GameActionResult}
|
||||||
|
*/
|
||||||
|
results = []
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result associated to game action
|
||||||
|
*/
|
||||||
|
class GameActionResult{
|
||||||
|
pointsRuleDefinition = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
description = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inventory item required to perform specific action
|
||||||
|
*/
|
||||||
|
class InventoryItem {
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
name = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scenario name
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
description = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ScenariosManager }
|
export { ScenariosManager }
|
||||||
Reference in New Issue
Block a user