ts2famix 2.0.3 → 2.1.0-beta.2
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/.vscode/settings.json +4 -0
- package/LICENSE +24 -24
- package/README.md +78 -78
- package/TODO +1 -0
- package/arwea-fix.json +1 -0
- package/bogus.ts +3 -0
- package/class-diagram.puml +792 -0
- package/debug.txt +13332 -0
- package/debuglog.txt +12073 -0
- package/dist/analyze.js +19 -9
- package/dist/analyze_functions/process_functions.js +101 -71
- package/dist/famix2puml.js +126 -0
- package/dist/famix_functions/EntityDictionary.js +881 -509
- package/dist/famix_functions/helpers_creation.js +18 -8
- package/dist/fqn.js +44 -11
- package/dist/getClasses-arrow-body.js +43 -0
- package/dist/lib/famix/famix_JSON_exporter.js +1 -1
- package/dist/lib/famix/famix_base_element.js +1 -1
- package/dist/lib/famix/famix_repository.js +67 -2
- package/dist/lib/famix/index.js +18 -8
- package/dist/lib/famix/model/famix/access.js +1 -1
- package/dist/lib/famix/model/famix/accessor.js +1 -1
- package/dist/lib/famix/model/famix/alias.js +1 -1
- package/dist/lib/famix/model/famix/arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/behavioral_entity.js +1 -1
- package/dist/lib/famix/model/famix/class.js +1 -1
- package/dist/lib/famix/model/famix/comment.js +1 -1
- package/dist/lib/famix/model/famix/concretisation.js +1 -1
- package/dist/lib/famix/model/famix/container_entity.js +1 -1
- package/dist/lib/famix/model/famix/decorator.js +1 -1
- package/dist/lib/famix/model/famix/entity.js +1 -1
- package/dist/lib/famix/model/famix/enum.js +1 -1
- package/dist/lib/famix/model/famix/enum_value.js +1 -1
- package/dist/lib/famix/model/famix/function.js +1 -1
- package/dist/lib/famix/model/famix/import_clause.js +1 -1
- package/dist/lib/famix/model/famix/index.js +1 -1
- package/dist/lib/famix/model/famix/indexed_file_anchor.js +1 -1
- package/dist/lib/famix/model/famix/inheritance.js +1 -1
- package/dist/lib/famix/model/famix/interface.js +1 -1
- package/dist/lib/famix/model/famix/invocation.js +1 -1
- package/dist/lib/famix/model/famix/method.js +1 -1
- package/dist/lib/famix/model/famix/module.js +1 -1
- package/dist/lib/famix/model/famix/named_entity.js +1 -1
- package/dist/lib/famix/model/famix/parameter.js +1 -1
- package/dist/lib/famix/model/famix/parameter_concretisation.js +1 -1
- package/dist/lib/famix/model/famix/parameter_type.js +1 -1
- package/dist/lib/famix/model/famix/parametric_arrow_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_class.js +1 -1
- package/dist/lib/famix/model/famix/parametric_function.js +1 -1
- package/dist/lib/famix/model/famix/parametric_interface.js +1 -1
- package/dist/lib/famix/model/famix/parametric_method.js +1 -1
- package/dist/lib/famix/model/famix/primitive_type.js +1 -1
- package/dist/lib/famix/model/famix/property.js +1 -1
- package/dist/lib/famix/model/famix/reference.js +1 -1
- package/dist/lib/famix/model/famix/scoping_entity.js +1 -1
- package/dist/lib/famix/model/famix/script_entity.js +1 -1
- package/dist/lib/famix/model/famix/source_anchor.js +1 -1
- package/dist/lib/famix/model/famix/source_language.js +1 -1
- package/dist/lib/famix/model/famix/sourced_entity.js +1 -1
- package/dist/lib/famix/model/famix/structural_entity.js +1 -1
- package/dist/lib/famix/model/famix/type.js +1 -1
- package/dist/lib/famix/model/famix/variable.js +1 -1
- package/dist/lib/famix/src/famix_JSON_exporter.js +55 -0
- package/dist/lib/famix/src/famix_base_element.js +18 -0
- package/dist/lib/famix/src/famix_repository.js +224 -0
- package/dist/lib/famix/src/index.js +31 -0
- package/dist/lib/famix/src/model/famix/access.js +40 -0
- package/dist/lib/famix/src/model/famix/accessor.js +17 -0
- package/dist/lib/famix/src/model/famix/alias.js +33 -0
- package/dist/lib/famix/src/model/famix/arrowFunction.js +17 -0
- package/dist/lib/famix/src/model/famix/arrow_function.js +17 -0
- package/dist/lib/famix/src/model/famix/behavioral_entity.js +79 -0
- package/dist/lib/famix/src/model/famix/class.js +71 -0
- package/dist/lib/famix/src/model/famix/comment.js +39 -0
- package/dist/lib/famix/src/model/famix/concretisation.js +31 -0
- package/dist/lib/famix/src/model/famix/container_entity.js +126 -0
- package/dist/lib/famix/src/model/famix/decorator.js +32 -0
- package/dist/lib/famix/src/model/famix/entity.js +17 -0
- package/dist/lib/famix/src/model/famix/enum.js +31 -0
- package/dist/lib/famix/src/model/famix/enum_value.js +25 -0
- package/dist/lib/famix/src/model/famix/function.js +17 -0
- package/dist/lib/famix/src/model/famix/implicit_variable.js +17 -0
- package/dist/lib/famix/src/model/famix/import_clause.js +41 -0
- package/dist/lib/famix/src/model/famix/index.js +86 -0
- package/dist/lib/famix/src/model/famix/indexed_file_anchor.js +38 -0
- package/dist/lib/famix/src/model/famix/inheritance.js +33 -0
- package/dist/lib/famix/src/model/famix/interface.js +64 -0
- package/dist/lib/famix/src/model/famix/invocation.js +54 -0
- package/dist/lib/famix/src/model/famix/method.js +67 -0
- package/dist/lib/famix/src/model/famix/module.js +60 -0
- package/dist/lib/famix/src/model/famix/named_entity.js +78 -0
- package/dist/lib/famix/src/model/famix/parameter.js +25 -0
- package/dist/lib/famix/src/model/famix/parameterConcretisation.js +44 -0
- package/dist/lib/famix/src/model/famix/parameter_concretisation.js +44 -0
- package/dist/lib/famix/src/model/famix/parameter_type.js +45 -0
- package/dist/lib/famix/src/model/famix/parametricArrowFunction.js +29 -0
- package/dist/lib/famix/src/model/famix/parametric_arrow_function.js +31 -0
- package/dist/lib/famix/src/model/famix/parametric_class.js +44 -0
- package/dist/lib/famix/src/model/famix/parametric_function.js +31 -0
- package/dist/lib/famix/src/model/famix/parametric_interface.js +44 -0
- package/dist/lib/famix/src/model/famix/parametric_method.js +31 -0
- package/dist/lib/famix/src/model/famix/primitive_type.js +17 -0
- package/dist/lib/famix/src/model/famix/property.js +73 -0
- package/dist/lib/famix/src/model/famix/reference.js +33 -0
- package/dist/lib/famix/src/model/famix/scoping_entity.js +36 -0
- package/dist/lib/famix/src/model/famix/script_entity.js +29 -0
- package/dist/lib/famix/src/model/famix/source_anchor.js +27 -0
- package/dist/lib/famix/src/model/famix/source_language.js +35 -0
- package/dist/lib/famix/src/model/famix/sourced_entity.js +60 -0
- package/dist/lib/famix/src/model/famix/structural_entity.js +39 -0
- package/dist/lib/famix/src/model/famix/text_anchor.js +38 -0
- package/dist/lib/famix/src/model/famix/type.js +73 -0
- package/dist/lib/famix/src/model/famix/variable.js +24 -0
- package/dist/lib/ts-complex/cyclomatic-service.js +1 -1
- package/dist/refactorer/refactor-getter-setter.js +18 -8
- package/dist/ts2famix-cli-wrapper.js +18 -8
- package/dist/ts2famix-cli.js +18 -8
- package/dist/ts2famix-tsconfig.js +18 -8
- package/doc-uml/famix-typescript-model.puml +607 -607
- package/eslint.config.mjs +28 -0
- package/fqn-model.json +1 -0
- package/iterateGenericTypes.ts +69 -0
- package/out/class-diagram/class-diagram.svg +1 -0
- package/package.json +70 -66
- package/sample.json +1 -0
- package/sample.ts +1 -0
- package/src/analyze.ts +120 -120
- package/src/analyze_functions/process_functions.ts +1040 -1019
- package/src/famix_functions/EntityDictionary.ts +2016 -1593
- package/src/famix_functions/helpers_creation.ts +135 -135
- package/src/fqn.ts +50 -16
- package/src/generate_uml.sh +20 -20
- package/src/lib/famix/License.md +22 -22
- package/src/lib/famix/famix_JSON_exporter.ts +56 -56
- package/src/lib/famix/famix_base_element.ts +22 -22
- package/src/lib/famix/famix_repository.ts +278 -243
- package/src/lib/famix/index.ts +8 -8
- package/src/lib/famix/model/famix/access.ts +50 -50
- package/src/lib/famix/model/famix/accessor.ts +15 -15
- package/src/lib/famix/model/famix/alias.ts +39 -39
- package/src/lib/famix/model/famix/arrow_function.ts +15 -15
- package/src/lib/famix/model/famix/behavioral_entity.ts +97 -97
- package/src/lib/famix/model/famix/class.ts +85 -85
- package/src/lib/famix/model/famix/comment.ts +47 -47
- package/src/lib/famix/model/famix/concretisation.ts +40 -40
- package/src/lib/famix/model/famix/container_entity.ts +160 -160
- package/src/lib/famix/model/famix/decorator.ts +37 -37
- package/src/lib/famix/model/famix/entity.ts +15 -15
- package/src/lib/famix/model/famix/enum.ts +30 -30
- package/src/lib/famix/model/famix/enum_value.ts +28 -28
- package/src/lib/famix/model/famix/function.ts +15 -15
- package/src/lib/famix/model/famix/import_clause.ts +51 -51
- package/src/lib/famix/model/famix/index.ts +41 -41
- package/src/lib/famix/model/famix/indexed_file_anchor.ts +46 -46
- package/src/lib/famix/model/famix/inheritance.ts +40 -40
- package/src/lib/famix/model/famix/interface.ts +75 -75
- package/src/lib/famix/model/famix/invocation.ts +65 -65
- package/src/lib/famix/model/famix/method.ts +89 -89
- package/src/lib/famix/model/famix/module.ts +71 -71
- package/src/lib/famix/model/famix/named_entity.ts +95 -95
- package/src/lib/famix/model/famix/parameter.ts +28 -28
- package/src/lib/famix/model/famix/parameter_concretisation.ts +51 -51
- package/src/lib/famix/model/famix/parameter_type.ts +58 -58
- package/src/lib/famix/model/famix/parametric_arrow_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_class.ts +49 -49
- package/src/lib/famix/model/famix/parametric_function.ts +32 -32
- package/src/lib/famix/model/famix/parametric_interface.ts +49 -49
- package/src/lib/famix/model/famix/parametric_method.ts +32 -32
- package/src/lib/famix/model/famix/primitive_type.ts +15 -15
- package/src/lib/famix/model/famix/property.ts +94 -94
- package/src/lib/famix/model/famix/reference.ts +40 -40
- package/src/lib/famix/model/famix/scoping_entity.ts +35 -35
- package/src/lib/famix/model/famix/script_entity.ts +34 -34
- package/src/lib/famix/model/famix/source_anchor.ts +30 -30
- package/src/lib/famix/model/famix/source_language.ts +35 -35
- package/src/lib/famix/model/famix/sourced_entity.ts +70 -70
- package/src/lib/famix/model/famix/structural_entity.ts +43 -43
- package/src/lib/famix/model/famix/type.ts +87 -87
- package/src/lib/famix/model/famix/variable.ts +27 -27
- package/src/lib/famix/package.json +28 -28
- package/src/lib/ts-complex/cyclomatic-service.ts +83 -83
- package/src/refactorer/refactor-getter-setter.ts +140 -140
- package/src/ts2famix-cli-wrapper.ts +21 -21
- package/src/ts2famix-cli.ts +60 -60
- package/stats.txt +3091 -0
- package/tabby-debug-output.txt +19433 -0
- package/ts2famix.log +22656 -0
- package/tsconfig.check-tests.json +14 -14
- package/tsconfig.json +72 -72
- package/validate-references.js +103 -0
package/package.json
CHANGED
|
@@ -1,66 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ts2famix",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "A TypeScript to JSON importer for Moose.",
|
|
5
|
-
"main": "dist/ts2famix-cli.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "ts-node src/ts2famix-cli.ts",
|
|
8
|
-
"debug": "node --inspect-brk node_modules/.bin/ts-node",
|
|
9
|
-
"build": "tsc",
|
|
10
|
-
"check-tests": "tsc --project tsconfig.check-tests.json",
|
|
11
|
-
"test": "jest --colors --silent",
|
|
12
|
-
"local": "sudo npm i -g && ts2famix",
|
|
13
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
14
|
-
"doc": "typedoc && touch docs/.gitkeep",
|
|
15
|
-
"coverage": "jest --colors --silent --coverage --coverageDirectory=coverage",
|
|
16
|
-
"uml": "./src/generate_uml.sh"
|
|
17
|
-
},
|
|
18
|
-
"bin": {
|
|
19
|
-
"ts2famix": "dist/ts2famix-cli-wrapper.js"
|
|
20
|
-
},
|
|
21
|
-
"keywords": [
|
|
22
|
-
"TypeScript",
|
|
23
|
-
"famix",
|
|
24
|
-
"static analysis",
|
|
25
|
-
"moose"
|
|
26
|
-
],
|
|
27
|
-
"author": "Christopher Fuhrman <christopher.fuhrman@etsmtl.ca>",
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "https://github.com/fuhrmanator/FamixTypeScriptImporter.git"
|
|
31
|
-
},
|
|
32
|
-
"bugs": {
|
|
33
|
-
"url": "https://github.com/fuhrmanator/FamixTypeScriptImporter/issues"
|
|
34
|
-
},
|
|
35
|
-
"homepage": "https://github.com/fuhrmanator/FamixTypeScriptImporter?tab=readme-ov-file#famixtypescriptimporter",
|
|
36
|
-
"nodemonConfig": {
|
|
37
|
-
"ignore": [
|
|
38
|
-
"dist/*"
|
|
39
|
-
]
|
|
40
|
-
},
|
|
41
|
-
"license": "MIT",
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "ts2famix",
|
|
3
|
+
"version": "2.1.0-beta.2",
|
|
4
|
+
"description": "A TypeScript to JSON importer for Moose.",
|
|
5
|
+
"main": "dist/ts2famix-cli.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "ts-node src/ts2famix-cli.ts",
|
|
8
|
+
"debug": "node --inspect-brk node_modules/.bin/ts-node",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"check-tests": "tsc --project tsconfig.check-tests.json",
|
|
11
|
+
"test": "jest --colors --silent",
|
|
12
|
+
"local": "sudo npm i -g && ts2famix",
|
|
13
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
14
|
+
"doc": "typedoc && touch docs/.gitkeep",
|
|
15
|
+
"coverage": "jest --colors --silent --coverage --coverageDirectory=coverage",
|
|
16
|
+
"uml": "./src/generate_uml.sh"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"ts2famix": "dist/ts2famix-cli-wrapper.js"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"TypeScript",
|
|
23
|
+
"famix",
|
|
24
|
+
"static analysis",
|
|
25
|
+
"moose"
|
|
26
|
+
],
|
|
27
|
+
"author": "Christopher Fuhrman <christopher.fuhrman@etsmtl.ca>",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/fuhrmanator/FamixTypeScriptImporter.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/fuhrmanator/FamixTypeScriptImporter/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/fuhrmanator/FamixTypeScriptImporter?tab=readme-ov-file#famixtypescriptimporter",
|
|
36
|
+
"nodemonConfig": {
|
|
37
|
+
"ignore": [
|
|
38
|
+
"dist/*"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.22.0",
|
|
44
|
+
"@types/jest": "^29.5.14",
|
|
45
|
+
"@types/lodash": "^4.17.16",
|
|
46
|
+
"@types/node": "^22.13.10",
|
|
47
|
+
"@types/yargs": "^17.0.33",
|
|
48
|
+
"eslint": "^9.22.0",
|
|
49
|
+
"globals": "^16.0.0",
|
|
50
|
+
"jest": "^29.7.0",
|
|
51
|
+
"jscpd": "^4.0.5",
|
|
52
|
+
"tplant": "^3.1.0",
|
|
53
|
+
"ts-jest": "^29.2.6",
|
|
54
|
+
"ts-node": "^10.9.2",
|
|
55
|
+
"typedoc": "^0.28.0",
|
|
56
|
+
"typescript-eslint": "^8.26.1"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"grapheme-splitter": "^1.0.4",
|
|
60
|
+
"lodash": "^4.17.21",
|
|
61
|
+
"ts-morph": "^25.0.1",
|
|
62
|
+
"tslog": "^4.9.2",
|
|
63
|
+
"tsutils": "^3.21.0",
|
|
64
|
+
"typescript": "^5.8.2",
|
|
65
|
+
"yargs": "^17.7.2"
|
|
66
|
+
},
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18.20.4"
|
|
69
|
+
}
|
|
70
|
+
}
|
package/sample.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[{"FM3":"FamixTypeScript.SourceLanguage","id":1,"sourcedEntities":[]},{"FM3":"FamixTypeScript.IndexedFileAnchor","id":2,"element":{"ref":3},"startPos":1,"endPos":13,"fileName":":/Users/Cris/Documents/GitHub/FamixTypeScriptImporter/sample.ts"},{"FM3":"FamixTypeScript.ScriptEntity","id":3,"sourceAnchor":{"ref":2},"comments":[],"incomingImports":[],"name":"sample.ts","decorators":[],"types":[{"ref":5}],"functions":[],"localVariables":[]},{"FM3":"FamixTypeScript.IndexedFileAnchor","id":4,"element":{"ref":5},"startPos":1,"endPos":11,"fileName":":/Users/Cris/Documents/GitHub/FamixTypeScriptImporter/sample.ts"},{"FM3":"FamixTypeScript.Class","id":5,"sourceAnchor":{"ref":4},"comments":[],"incomingImports":[],"name":"A","decorators":[],"types":[],"functions":[],"localVariables":[],"incomingReferences":[],"isAbstract":false,"attributes":[],"methods":[],"superInheritances":[],"subInheritances":[]}]
|
package/sample.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class A {}
|
package/src/analyze.ts
CHANGED
|
@@ -1,120 +1,120 @@
|
|
|
1
|
-
import { Project } from "ts-morph";
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import { FamixRepository } from "./lib/famix/famix_repository";
|
|
4
|
-
import { Logger } from "tslog";
|
|
5
|
-
import * as processFunctions from "./analyze_functions/process_functions";
|
|
6
|
-
import { EntityDictionary } from "./famix_functions/EntityDictionary";
|
|
7
|
-
import path from "path";
|
|
8
|
-
|
|
9
|
-
export const logger = new Logger({ name: "ts2famix", minLevel: 3 });
|
|
10
|
-
export const config = { "expectGraphemes": false };
|
|
11
|
-
export const entityDictionary = new EntityDictionary();
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This class is used to build a Famix model from a TypeScript source code
|
|
15
|
-
*/
|
|
16
|
-
export class Importer {
|
|
17
|
-
|
|
18
|
-
private project = new Project(
|
|
19
|
-
{
|
|
20
|
-
compilerOptions: {
|
|
21
|
-
baseUrl: "./test_src"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
); // The project containing the source files to analyze
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Main method
|
|
28
|
-
* @param paths An array of paths to the source files to analyze
|
|
29
|
-
* @returns The Famix repository containing the Famix model
|
|
30
|
-
*/
|
|
31
|
-
public famixRepFromPaths(paths: Array<string>): FamixRepository {
|
|
32
|
-
|
|
33
|
-
// try {
|
|
34
|
-
logger.debug(`famixRepFromPaths: paths: ${paths}`);
|
|
35
|
-
|
|
36
|
-
this.project.addSourceFilesAtPaths(paths);
|
|
37
|
-
|
|
38
|
-
initFamixRep(this.project);
|
|
39
|
-
|
|
40
|
-
this.processEntities(this.project);
|
|
41
|
-
|
|
42
|
-
const famixRep = entityDictionary.famixRep;
|
|
43
|
-
// }
|
|
44
|
-
// catch (error) {
|
|
45
|
-
// logger.error(`> ERROR: got exception ${error}. Exiting...`);
|
|
46
|
-
// logger.error(error.message);
|
|
47
|
-
// logger.error(error.stack);
|
|
48
|
-
// process.exit(1);
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
return famixRep;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private processEntities(project: Project): void {
|
|
55
|
-
const onlyTypeScriptFiles = project.getSourceFiles().filter(f => f.getFilePath().endsWith('.ts'));
|
|
56
|
-
processFunctions.processFiles(onlyTypeScriptFiles);
|
|
57
|
-
const accesses = processFunctions.accessMap;
|
|
58
|
-
const methodsAndFunctionsWithId = processFunctions.methodsAndFunctionsWithId;
|
|
59
|
-
const classes = processFunctions.classes;
|
|
60
|
-
const interfaces = processFunctions.interfaces;
|
|
61
|
-
const modules = processFunctions.modules;
|
|
62
|
-
const exports = processFunctions.listOfExportMaps;
|
|
63
|
-
|
|
64
|
-
processFunctions.processImportClausesForImportEqualsDeclarations(project.getSourceFiles(), exports);
|
|
65
|
-
processFunctions.processImportClausesForModules(modules, exports);
|
|
66
|
-
processFunctions.processAccesses(accesses);
|
|
67
|
-
processFunctions.processInvocations(methodsAndFunctionsWithId);
|
|
68
|
-
processFunctions.processInheritances(classes, interfaces);
|
|
69
|
-
processFunctions.processConcretisations(classes, interfaces, methodsAndFunctionsWithId);
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Main method for tests
|
|
75
|
-
*
|
|
76
|
-
* @param filename The name of the file to analyze
|
|
77
|
-
* @param source A TypeScript source code
|
|
78
|
-
* @returns The Famix repository containing the Famix model
|
|
79
|
-
*/
|
|
80
|
-
// TODO: this is slow because it writes the source code to a file and then reads it again - it's possible to just pass the source code to the ts-morph project
|
|
81
|
-
public famixRepFromSource(filename: string, source: string): FamixRepository {
|
|
82
|
-
const filePath = `./test_src/${filename}.ts`;
|
|
83
|
-
|
|
84
|
-
fs.writeFileSync(filePath, source, 'utf-8');
|
|
85
|
-
|
|
86
|
-
const famixRep = this.famixRepFromPaths([filePath]);
|
|
87
|
-
|
|
88
|
-
return famixRep;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Main method for a ts-morph project
|
|
93
|
-
* @param project A ts-morph project
|
|
94
|
-
* @returns The Famix repository containing the Famix model
|
|
95
|
-
*/
|
|
96
|
-
public famixRepFromProject(project: Project): FamixRepository {
|
|
97
|
-
//const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
|
|
98
|
-
|
|
99
|
-
//const famixRep = this.famixRepFromPaths(sourceFileNames);
|
|
100
|
-
|
|
101
|
-
initFamixRep(project);
|
|
102
|
-
|
|
103
|
-
this.processEntities(project);
|
|
104
|
-
|
|
105
|
-
return entityDictionary.famixRep;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function initFamixRep(project: Project): void {
|
|
111
|
-
// get compiler options
|
|
112
|
-
const compilerOptions = project.getCompilerOptions();
|
|
113
|
-
|
|
114
|
-
// get baseUrl
|
|
115
|
-
const baseUrl = compilerOptions.baseUrl || ".";
|
|
116
|
-
|
|
117
|
-
const absoluteBaseUrl = path.resolve(baseUrl);
|
|
118
|
-
|
|
119
|
-
entityDictionary.famixRep.setAbsolutePath(path.normalize(absoluteBaseUrl));
|
|
120
|
-
}
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { FamixRepository } from "./lib/famix/famix_repository";
|
|
4
|
+
import { Logger } from "tslog";
|
|
5
|
+
import * as processFunctions from "./analyze_functions/process_functions";
|
|
6
|
+
import { EntityDictionary } from "./famix_functions/EntityDictionary";
|
|
7
|
+
import path from "path";
|
|
8
|
+
|
|
9
|
+
export const logger = new Logger({ name: "ts2famix", minLevel: 3 });
|
|
10
|
+
export const config = { "expectGraphemes": false };
|
|
11
|
+
export const entityDictionary = new EntityDictionary();
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This class is used to build a Famix model from a TypeScript source code
|
|
15
|
+
*/
|
|
16
|
+
export class Importer {
|
|
17
|
+
|
|
18
|
+
private project = new Project(
|
|
19
|
+
{
|
|
20
|
+
compilerOptions: {
|
|
21
|
+
baseUrl: "./test_src"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
); // The project containing the source files to analyze
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Main method
|
|
28
|
+
* @param paths An array of paths to the source files to analyze
|
|
29
|
+
* @returns The Famix repository containing the Famix model
|
|
30
|
+
*/
|
|
31
|
+
public famixRepFromPaths(paths: Array<string>): FamixRepository {
|
|
32
|
+
|
|
33
|
+
// try {
|
|
34
|
+
logger.debug(`famixRepFromPaths: paths: ${paths}`);
|
|
35
|
+
|
|
36
|
+
this.project.addSourceFilesAtPaths(paths);
|
|
37
|
+
|
|
38
|
+
initFamixRep(this.project);
|
|
39
|
+
|
|
40
|
+
this.processEntities(this.project);
|
|
41
|
+
|
|
42
|
+
const famixRep = entityDictionary.famixRep;
|
|
43
|
+
// }
|
|
44
|
+
// catch (error) {
|
|
45
|
+
// logger.error(`> ERROR: got exception ${error}. Exiting...`);
|
|
46
|
+
// logger.error(error.message);
|
|
47
|
+
// logger.error(error.stack);
|
|
48
|
+
// process.exit(1);
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
return famixRep;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private processEntities(project: Project): void {
|
|
55
|
+
const onlyTypeScriptFiles = project.getSourceFiles().filter(f => f.getFilePath().endsWith('.ts'));
|
|
56
|
+
processFunctions.processFiles(onlyTypeScriptFiles);
|
|
57
|
+
const accesses = processFunctions.accessMap;
|
|
58
|
+
const methodsAndFunctionsWithId = processFunctions.methodsAndFunctionsWithId;
|
|
59
|
+
const classes = processFunctions.classes;
|
|
60
|
+
const interfaces = processFunctions.interfaces;
|
|
61
|
+
const modules = processFunctions.modules;
|
|
62
|
+
const exports = processFunctions.listOfExportMaps;
|
|
63
|
+
|
|
64
|
+
processFunctions.processImportClausesForImportEqualsDeclarations(project.getSourceFiles(), exports);
|
|
65
|
+
processFunctions.processImportClausesForModules(modules, exports);
|
|
66
|
+
processFunctions.processAccesses(accesses);
|
|
67
|
+
processFunctions.processInvocations(methodsAndFunctionsWithId);
|
|
68
|
+
processFunctions.processInheritances(classes, interfaces);
|
|
69
|
+
// processFunctions.processConcretisations(classes, interfaces, methodsAndFunctionsWithId);
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Main method for tests
|
|
75
|
+
*
|
|
76
|
+
* @param filename The name of the file to analyze
|
|
77
|
+
* @param source A TypeScript source code
|
|
78
|
+
* @returns The Famix repository containing the Famix model
|
|
79
|
+
*/
|
|
80
|
+
// TODO: this is slow because it writes the source code to a file and then reads it again - it's possible to just pass the source code to the ts-morph project
|
|
81
|
+
public famixRepFromSource(filename: string, source: string): FamixRepository {
|
|
82
|
+
const filePath = `./test_src/${filename}.ts`;
|
|
83
|
+
|
|
84
|
+
fs.writeFileSync(filePath, source, 'utf-8');
|
|
85
|
+
|
|
86
|
+
const famixRep = this.famixRepFromPaths([filePath]);
|
|
87
|
+
|
|
88
|
+
return famixRep;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Main method for a ts-morph project
|
|
93
|
+
* @param project A ts-morph project
|
|
94
|
+
* @returns The Famix repository containing the Famix model
|
|
95
|
+
*/
|
|
96
|
+
public famixRepFromProject(project: Project): FamixRepository {
|
|
97
|
+
//const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
|
|
98
|
+
|
|
99
|
+
//const famixRep = this.famixRepFromPaths(sourceFileNames);
|
|
100
|
+
|
|
101
|
+
initFamixRep(project);
|
|
102
|
+
|
|
103
|
+
this.processEntities(project);
|
|
104
|
+
|
|
105
|
+
return entityDictionary.famixRep;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function initFamixRep(project: Project): void {
|
|
111
|
+
// get compiler options
|
|
112
|
+
const compilerOptions = project.getCompilerOptions();
|
|
113
|
+
|
|
114
|
+
// get baseUrl
|
|
115
|
+
const baseUrl = compilerOptions.baseUrl || ".";
|
|
116
|
+
|
|
117
|
+
const absoluteBaseUrl = path.resolve(baseUrl);
|
|
118
|
+
|
|
119
|
+
entityDictionary.famixRep.setAbsolutePath(path.normalize(absoluteBaseUrl));
|
|
120
|
+
}
|