ts2famix 1.0.10 → 1.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +24 -24
- package/LICENSE +23 -23
- package/README.md +109 -109
- package/jest.config-old.ts +199 -199
- package/package.json +47 -47
- package/src/analyze.ts +94 -94
- package/src/analyze_functions/processAccesses.ts +57 -50
- package/src/analyze_functions/processFiles.ts +669 -660
- package/src/analyze_functions/processImportClauses.ts +77 -77
- package/src/analyze_functions/processInheritances.ts +84 -84
- package/src/analyze_functions/processInvocations.ts +51 -51
- package/src/famix2puml.ts +119 -119
- package/src/famix_functions/famix_functions.ts +559 -555
- package/src/famix_functions/famix_functions_associations.ts +215 -215
- package/src/famix_functions/famix_functions_index.ts +44 -44
- package/src/famix_functions/famix_functions_types.ts +105 -100
- package/src/generate_uml.sh +16 -16
- package/src/lib/famix/License.md +22 -22
- package/src/lib/famix/package-lock.json +301 -301
- package/src/lib/famix/package.json +27 -27
- package/src/lib/famix/readme.md +4 -4
- package/src/lib/famix/src/famix_JSON_exporter.ts +56 -56
- package/src/lib/famix/src/famix_base_element.ts +18 -18
- package/src/lib/famix/src/famix_repository.ts +199 -199
- package/src/lib/famix/src/index.ts +8 -8
- package/src/lib/famix/src/model/famix/access.ts +53 -53
- package/src/lib/famix/src/model/famix/accessor.ts +15 -15
- package/src/lib/famix/src/model/famix/alias.ts +41 -41
- package/src/lib/famix/src/model/famix/association.ts +44 -44
- package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -107
- package/src/lib/famix/src/model/famix/c_source_language.ts +15 -15
- package/src/lib/famix/src/model/famix/class.ts +86 -86
- package/src/lib/famix/src/model/famix/comment.ts +50 -50
- package/src/lib/famix/src/model/famix/container_entity.ts +165 -165
- package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -27
- package/src/lib/famix/src/model/famix/decorator.ts +39 -39
- package/src/lib/famix/src/model/famix/entity.ts +15 -15
- package/src/lib/famix/src/model/famix/enum.ts +31 -31
- package/src/lib/famix/src/model/famix/enum_value.ts +29 -29
- package/src/lib/famix/src/model/famix/function.ts +15 -15
- package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -15
- package/src/lib/famix/src/model/famix/import_clause.ts +53 -53
- package/src/lib/famix/src/model/famix/index.ts +42 -42
- package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -49
- package/src/lib/famix/src/model/famix/inheritance.ts +42 -42
- package/src/lib/famix/src/model/famix/interface.ts +75 -75
- package/src/lib/famix/src/model/famix/invocation.ts +68 -68
- package/src/lib/famix/src/model/famix/method.ts +96 -96
- package/src/lib/famix/src/model/famix/module.ts +31 -31
- package/src/lib/famix/src/model/famix/named_entity.ts +98 -98
- package/src/lib/famix/src/model/famix/namespace.ts +28 -28
- package/src/lib/famix/src/model/famix/parameter.ts +29 -29
- package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -31
- package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -31
- package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -40
- package/src/lib/famix/src/model/famix/primitive_type.ts +15 -15
- package/src/lib/famix/src/model/famix/property.ts +54 -54
- package/src/lib/famix/src/model/famix/reference.ts +42 -42
- package/src/lib/famix/src/model/famix/scoping_entity.ts +31 -31
- package/src/lib/famix/src/model/famix/script_entity.ts +38 -38
- package/src/lib/famix/src/model/famix/source_anchor.ts +31 -31
- package/src/lib/famix/src/model/famix/source_language.ts +31 -31
- package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/src/model/famix/structural_entity.ts +44 -44
- package/src/lib/famix/src/model/famix/text_anchor.ts +49 -49
- package/src/lib/famix/src/model/famix/type.ts +88 -88
- package/src/lib/famix/src/model/famix/type_parameter.ts +33 -33
- package/src/lib/famix/src/model/famix/variable.ts +28 -28
- package/src/lib/famix/tsconfig.json +26 -26
- package/src/lib/famix/tslint.json +14 -14
- package/src/lib/ts-complex/cyclomatic-service.ts +85 -85
- package/src/ts2famix-cli.ts +39 -39
- package/tsconfig.json +69 -69
- package/dist/analyze.js +0 -102
- package/dist/analyze_functions/processAccesses.js +0 -47
- package/dist/analyze_functions/processFiles.js +0 -540
- package/dist/analyze_functions/processImportClauses.js +0 -70
- package/dist/analyze_functions/processInheritances.js +0 -73
- package/dist/analyze_functions/processInvocations.js +0 -49
- package/dist/famix2puml.js +0 -125
- package/dist/famix_functions/famix_functions.js +0 -513
- package/dist/famix_functions/famix_functions_associations.js +0 -205
- package/dist/famix_functions/famix_functions_index.js +0 -62
- package/dist/famix_functions/famix_functions_types.js +0 -110
- package/dist/fqn.js +0 -126
- package/dist/fqp_implementation.js +0 -73
- package/dist/lib/famix/src/famix_JSON_exporter.js +0 -54
- package/dist/lib/famix/src/famix_base_element.js +0 -13
- package/dist/lib/famix/src/famix_repository.js +0 -187
- package/dist/lib/famix/src/index.js +0 -30
- package/dist/lib/famix/src/model/famix/access.js +0 -39
- package/dist/lib/famix/src/model/famix/accessor.js +0 -16
- package/dist/lib/famix/src/model/famix/alias.js +0 -32
- package/dist/lib/famix/src/model/famix/association.js +0 -36
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +0 -81
- package/dist/lib/famix/src/model/famix/c_source_language.js +0 -16
- package/dist/lib/famix/src/model/famix/class.js +0 -70
- package/dist/lib/famix/src/model/famix/comment.js +0 -38
- package/dist/lib/famix/src/model/famix/container_entity.js +0 -125
- package/dist/lib/famix/src/model/famix/custom_source_language.js +0 -23
- package/dist/lib/famix/src/model/famix/decorator.js +0 -31
- package/dist/lib/famix/src/model/famix/entity.js +0 -16
- package/dist/lib/famix/src/model/famix/enum.js +0 -30
- package/dist/lib/famix/src/model/famix/enum_value.js +0 -24
- package/dist/lib/famix/src/model/famix/function.js +0 -16
- package/dist/lib/famix/src/model/famix/implicit_variable.js +0 -16
- package/dist/lib/famix/src/model/famix/import_clause.js +0 -39
- package/dist/lib/famix/src/model/famix/index.js +0 -87
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -37
- package/dist/lib/famix/src/model/famix/inheritance.js +0 -32
- package/dist/lib/famix/src/model/famix/interface.js +0 -63
- package/dist/lib/famix/src/model/famix/invocation.js +0 -53
- package/dist/lib/famix/src/model/famix/method.js +0 -66
- package/dist/lib/famix/src/model/famix/module.js +0 -30
- package/dist/lib/famix/src/model/famix/named_entity.js +0 -77
- package/dist/lib/famix/src/model/famix/namespace.js +0 -24
- package/dist/lib/famix/src/model/famix/parameter.js +0 -24
- package/dist/lib/famix/src/model/famix/parameterizable_class.js +0 -30
- package/dist/lib/famix/src/model/famix/parameterizable_interface.js +0 -30
- package/dist/lib/famix/src/model/famix/parameterized_type.js +0 -36
- package/dist/lib/famix/src/model/famix/primitive_type.js +0 -16
- package/dist/lib/famix/src/model/famix/property.js +0 -44
- package/dist/lib/famix/src/model/famix/reference.js +0 -32
- package/dist/lib/famix/src/model/famix/scoping_entity.js +0 -30
- package/dist/lib/famix/src/model/famix/script_entity.js +0 -30
- package/dist/lib/famix/src/model/famix/source_anchor.js +0 -26
- package/dist/lib/famix/src/model/famix/source_language.js +0 -30
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -55
- package/dist/lib/famix/src/model/famix/structural_entity.js +0 -38
- package/dist/lib/famix/src/model/famix/text_anchor.js +0 -37
- package/dist/lib/famix/src/model/famix/type.js +0 -71
- package/dist/lib/famix/src/model/famix/type_parameter.js +0 -24
- package/dist/lib/famix/src/model/famix/variable.js +0 -23
- package/dist/lib/ts-complex/cyclomatic-service.js +0 -83
- package/dist/ts2famix-cli.js +0 -63
- package/dist/ts2famix-tsconfig.js +0 -53
- package/metrics.ts +0 -23
- package/src/fqp_implementation.ts +0 -66
package/src/famix2puml.ts
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import yargs from 'yargs';
|
|
3
|
-
|
|
4
|
-
const argv = yargs
|
|
5
|
-
.example('ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml', 'creates a PlantUML class diagram from a JSON-format model of a typescript project')
|
|
6
|
-
.alias('i', 'input')
|
|
7
|
-
.nargs('i', 1)
|
|
8
|
-
.alias('o', 'output')
|
|
9
|
-
.nargs('o', 1)
|
|
10
|
-
.demandOption('input').demandOption('output').parseSync();
|
|
11
|
-
|
|
12
|
-
const INHERITANCE_LINK_COLOR = 'blue';
|
|
13
|
-
|
|
14
|
-
// approximation for code completion
|
|
15
|
-
interface FamixTypeScriptElement {
|
|
16
|
-
FM3: string
|
|
17
|
-
name: string
|
|
18
|
-
id?: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface Association {
|
|
22
|
-
from: string;
|
|
23
|
-
to: string;
|
|
24
|
-
name: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const jsonFileName = argv.input as string;
|
|
28
|
-
const pumlFileName = (argv.output as string).substring((argv.output as string).indexOf("/")+1, (argv.output as string).lastIndexOf('.'));
|
|
29
|
-
const parsedModel: Array<FamixTypeScriptElement> = JSON.parse(fs.readFileSync(jsonFileName, 'utf-8'));
|
|
30
|
-
const classNameMap = new Map<string, string>();
|
|
31
|
-
const associations = new Array<Association>();
|
|
32
|
-
|
|
33
|
-
// maps all class names to their id
|
|
34
|
-
parsedModel.forEach(element => {
|
|
35
|
-
// map has id as key and unique (plantuml) class name
|
|
36
|
-
classNameMap.set(element.id, uniqueElementName(element));
|
|
37
|
-
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
38
|
-
// special case association
|
|
39
|
-
if (nameWithoutPrefix.endsWith('Inheritance')) {
|
|
40
|
-
const subclass = element['subclass'].ref;
|
|
41
|
-
const superclass = element['superclass'].ref;
|
|
42
|
-
associations.push({ from: subclass, to: superclass, name: nameWithoutPrefix });
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
// generates plantuml
|
|
47
|
-
let plantUMLOutString = `@startuml ${pumlFileName}
|
|
48
|
-
skinparam style strictuml
|
|
49
|
-
title Object diagram for ${jsonFileName}
|
|
50
|
-
`;
|
|
51
|
-
parsedModel.forEach(element => {
|
|
52
|
-
plantUMLOutString += `${toPlantUML(element)}\n`;
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// creates associations
|
|
56
|
-
associations.forEach(association => {
|
|
57
|
-
// inheritance is a special case, show it in UML even though it doesn't make 100% sense in object diagrams
|
|
58
|
-
const isInheritance = association.name.startsWith('Inheritance');
|
|
59
|
-
if (isInheritance) {
|
|
60
|
-
plantUMLOutString += `${classNameMap.get(association.from)} --|> ${classNameMap.get(association.to)} #line:${INHERITANCE_LINK_COLOR}\n`;
|
|
61
|
-
} else {
|
|
62
|
-
plantUMLOutString += `${classNameMap.get(association.from)} ..> "${association.name}" ${classNameMap.get(association.to)}\n`;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
plantUMLOutString += '@enduml';
|
|
67
|
-
|
|
68
|
-
// writes to output file
|
|
69
|
-
fs.writeFile(argv.output as string, plantUMLOutString, (err) => {
|
|
70
|
-
if (err) { throw err; }
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
function uniqueElementName(element: FamixTypeScriptElement): string {
|
|
74
|
-
return `${element.FM3}${element.id}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function toPlantUML(element: FamixTypeScriptElement) {
|
|
78
|
-
let plantUMLString = '';
|
|
79
|
-
const optionalName = element.name || '';
|
|
80
|
-
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
81
|
-
plantUMLString += `object "${optionalName}:${nameWithoutPrefix}" as ${uniqueElementName(element)} {\n`;
|
|
82
|
-
plantUMLString += `id = ${element.id}\n`;
|
|
83
|
-
plantUMLString += propertiesToPlantUML(element);
|
|
84
|
-
plantUMLString += '}\n';
|
|
85
|
-
return plantUMLString;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function propertiesToPlantUML(element: FamixTypeScriptElement) {
|
|
89
|
-
let plantUMLString = '';
|
|
90
|
-
for (const property in element) {
|
|
91
|
-
const attribute = element[property];
|
|
92
|
-
const isOneToManyReference = typeof attribute !== 'string' && attribute.length; // array but not a string
|
|
93
|
-
|
|
94
|
-
switch (property) {
|
|
95
|
-
// ignores these properties
|
|
96
|
-
case 'subclass':
|
|
97
|
-
case 'superclass':
|
|
98
|
-
case 'FM3':
|
|
99
|
-
case 'id':
|
|
100
|
-
case 'name':
|
|
101
|
-
break;
|
|
102
|
-
|
|
103
|
-
default:
|
|
104
|
-
if (isOneToManyReference) {
|
|
105
|
-
attribute.forEach((composite, index) => {
|
|
106
|
-
associations.push({ from: element.id, to: composite.ref, name: `${property}[${index}]` });
|
|
107
|
-
});
|
|
108
|
-
} else if (typeof attribute === 'object') {
|
|
109
|
-
associations.push({ from: element.id, to: attribute.ref, name: property });
|
|
110
|
-
} else { // typeof string, boolean, number, etc
|
|
111
|
-
// treats it as a simple attribute
|
|
112
|
-
plantUMLString += `${property} = ${element[property]}\n`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return plantUMLString;
|
|
119
|
-
}
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
|
|
4
|
+
const argv = yargs
|
|
5
|
+
.example('ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml', 'creates a PlantUML class diagram from a JSON-format model of a typescript project')
|
|
6
|
+
.alias('i', 'input')
|
|
7
|
+
.nargs('i', 1)
|
|
8
|
+
.alias('o', 'output')
|
|
9
|
+
.nargs('o', 1)
|
|
10
|
+
.demandOption('input').demandOption('output').parseSync();
|
|
11
|
+
|
|
12
|
+
const INHERITANCE_LINK_COLOR = 'blue';
|
|
13
|
+
|
|
14
|
+
// approximation for code completion
|
|
15
|
+
interface FamixTypeScriptElement {
|
|
16
|
+
FM3: string
|
|
17
|
+
name: string
|
|
18
|
+
id?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Association {
|
|
22
|
+
from: string;
|
|
23
|
+
to: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const jsonFileName = argv.input as string;
|
|
28
|
+
const pumlFileName = (argv.output as string).substring((argv.output as string).indexOf("/")+1, (argv.output as string).lastIndexOf('.'));
|
|
29
|
+
const parsedModel: Array<FamixTypeScriptElement> = JSON.parse(fs.readFileSync(jsonFileName, 'utf-8'));
|
|
30
|
+
const classNameMap = new Map<string, string>();
|
|
31
|
+
const associations = new Array<Association>();
|
|
32
|
+
|
|
33
|
+
// maps all class names to their id
|
|
34
|
+
parsedModel.forEach(element => {
|
|
35
|
+
// map has id as key and unique (plantuml) class name
|
|
36
|
+
classNameMap.set(element.id, uniqueElementName(element));
|
|
37
|
+
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
38
|
+
// special case association
|
|
39
|
+
if (nameWithoutPrefix.endsWith('Inheritance')) {
|
|
40
|
+
const subclass = element['subclass'].ref;
|
|
41
|
+
const superclass = element['superclass'].ref;
|
|
42
|
+
associations.push({ from: subclass, to: superclass, name: nameWithoutPrefix });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// generates plantuml
|
|
47
|
+
let plantUMLOutString = `@startuml ${pumlFileName}
|
|
48
|
+
skinparam style strictuml
|
|
49
|
+
title Object diagram for ${jsonFileName}
|
|
50
|
+
`;
|
|
51
|
+
parsedModel.forEach(element => {
|
|
52
|
+
plantUMLOutString += `${toPlantUML(element)}\n`;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// creates associations
|
|
56
|
+
associations.forEach(association => {
|
|
57
|
+
// inheritance is a special case, show it in UML even though it doesn't make 100% sense in object diagrams
|
|
58
|
+
const isInheritance = association.name.startsWith('Inheritance');
|
|
59
|
+
if (isInheritance) {
|
|
60
|
+
plantUMLOutString += `${classNameMap.get(association.from)} --|> ${classNameMap.get(association.to)} #line:${INHERITANCE_LINK_COLOR}\n`;
|
|
61
|
+
} else {
|
|
62
|
+
plantUMLOutString += `${classNameMap.get(association.from)} ..> "${association.name}" ${classNameMap.get(association.to)}\n`;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
plantUMLOutString += '@enduml';
|
|
67
|
+
|
|
68
|
+
// writes to output file
|
|
69
|
+
fs.writeFile(argv.output as string, plantUMLOutString, (err) => {
|
|
70
|
+
if (err) { throw err; }
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function uniqueElementName(element: FamixTypeScriptElement): string {
|
|
74
|
+
return `${element.FM3}${element.id}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toPlantUML(element: FamixTypeScriptElement) {
|
|
78
|
+
let plantUMLString = '';
|
|
79
|
+
const optionalName = element.name || '';
|
|
80
|
+
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
81
|
+
plantUMLString += `object "${optionalName}:${nameWithoutPrefix}" as ${uniqueElementName(element)} {\n`;
|
|
82
|
+
plantUMLString += `id = ${element.id}\n`;
|
|
83
|
+
plantUMLString += propertiesToPlantUML(element);
|
|
84
|
+
plantUMLString += '}\n';
|
|
85
|
+
return plantUMLString;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function propertiesToPlantUML(element: FamixTypeScriptElement) {
|
|
89
|
+
let plantUMLString = '';
|
|
90
|
+
for (const property in element) {
|
|
91
|
+
const attribute = element[property];
|
|
92
|
+
const isOneToManyReference = typeof attribute !== 'string' && attribute.length; // array but not a string
|
|
93
|
+
|
|
94
|
+
switch (property) {
|
|
95
|
+
// ignores these properties
|
|
96
|
+
case 'subclass':
|
|
97
|
+
case 'superclass':
|
|
98
|
+
case 'FM3':
|
|
99
|
+
case 'id':
|
|
100
|
+
case 'name':
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
default:
|
|
104
|
+
if (isOneToManyReference) {
|
|
105
|
+
attribute.forEach((composite, index) => {
|
|
106
|
+
associations.push({ from: element.id, to: composite.ref, name: `${property}[${index}]` });
|
|
107
|
+
});
|
|
108
|
+
} else if (typeof attribute === 'object') {
|
|
109
|
+
associations.push({ from: element.id, to: attribute.ref, name: property });
|
|
110
|
+
} else { // typeof string, boolean, number, etc
|
|
111
|
+
// treats it as a simple attribute
|
|
112
|
+
plantUMLString += `${property} = ${element[property]}\n`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return plantUMLString;
|
|
119
|
+
}
|