JSPM

  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q25648F
  • License MIT

The repository supports the NPM build process based on UML models created and managed with the JSONEditor4Code. A JSON file defines the attributes and methods of a class and a JSON editor running in a browser allows the generation of Javascript code. In turn any alteration of the code in the folder src/ of the main Javascript code will update the UML model in the folder jscc/.

Package Exports

  • build4code

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (build4code) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build4Code

The repository supports the NPM build process based on UML models created and managed with the JSONEditor4Code. A JSON file defines the attributes and methods of a class and a JSON editor running in a browser allows the generation of Javascript code.

JavaScript to UML Converter

The JavaScript to UML converter is part of the build2code repository. It is used to create UML model of a Javascript constructor. See ClassEditorUML how the generated JSON file can be used in an UML Editor for Javascript sources.

Input Parameters of js2uml

js2uml uses the prototype definition of methods, i.e. for a Javascript class LoadFile4DOM for extracting the code and parameters of the call for a function and stores the extract information in JSON file to represent the UML structure of the JavaScript class. The prototype-methods are defined in the following way.

function LoadFile4DOM () {
  // Constructor called with new LoadFile4DOM()
  // ...
}

LoadFile4DOM.prototype.my_method = function (pPar1,pPar2) {
  // code for the method "mymethod"
}

The function js2uml() needs the following input parameters.

  • (pUML) a JSON for a the Javascript class that represents the previous representation of UML (e.g. loadfile4dom_uml.json). The JSON pUML is usually generated with ClassEditorUML. The previous UML definition of the class will be updated by js2uml() (e.g. code bodies and parameters of methods are updated from the source Javascript file e.g. loadfile4dom.js). Bugfixing of the code is usually performed in an editor like Atom and the general structure of a Javascript class during software design is done in an UML editor. js2uml() will use from the input UML file to take previously defined comments for
    • attributes,
    • methods and
    • parameters of methods (functions) maps those comments to the parsed UML structure.
  • (pConstructor) as a reference to the defined attributes of constructor (e.g. pConstructor=LoadFile4DOM).
  • (pOptions) defines thei options for parsing
  • (pkg) the required JSON package.json. You can call the js2uml() within a build script for code generation with the following commands.
const pkg = require('./package.json')
const b4c = require('build4code');
let js2uml = b4c.js2uml;

let vConstructor = require('loadfile4dom');
let vOptions = {
  "constructor":true,
  "scan_prototype":true
};

var vUML = b4c.js2uml(pUML,vConstructor,pOptions,pkg);

vOption.scan_prototype = true uses the reference to LoadFile4DOM.prototype for scanning all as prototypes defined methods of LoadFile4DOM constructor. Methods might be also defined within the constructor e.g. with:

function LoadFile4DOM () {
  this.my_attribute1 = 0.0;
  this.my_method1 = function (pPar1,pPar2) {
    // code of my_method1 ...
  }
}
LoadFile4DOM.prototype.my_method2 = function (pPar1,pPar2) {
  // code of my_method2 ...  
}

my_method2() is defined as prototype, while my_method1() will consume memory for the methods any create instances of LoadFile4DOM created with new LoadFile4DOM(). If no methods are defined as prototype set the options to false even if you use a constructor, i.e.

let vOptions = {
 "constructor":true,
 "scan_prototype":false
}

The constructor could also be also just a hash of functions.

const pkg = require('./package.json')
const b4c = require('build4code');
let js2uml = b4c.js2uml;
let vOptions = {
  "constructor":false,
  "scan_prototype":false,
  "include_overwrite": [
    "my_method1",
    "my_method2"
  ]
};

let vHash = {
  "my_attribute1": 0.0,
  "my_method1": function (pPar1,pPar2) {
    // code of my_method1 ...
  }
};

 var vUML = b4c.js2uml(vUML,vHash,vOptions,pkg);

An example for such as static class is Handlebars. You can use the template engine Handlebars just with require command an without creating a new instance with new Handlebars(). Nevertheless the document can be parsed and converted in the UML model as "static class" in Javascript.

If we extend the Handelbars module to Handlebars4Code, it is necessary to scan the static super class Handelbars and the Handlebars4Code static class so that only the new defined methods and attributes are displayed in the UML export for hash2uml().

Currently the include_overwrite array lists all functions in Handelbars that will be overwritten in Handlebars4Code. The listed methods will in the include_overwrite array will be included in the UML export. The options is currently necessary because there is no solution yet to identify if a function is overwritten without modifying the source code of the static classes. ClassEditorUML has setting in repository info to declare a JavaScript class as static. The option will be set by js2uml() and