ts2famix 1.4.1 → 2.0.1
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/LICENSE +1 -0
- package/README.md +30 -61
- package/dist/analyze.js +4 -2
- package/dist/analyze_functions/process_functions.js +285 -131
- package/dist/famix_functions/EntityDictionary.js +864 -231
- package/dist/famix_functions/helpers_creation.js +61 -10
- package/dist/fqn.js +160 -111
- package/dist/lib/famix/famix_JSON_exporter.js +55 -0
- package/dist/lib/famix/famix_base_element.js +18 -0
- package/dist/lib/famix/famix_repository.js +224 -0
- package/dist/lib/famix/{src/index.js → index.js} +1 -0
- package/dist/lib/famix/model/famix/access.js +40 -0
- package/dist/lib/famix/model/famix/accessor.js +17 -0
- package/dist/lib/famix/model/famix/alias.js +33 -0
- package/dist/lib/famix/model/famix/arrow_function.js +17 -0
- package/dist/lib/famix/model/famix/behavioral_entity.js +79 -0
- package/dist/lib/famix/model/famix/class.js +71 -0
- package/dist/lib/famix/model/famix/comment.js +39 -0
- package/dist/lib/famix/model/famix/concretisation.js +31 -0
- package/dist/lib/famix/model/famix/container_entity.js +126 -0
- package/dist/lib/famix/model/famix/decorator.js +32 -0
- package/dist/lib/famix/model/famix/entity.js +17 -0
- package/dist/lib/famix/model/famix/enum.js +31 -0
- package/dist/lib/famix/model/famix/enum_value.js +25 -0
- package/dist/lib/famix/model/famix/function.js +17 -0
- package/dist/lib/famix/model/famix/import_clause.js +41 -0
- package/dist/lib/famix/model/famix/index.js +86 -0
- package/dist/lib/famix/model/famix/indexed_file_anchor.js +38 -0
- package/dist/lib/famix/model/famix/inheritance.js +33 -0
- package/dist/lib/famix/model/famix/interface.js +64 -0
- package/dist/lib/famix/model/famix/invocation.js +54 -0
- package/dist/lib/famix/model/famix/method.js +67 -0
- package/dist/lib/famix/model/famix/module.js +60 -0
- package/dist/lib/famix/model/famix/named_entity.js +78 -0
- package/dist/lib/famix/model/famix/parameter.js +25 -0
- package/dist/lib/famix/model/famix/parameter_concretisation.js +44 -0
- package/dist/lib/famix/model/famix/parameter_type.js +45 -0
- package/dist/lib/famix/model/famix/parametric_arrow_function.js +31 -0
- package/dist/lib/famix/model/famix/parametric_class.js +44 -0
- package/dist/lib/famix/model/famix/parametric_function.js +31 -0
- package/dist/lib/famix/model/famix/parametric_interface.js +44 -0
- package/dist/lib/famix/model/famix/parametric_method.js +31 -0
- package/dist/lib/famix/model/famix/primitive_type.js +17 -0
- package/dist/lib/famix/model/famix/property.js +73 -0
- package/dist/lib/famix/model/famix/reference.js +33 -0
- package/dist/lib/famix/model/famix/scoping_entity.js +36 -0
- package/dist/lib/famix/model/famix/script_entity.js +29 -0
- package/dist/lib/famix/model/famix/source_anchor.js +27 -0
- package/dist/lib/famix/model/famix/source_language.js +35 -0
- package/dist/lib/famix/model/famix/sourced_entity.js +60 -0
- package/dist/lib/famix/model/famix/structural_entity.js +39 -0
- package/dist/lib/famix/model/famix/type.js +73 -0
- package/dist/lib/famix/model/famix/variable.js +24 -0
- package/dist/lib/ts-complex/cyclomatic-service.js +3 -3
- package/dist/refactorer/refactor-getter-setter.js +142 -0
- package/dist/ts2famix-cli-wrapper.js +42 -0
- package/dist/ts2famix-cli.js +8 -1
- package/dist/ts2famix-tsconfig.js +1 -0
- package/doc-uml/famix-typescript-model.puml +608 -0
- package/doc-uml/famix-typescript-model.svg +1 -0
- package/jest.config.json +2 -1
- package/package.json +13 -12
- package/src/analyze.ts +24 -23
- package/src/analyze_functions/process_functions.ts +310 -129
- package/src/famix_functions/EntityDictionary.ts +949 -271
- package/src/famix_functions/helpers_creation.ts +64 -6
- package/src/fqn.ts +169 -96
- package/{dist/lib/famix/src/famix_JSON_exporter.js → src/lib/famix/famix_JSON_exporter.ts} +16 -14
- package/src/lib/famix/famix_base_element.ts +22 -0
- package/{dist/lib/famix/src/famix_repository.js → src/lib/famix/famix_repository.ts} +96 -75
- package/src/lib/famix/model/famix/access.ts +50 -0
- package/src/lib/famix/model/famix/alias.ts +39 -0
- package/src/lib/famix/{src/model/famix/implicit_variable.ts → model/famix/arrow_function.ts} +3 -3
- package/src/lib/famix/model/famix/behavioral_entity.ts +97 -0
- package/src/lib/famix/model/famix/class.ts +85 -0
- package/src/lib/famix/model/famix/comment.ts +47 -0
- package/src/lib/famix/model/famix/concretisation.ts +40 -0
- package/src/lib/famix/model/famix/container_entity.ts +160 -0
- package/src/lib/famix/model/famix/decorator.ts +37 -0
- package/src/lib/famix/model/famix/enum.ts +30 -0
- package/src/lib/famix/model/famix/enum_value.ts +28 -0
- package/src/lib/famix/model/famix/import_clause.ts +51 -0
- package/src/lib/famix/{src/model → model}/famix/index.ts +8 -7
- package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -0
- package/src/lib/famix/model/famix/inheritance.ts +40 -0
- package/src/lib/famix/model/famix/interface.ts +75 -0
- package/src/lib/famix/model/famix/invocation.ts +65 -0
- package/src/lib/famix/model/famix/method.ts +89 -0
- package/src/lib/famix/model/famix/module.ts +71 -0
- package/src/lib/famix/model/famix/named_entity.ts +95 -0
- package/src/lib/famix/{src/model → model}/famix/parameter.ts +11 -12
- package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -0
- package/src/lib/famix/model/famix/parameter_type.ts +58 -0
- package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -0
- package/src/lib/famix/model/famix/parametric_class.ts +49 -0
- package/src/lib/famix/model/famix/parametric_function.ts +32 -0
- package/src/lib/famix/model/famix/parametric_interface.ts +49 -0
- package/src/lib/famix/model/famix/parametric_method.ts +32 -0
- package/src/lib/famix/model/famix/primitive_type.ts +15 -0
- package/src/lib/famix/model/famix/property.ts +94 -0
- package/src/lib/famix/model/famix/reference.ts +40 -0
- package/src/lib/famix/model/famix/scoping_entity.ts +35 -0
- package/src/lib/famix/model/famix/script_entity.ts +34 -0
- package/src/lib/famix/model/famix/source_anchor.ts +30 -0
- package/src/lib/famix/model/famix/source_language.ts +35 -0
- package/src/lib/famix/model/famix/sourced_entity.ts +70 -0
- package/src/lib/famix/model/famix/structural_entity.ts +43 -0
- package/src/lib/famix/model/famix/type.ts +87 -0
- package/src/lib/famix/model/famix/variable.ts +27 -0
- package/src/lib/famix/package.json +1 -1
- package/src/lib/ts-complex/cyclomatic-service.ts +10 -10
- package/src/refactorer/refactor-getter-setter.ts +140 -0
- package/src/ts2famix-cli-wrapper.ts +21 -0
- package/src/ts2famix-cli.ts +8 -2
- package/tsconfig.check-tests.json +14 -0
- package/tsconfig.json +71 -69
- package/dist/famix2puml.js +0 -125
- package/dist/lib/famix/src/famix_base_element.js +0 -17
- 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/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/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 -83
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +0 -51
- 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 -31
- 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/parameter_type.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 -35
- 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 -35
- package/dist/lib/famix/src/model/famix/sourced_entity.js +0 -59
- 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/variable.js +0 -23
- package/doc-uml/metamodel-full.svg +0 -1
- package/doc-uml/metamodel.svg +0 -1
- package/jest.config-old.ts +0 -199
- package/plantuml.jar +0 -0
- package/src/famix2puml.ts +0 -119
- package/src/lib/famix/package-lock.json +0 -301
- package/src/lib/famix/readme.md +0 -5
- package/src/lib/famix/src/famix_JSON_exporter.ts +0 -56
- package/src/lib/famix/src/famix_base_element.ts +0 -22
- package/src/lib/famix/src/famix_repository.ts +0 -243
- package/src/lib/famix/src/model/famix/access.ts +0 -53
- package/src/lib/famix/src/model/famix/alias.ts +0 -41
- package/src/lib/famix/src/model/famix/association.ts +0 -44
- package/src/lib/famix/src/model/famix/behavioral_entity.ts +0 -107
- package/src/lib/famix/src/model/famix/class.ts +0 -86
- package/src/lib/famix/src/model/famix/comment.ts +0 -50
- package/src/lib/famix/src/model/famix/container_entity.ts +0 -165
- package/src/lib/famix/src/model/famix/decorator.ts +0 -39
- package/src/lib/famix/src/model/famix/enum.ts +0 -31
- package/src/lib/famix/src/model/famix/enum_value.ts +0 -29
- package/src/lib/famix/src/model/famix/import_clause.ts +0 -53
- package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +0 -71
- package/src/lib/famix/src/model/famix/inheritance.ts +0 -42
- package/src/lib/famix/src/model/famix/interface.ts +0 -75
- package/src/lib/famix/src/model/famix/invocation.ts +0 -68
- package/src/lib/famix/src/model/famix/method.ts +0 -96
- package/src/lib/famix/src/model/famix/module.ts +0 -31
- package/src/lib/famix/src/model/famix/named_entity.ts +0 -98
- package/src/lib/famix/src/model/famix/namespace.ts +0 -28
- package/src/lib/famix/src/model/famix/parameter_type.ts +0 -33
- package/src/lib/famix/src/model/famix/parameterizable_class.ts +0 -31
- package/src/lib/famix/src/model/famix/parameterizable_interface.ts +0 -31
- package/src/lib/famix/src/model/famix/parameterized_type.ts +0 -40
- package/src/lib/famix/src/model/famix/primitive_type.ts +0 -15
- package/src/lib/famix/src/model/famix/property.ts +0 -54
- package/src/lib/famix/src/model/famix/reference.ts +0 -42
- package/src/lib/famix/src/model/famix/scoping_entity.ts +0 -35
- package/src/lib/famix/src/model/famix/script_entity.ts +0 -38
- package/src/lib/famix/src/model/famix/source_anchor.ts +0 -31
- package/src/lib/famix/src/model/famix/source_language.ts +0 -37
- package/src/lib/famix/src/model/famix/sourced_entity.ts +0 -73
- package/src/lib/famix/src/model/famix/structural_entity.ts +0 -44
- package/src/lib/famix/src/model/famix/text_anchor.ts +0 -49
- package/src/lib/famix/src/model/famix/type.ts +0 -88
- package/src/lib/famix/src/model/famix/variable.ts +0 -28
- package/src/lib/famix/tsconfig.json +0 -27
- package/src/lib/famix/tslint.json +0 -15
- /package/src/lib/famix/{src/index.ts → index.ts} +0 -0
- /package/src/lib/famix/{src/model → model}/famix/accessor.ts +0 -0
- /package/src/lib/famix/{src/model → model}/famix/entity.ts +0 -0
- /package/src/lib/famix/{src/model → model}/famix/function.ts +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ClassDeclaration, Project, SourceFile, SyntaxKind } from "ts-morph";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
|
|
4
|
+
const project = new Project();
|
|
5
|
+
project.addSourceFilesAtPaths("src/lib/famix/model/famix/famix_base_element.ts");
|
|
6
|
+
project.getSourceFiles().forEach(sourceFile => { console.log(sourceFile.getFilePath()); });
|
|
7
|
+
|
|
8
|
+
project.getSourceFiles().forEach(sourceFile => {
|
|
9
|
+
const typeMap = createTypeMap(sourceFile);
|
|
10
|
+
|
|
11
|
+
const classes = sourceFile.getClasses();
|
|
12
|
+
classes.forEach(cls => {
|
|
13
|
+
const properties = cls.getProperties();
|
|
14
|
+
cls.getMethods().forEach(method => {
|
|
15
|
+
const methodName = method.getName();
|
|
16
|
+
let propName: string;
|
|
17
|
+
|
|
18
|
+
if (isEligibleGetter(methodName)) {
|
|
19
|
+
propName = methodName.charAt(3).toLowerCase() + methodName.slice(4);
|
|
20
|
+
renamePropertyIfExists(cls, propName, properties);
|
|
21
|
+
refactorToGetter(cls, method, propName, typeMap);
|
|
22
|
+
replaceMethodCalls(cls, `get${capitalize(propName)}`, propName);
|
|
23
|
+
} else if (isEligibleSetter(methodName)) {
|
|
24
|
+
propName = methodName.charAt(3).toLowerCase() + methodName.slice(4);
|
|
25
|
+
renamePropertyIfExists(cls, propName, properties);
|
|
26
|
+
refactorToSetter(cls, method, propName, typeMap);
|
|
27
|
+
replaceMethodCalls(cls, `set${capitalize(propName)}`, propName);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
project.save().then(() => {
|
|
34
|
+
console.log("Refactoring complete!");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
function isEligibleGetter(methodName: string): boolean {
|
|
38
|
+
return methodName.startsWith("get") && /^[A-Z][a-zA-Z0-9]*$/.test(methodName.slice(3)) && !methodName.includes("JSON");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isEligibleSetter(methodName: string): boolean {
|
|
42
|
+
return methodName.startsWith("set") && /^[A-Z][a-zA-Z0-9]*$/.test(methodName.slice(3));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renamePropertyIfExists(cls: any, propName: string, properties: any[]) {
|
|
46
|
+
const existingProperty = properties.find(prop => prop.getName() === propName);
|
|
47
|
+
if (existingProperty) {
|
|
48
|
+
existingProperty.rename(`_${propName}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function createTypeMap(sourceFile: SourceFile): Map<string, string> {
|
|
53
|
+
const typeMap = new Map<string, string>();
|
|
54
|
+
const importDeclarations = sourceFile.getImportDeclarations();
|
|
55
|
+
|
|
56
|
+
importDeclarations.forEach(importDecl => {
|
|
57
|
+
const moduleSpecifier = importDecl.getModuleSpecifier().getText().replace(/['"]/g, '');
|
|
58
|
+
const absolutePath = path.resolve(sourceFile.getDirectory().getPath(), moduleSpecifier);
|
|
59
|
+
const normalizedPath = normalizePath(absolutePath);
|
|
60
|
+
const namedImports = importDecl.getNamedImports();
|
|
61
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
62
|
+
|
|
63
|
+
namedImports.forEach(namedImport => {
|
|
64
|
+
console.log(`Named import: ${namedImport.getName()}, path: ${normalizedPath}`);
|
|
65
|
+
typeMap.set(namedImport.getName(), normalizedPath);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (defaultImport) {
|
|
69
|
+
typeMap.set(defaultImport.getText(), normalizedPath);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return typeMap;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function refactorToGetter(cls: any, method: any, propName: string, typeMap: Map<string, string>) {
|
|
77
|
+
const getterName = propName;
|
|
78
|
+
const renamedProp = `_${propName}`;
|
|
79
|
+
const returnType = method.getReturnType().getText();
|
|
80
|
+
const simplifiedType = replaceLongTypePaths(returnType, typeMap);
|
|
81
|
+
|
|
82
|
+
const getterBody = method.getBodyText().replace(new RegExp(`this\\.${propName}`, 'g'), `this.${renamedProp}`);
|
|
83
|
+
|
|
84
|
+
cls.addGetAccessor({
|
|
85
|
+
name: getterName,
|
|
86
|
+
statements: getterBody,
|
|
87
|
+
// returnType: simplifiedType, // don't need a return type for getter
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
method.remove();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function refactorToSetter(cls: any, method: any, propName: string, typeMap: Map<string, string>) {
|
|
94
|
+
const setterName = propName;
|
|
95
|
+
const renamedProp = `_${propName}`;
|
|
96
|
+
|
|
97
|
+
const parameter = method.getParameters()[0];
|
|
98
|
+
const paramName = parameter.getName();
|
|
99
|
+
const paramType = replaceLongTypePaths(parameter.getType().getText(), typeMap);
|
|
100
|
+
|
|
101
|
+
const setterBody = method.getBodyText().replace(new RegExp(`this\\.${propName}`, 'g'), `this.${renamedProp}`);
|
|
102
|
+
|
|
103
|
+
cls.addSetAccessor({
|
|
104
|
+
name: setterName,
|
|
105
|
+
statements: setterBody,
|
|
106
|
+
parameters: [{ name: paramName, type: paramType }],
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
method.remove();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function replaceLongTypePaths(type: string, typeMap: Map<string, string>): string {
|
|
113
|
+
for (const [importName, importPath] of typeMap.entries()) {
|
|
114
|
+
const longPath = `import("${importPath}")${importName}`;
|
|
115
|
+
const regex = new RegExp(`import\\(["']${normalizePath(importPath)}["']\\)\\.${importName}`, 'g');
|
|
116
|
+
if (regex.test(type)) {
|
|
117
|
+
return importName;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return type;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function normalizePath(filePath: string): string {
|
|
124
|
+
return filePath.replace(/\\/g, '/');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function replaceMethodCalls(cls: ClassDeclaration, methodName: string, propName: string) {
|
|
128
|
+
cls.getDescendantsOfKind(SyntaxKind.CallExpression).forEach(callExpr => {
|
|
129
|
+
const expr = callExpr.getExpression();
|
|
130
|
+
if (expr.getText() === `this.${methodName}`) {
|
|
131
|
+
callExpr.replaceWithText(`this.${propName}`);
|
|
132
|
+
} else if (expr.getText() === `this.${methodName}` && callExpr.getArguments().length > 0) {
|
|
133
|
+
callExpr.replaceWithText(`this.${propName} = ${callExpr.getArguments()[0].getText()}`);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function capitalize(str: string): string {
|
|
139
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
140
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
|
|
6
|
+
// Resolve the path to ts2famix-cli.js relative to the wrapper script
|
|
7
|
+
const cliPath = path.resolve(__dirname, 'ts2famix-cli.js');
|
|
8
|
+
|
|
9
|
+
// Allow tslog to display the proper TypeScript files and line numbers
|
|
10
|
+
const args = [
|
|
11
|
+
'--enable-source-maps',
|
|
12
|
+
'--experimental-specifier-resolution=node',
|
|
13
|
+
cliPath,
|
|
14
|
+
...process.argv.slice(2)
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
const child = spawn('node', args, { stdio: 'inherit' });
|
|
18
|
+
|
|
19
|
+
child.on('close', (code) => {
|
|
20
|
+
process.exit(code);
|
|
21
|
+
});
|
package/src/ts2famix-cli.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as fs from "fs";
|
|
3
3
|
import yargs from "yargs";
|
|
4
4
|
import { Importer } from './analyze';
|
|
5
|
-
import { FamixRepository } from "./lib/famix/
|
|
5
|
+
import { FamixRepository } from "./lib/famix/famix_repository";
|
|
6
6
|
import { Project } from "ts-morph";
|
|
7
7
|
import { config } from "./analyze";
|
|
8
8
|
|
|
@@ -33,8 +33,14 @@ let famixRep: FamixRepository;
|
|
|
33
33
|
|
|
34
34
|
if ((argv.input as string).endsWith('tsconfig.json')) {
|
|
35
35
|
const tsConfigFilePath = argv.input as string;
|
|
36
|
+
// get the baseUrl from the tsconfig file
|
|
37
|
+
const baseUrl = tsConfigFilePath.substring(0, tsConfigFilePath.lastIndexOf('/'));
|
|
38
|
+
logger.info(`baseUrl: ${baseUrl}`);
|
|
36
39
|
const project = new Project({
|
|
37
|
-
tsConfigFilePath
|
|
40
|
+
tsConfigFilePath,
|
|
41
|
+
compilerOptions: {
|
|
42
|
+
baseUrl: baseUrl,
|
|
43
|
+
}
|
|
38
44
|
});
|
|
39
45
|
famixRep = importer.famixRepFromProject(project);
|
|
40
46
|
|
package/tsconfig.json
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Basic Options */
|
|
4
|
+
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
|
5
|
+
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
6
|
+
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
7
|
+
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
8
|
+
// "checkJs": true, /* Report errors in .js files. */
|
|
9
|
+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
|
10
|
+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
|
11
|
+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
|
12
|
+
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
13
|
+
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
14
|
+
"outDir": "./dist", /* Redirect output structure to the directory. */
|
|
15
|
+
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
|
16
|
+
// "composite": true, /* Enable project compilation */
|
|
17
|
+
// "incremental": true, /* Enable incremental compilation */
|
|
18
|
+
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
19
|
+
// "removeComments": true, /* Do not emit comments to output. */
|
|
20
|
+
// "noEmit": true, /* Do not emit outputs. */
|
|
21
|
+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
22
|
+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
23
|
+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
24
|
+
/* Strict Type-Checking Options */
|
|
25
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
26
|
+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
27
|
+
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
28
|
+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
29
|
+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
30
|
+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
31
|
+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
32
|
+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
33
|
+
/* Additional Checks */
|
|
34
|
+
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
35
|
+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
36
|
+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
37
|
+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
38
|
+
/* Module Resolution Options */
|
|
39
|
+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
|
40
|
+
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
|
41
|
+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
42
|
+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
43
|
+
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
44
|
+
// "types": [], /* Type declaration files to be included in compilation. */
|
|
45
|
+
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
46
|
+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
47
|
+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
48
|
+
/* Source Map Options */
|
|
49
|
+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
50
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
51
|
+
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
52
|
+
"inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
53
|
+
/* Experimental Options */
|
|
54
|
+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
55
|
+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
56
|
+
},
|
|
57
|
+
"include": [
|
|
58
|
+
"src/**/*.ts",
|
|
59
|
+
],
|
|
60
|
+
"exclude": [
|
|
61
|
+
"node_modules",
|
|
62
|
+
"**/*.spec.ts",
|
|
63
|
+
],
|
|
64
|
+
"typedocOptions": {
|
|
65
|
+
"entryPoints": [
|
|
66
|
+
"src/*"
|
|
67
|
+
],
|
|
68
|
+
"entryPointStrategy": "expand",
|
|
69
|
+
"out": "docs",
|
|
70
|
+
"githubPages": false
|
|
71
|
+
}
|
|
72
|
+
}
|
package/dist/famix2puml.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
const fs = __importStar(require("fs"));
|
|
30
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
31
|
-
const argv = yargs_1.default
|
|
32
|
-
.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')
|
|
33
|
-
.alias('i', 'input')
|
|
34
|
-
.nargs('i', 1)
|
|
35
|
-
.alias('o', 'output')
|
|
36
|
-
.nargs('o', 1)
|
|
37
|
-
.demandOption('input').demandOption('output').parseSync();
|
|
38
|
-
const INHERITANCE_LINK_COLOR = 'blue';
|
|
39
|
-
const jsonFileName = argv.input;
|
|
40
|
-
const pumlFileName = argv.output.substring(argv.output.indexOf("/") + 1, argv.output.lastIndexOf('.'));
|
|
41
|
-
const parsedModel = JSON.parse(fs.readFileSync(jsonFileName, 'utf-8'));
|
|
42
|
-
const classNameMap = new Map();
|
|
43
|
-
const associations = new Array();
|
|
44
|
-
// maps all class names to their id
|
|
45
|
-
parsedModel.forEach(element => {
|
|
46
|
-
// map has id as key and unique (plantuml) class name
|
|
47
|
-
classNameMap.set(element.id, uniqueElementName(element));
|
|
48
|
-
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
49
|
-
// special case association
|
|
50
|
-
if (nameWithoutPrefix.endsWith('Inheritance')) {
|
|
51
|
-
const subclass = element['subclass'].ref;
|
|
52
|
-
const superclass = element['superclass'].ref;
|
|
53
|
-
associations.push({ from: subclass, to: superclass, name: nameWithoutPrefix });
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
// generates plantuml
|
|
57
|
-
let plantUMLOutString = `@startuml ${pumlFileName}
|
|
58
|
-
skinparam style strictuml
|
|
59
|
-
title Object diagram for ${jsonFileName}
|
|
60
|
-
`;
|
|
61
|
-
parsedModel.forEach(element => {
|
|
62
|
-
plantUMLOutString += `${toPlantUML(element)}\n`;
|
|
63
|
-
});
|
|
64
|
-
// creates associations
|
|
65
|
-
associations.forEach(association => {
|
|
66
|
-
// inheritance is a special case, show it in UML even though it doesn't make 100% sense in object diagrams
|
|
67
|
-
const isInheritance = association.name.startsWith('Inheritance');
|
|
68
|
-
if (isInheritance) {
|
|
69
|
-
plantUMLOutString += `${classNameMap.get(association.from)} --|> ${classNameMap.get(association.to)} #line:${INHERITANCE_LINK_COLOR}\n`;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
plantUMLOutString += `${classNameMap.get(association.from)} ..> "${association.name}" ${classNameMap.get(association.to)}\n`;
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
plantUMLOutString += '@enduml';
|
|
76
|
-
// writes to output file
|
|
77
|
-
fs.writeFile(argv.output, plantUMLOutString, (err) => {
|
|
78
|
-
if (err) {
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
function uniqueElementName(element) {
|
|
83
|
-
return `${element.FM3}${element.id}`;
|
|
84
|
-
}
|
|
85
|
-
function toPlantUML(element) {
|
|
86
|
-
let plantUMLString = '';
|
|
87
|
-
const optionalName = element.name || '';
|
|
88
|
-
const nameWithoutPrefix = element.FM3.split('.')[1];
|
|
89
|
-
plantUMLString += `object "${optionalName}:${nameWithoutPrefix}" as ${uniqueElementName(element)} {\n`;
|
|
90
|
-
plantUMLString += `id = ${element.id}\n`;
|
|
91
|
-
plantUMLString += propertiesToPlantUML(element);
|
|
92
|
-
plantUMLString += '}\n';
|
|
93
|
-
return plantUMLString;
|
|
94
|
-
}
|
|
95
|
-
function propertiesToPlantUML(element) {
|
|
96
|
-
let plantUMLString = '';
|
|
97
|
-
for (const property in element) {
|
|
98
|
-
const attribute = element[property];
|
|
99
|
-
const isOneToManyReference = typeof attribute !== 'string' && attribute.length; // array but not a string
|
|
100
|
-
switch (property) {
|
|
101
|
-
// ignores these properties
|
|
102
|
-
case 'subclass':
|
|
103
|
-
case 'superclass':
|
|
104
|
-
case 'FM3':
|
|
105
|
-
case 'id':
|
|
106
|
-
case 'name':
|
|
107
|
-
break;
|
|
108
|
-
default:
|
|
109
|
-
if (isOneToManyReference) {
|
|
110
|
-
attribute.forEach((composite, index) => {
|
|
111
|
-
associations.push({ from: element.id, to: composite.ref, name: `${property}[${index}]` });
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else if (typeof attribute === 'object') {
|
|
115
|
-
associations.push({ from: element.id, to: attribute.ref, name: property });
|
|
116
|
-
}
|
|
117
|
-
else { // typeof string, boolean, number, etc
|
|
118
|
-
// treats it as a simple attribute
|
|
119
|
-
plantUMLString += `${property} = ${element[property]}\n`;
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return plantUMLString;
|
|
125
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FamixBaseElement = void 0;
|
|
4
|
-
const analyze_1 = require("../../../analyze");
|
|
5
|
-
// import { FamixRepository } from "./famix_repository";
|
|
6
|
-
class FamixBaseElement {
|
|
7
|
-
// constructor(repo: FamixRepository) {
|
|
8
|
-
// repo.addElement(this);
|
|
9
|
-
// }
|
|
10
|
-
constructor() {
|
|
11
|
-
}
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
-
addPropertiesToExporter(exporter) {
|
|
14
|
-
analyze_1.logger.debug("addPropertiesToExporter not implemented for " + this.constructor.name + `(${exporter})`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.FamixBaseElement = FamixBaseElement;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Access = void 0;
|
|
4
|
-
const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
|
|
5
|
-
const association_1 = require("./association");
|
|
6
|
-
class Access extends association_1.Association {
|
|
7
|
-
getAccessor() {
|
|
8
|
-
return this.accessor;
|
|
9
|
-
}
|
|
10
|
-
setAccessor(accessor) {
|
|
11
|
-
this.accessor = accessor;
|
|
12
|
-
accessor.addAccess(this);
|
|
13
|
-
}
|
|
14
|
-
getVariable() {
|
|
15
|
-
return this.variable;
|
|
16
|
-
}
|
|
17
|
-
setVariable(variable) {
|
|
18
|
-
this.variable = variable;
|
|
19
|
-
variable.addIncomingAccess(this);
|
|
20
|
-
}
|
|
21
|
-
getIsWrite() {
|
|
22
|
-
return this.isWrite;
|
|
23
|
-
}
|
|
24
|
-
setIsWrite(isWrite) {
|
|
25
|
-
this.isWrite = isWrite;
|
|
26
|
-
}
|
|
27
|
-
getJSON() {
|
|
28
|
-
const json = new famix_JSON_exporter_1.FamixJSONExporter("Access", this);
|
|
29
|
-
this.addPropertiesToExporter(json);
|
|
30
|
-
return json.getJSON();
|
|
31
|
-
}
|
|
32
|
-
addPropertiesToExporter(exporter) {
|
|
33
|
-
super.addPropertiesToExporter(exporter);
|
|
34
|
-
exporter.addProperty("accessor", this.getAccessor());
|
|
35
|
-
exporter.addProperty("variable", this.getVariable());
|
|
36
|
-
exporter.addProperty("isWrite", this.getIsWrite());
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.Access = Access;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Accessor = void 0;
|
|
4
|
-
const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
|
|
5
|
-
const method_1 = require("./method");
|
|
6
|
-
class Accessor extends method_1.Method {
|
|
7
|
-
getJSON() {
|
|
8
|
-
const json = new famix_JSON_exporter_1.FamixJSONExporter("Accessor", this);
|
|
9
|
-
this.addPropertiesToExporter(json);
|
|
10
|
-
return json.getJSON();
|
|
11
|
-
}
|
|
12
|
-
addPropertiesToExporter(exporter) {
|
|
13
|
-
super.addPropertiesToExporter(exporter);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
exports.Accessor = Accessor;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Alias = void 0;
|
|
4
|
-
const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
|
|
5
|
-
const named_entity_1 = require("./named_entity");
|
|
6
|
-
class Alias extends named_entity_1.NamedEntity {
|
|
7
|
-
getParentEntity() {
|
|
8
|
-
return this.parentEntity;
|
|
9
|
-
}
|
|
10
|
-
setParentEntity(parentEntity) {
|
|
11
|
-
this.parentEntity = parentEntity;
|
|
12
|
-
parentEntity.addAlias(this);
|
|
13
|
-
}
|
|
14
|
-
getAliasedEntity() {
|
|
15
|
-
return this.aliasedEntity;
|
|
16
|
-
}
|
|
17
|
-
setAliasedEntity(aliasedEntity) {
|
|
18
|
-
this.aliasedEntity = aliasedEntity;
|
|
19
|
-
aliasedEntity.addTypeAlias(this);
|
|
20
|
-
}
|
|
21
|
-
getJSON() {
|
|
22
|
-
const json = new famix_JSON_exporter_1.FamixJSONExporter("Alias", this);
|
|
23
|
-
this.addPropertiesToExporter(json);
|
|
24
|
-
return json.getJSON();
|
|
25
|
-
}
|
|
26
|
-
addPropertiesToExporter(exporter) {
|
|
27
|
-
super.addPropertiesToExporter(exporter);
|
|
28
|
-
exporter.addProperty("parentEntity", this.getParentEntity());
|
|
29
|
-
exporter.addProperty("aliasedEntity", this.getAliasedEntity());
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.Alias = Alias;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Association = void 0;
|
|
4
|
-
const famix_JSON_exporter_1 = require("../../famix_JSON_exporter");
|
|
5
|
-
const sourced_entity_1 = require("./sourced_entity");
|
|
6
|
-
class Association extends sourced_entity_1.SourcedEntity {
|
|
7
|
-
getNext() {
|
|
8
|
-
return this.next;
|
|
9
|
-
}
|
|
10
|
-
setNext(next) {
|
|
11
|
-
if (this.next === undefined) {
|
|
12
|
-
this.next = next;
|
|
13
|
-
next.setPrevious(this);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
getPrevious() {
|
|
17
|
-
return this.previous;
|
|
18
|
-
}
|
|
19
|
-
setPrevious(previous) {
|
|
20
|
-
if (this.previous === undefined) {
|
|
21
|
-
this.previous = previous;
|
|
22
|
-
previous.setNext(this);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
getJSON() {
|
|
26
|
-
const json = new famix_JSON_exporter_1.FamixJSONExporter("Association", this);
|
|
27
|
-
this.addPropertiesToExporter(json);
|
|
28
|
-
return json.getJSON();
|
|
29
|
-
}
|
|
30
|
-
addPropertiesToExporter(exporter) {
|
|
31
|
-
super.addPropertiesToExporter(exporter);
|
|
32
|
-
exporter.addProperty("next", this.getNext());
|
|
33
|
-
exporter.addProperty("previous", this.getPrevious());
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.Association = Association;
|