ts2famix 1.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/.eslintrc.json +24 -0
- package/.github/workflows/node.js.yml +60 -0
- package/LICENSE +23 -0
- package/README.md +111 -0
- package/doc-metamodel/skins.include.puml +2 -0
- package/jest.config.ts +199 -0
- package/package.json +47 -0
- package/src/analyze.ts +90 -0
- package/src/analyze_functions/processAccesses.ts +50 -0
- package/src/analyze_functions/processFiles.ts +656 -0
- package/src/analyze_functions/processImportClauses.ts +77 -0
- package/src/analyze_functions/processInheritances.ts +84 -0
- package/src/analyze_functions/processInvocations.ts +51 -0
- package/src/famix2puml.ts +119 -0
- package/src/famix_functions/famix_functions.ts +552 -0
- package/src/famix_functions/famix_functions_associations.ts +208 -0
- package/src/famix_functions/famix_functions_index.ts +44 -0
- package/src/famix_functions/famix_functions_types.ts +100 -0
- package/src/fqn.ts +127 -0
- package/src/fqp_implementation.ts +66 -0
- package/src/generate_uml.sh +16 -0
- package/src/lib/famix/License.md +23 -0
- package/src/lib/famix/package-lock.json +301 -0
- package/src/lib/famix/package.json +28 -0
- package/src/lib/famix/readme.md +5 -0
- package/src/lib/famix/src/famix_JSON_exporter.ts +56 -0
- package/src/lib/famix/src/famix_base_element.ts +18 -0
- package/src/lib/famix/src/famix_repository.ts +199 -0
- package/src/lib/famix/src/index.ts +8 -0
- package/src/lib/famix/src/model/famix/access.ts +53 -0
- package/src/lib/famix/src/model/famix/accessor.ts +15 -0
- package/src/lib/famix/src/model/famix/alias.ts +41 -0
- package/src/lib/famix/src/model/famix/association.ts +44 -0
- package/src/lib/famix/src/model/famix/behavioral_entity.ts +107 -0
- package/src/lib/famix/src/model/famix/c_source_language.ts +15 -0
- package/src/lib/famix/src/model/famix/class.ts +86 -0
- package/src/lib/famix/src/model/famix/comment.ts +50 -0
- package/src/lib/famix/src/model/famix/container_entity.ts +165 -0
- package/src/lib/famix/src/model/famix/custom_source_language.ts +27 -0
- package/src/lib/famix/src/model/famix/decorator.ts +39 -0
- package/src/lib/famix/src/model/famix/entity.ts +15 -0
- package/src/lib/famix/src/model/famix/enum.ts +31 -0
- package/src/lib/famix/src/model/famix/enum_value.ts +29 -0
- package/src/lib/famix/src/model/famix/function.ts +15 -0
- package/src/lib/famix/src/model/famix/implicit_variable.ts +15 -0
- package/src/lib/famix/src/model/famix/import_clause.ts +53 -0
- package/src/lib/famix/src/model/famix/index.ts +42 -0
- package/src/lib/famix/src/model/famix/indexed_file_anchor.ts +49 -0
- package/src/lib/famix/src/model/famix/inheritance.ts +42 -0
- package/src/lib/famix/src/model/famix/interface.ts +75 -0
- package/src/lib/famix/src/model/famix/invocation.ts +68 -0
- package/src/lib/famix/src/model/famix/method.ts +96 -0
- package/src/lib/famix/src/model/famix/module.ts +31 -0
- package/src/lib/famix/src/model/famix/named_entity.ts +98 -0
- package/src/lib/famix/src/model/famix/namespace.ts +28 -0
- package/src/lib/famix/src/model/famix/parameter.ts +29 -0
- package/src/lib/famix/src/model/famix/parameterizable_class.ts +31 -0
- package/src/lib/famix/src/model/famix/parameterizable_interface.ts +31 -0
- package/src/lib/famix/src/model/famix/parameterized_type.ts +40 -0
- package/src/lib/famix/src/model/famix/primitive_type.ts +15 -0
- package/src/lib/famix/src/model/famix/property.ts +54 -0
- package/src/lib/famix/src/model/famix/reference.ts +42 -0
- package/src/lib/famix/src/model/famix/scoping_entity.ts +31 -0
- package/src/lib/famix/src/model/famix/script_entity.ts +38 -0
- package/src/lib/famix/src/model/famix/source_anchor.ts +31 -0
- package/src/lib/famix/src/model/famix/source_language.ts +31 -0
- package/src/lib/famix/src/model/famix/sourced_entity.ts +70 -0
- package/src/lib/famix/src/model/famix/structural_entity.ts +44 -0
- package/src/lib/famix/src/model/famix/text_anchor.ts +49 -0
- package/src/lib/famix/src/model/famix/type.ts +88 -0
- package/src/lib/famix/src/model/famix/type_parameter.ts +33 -0
- package/src/lib/famix/src/model/famix/variable.ts +28 -0
- package/src/lib/famix/tsconfig.json +27 -0
- package/src/lib/famix/tslint.json +15 -0
- package/src/lib/ts-complex/cyclomatic-service.ts +85 -0
- package/src/ts2famix-cli.ts +26 -0
- package/src/ts2famix-tsconfig.ts +30 -0
- package/test/abstractClassWithComments.test.ts +58 -0
- package/test/abstracts.test.ts +53 -0
- package/test/access.test.ts +62 -0
- package/test/accesses.test.ts +42 -0
- package/test/accessorsWithDecorators.test.ts +98 -0
- package/test/alias.test.ts +39 -0
- package/test/classExtendsUndefinedClass.test.ts +41 -0
- package/test/classImplementsUndefinedInterface.test.ts +45 -0
- package/test/classWithDecorators.test.ts +65 -0
- package/test/entities.test.ts +232 -0
- package/test/entities_json.test.ts +48 -0
- package/test/enum.test.ts +55 -0
- package/test/functionReturnsFunction.test.ts +53 -0
- package/test/functionWithParameters.test.ts +38 -0
- package/test/functionWithVariables.test.ts +64 -0
- package/test/functions.test.ts +23 -0
- package/test/functionsInFunction.test.ts +40 -0
- package/test/functionsInMethod.test.ts +42 -0
- package/test/genericClass.test.ts +42 -0
- package/test/genericClassInheritsInterface.test.ts +47 -0
- package/test/genericInterface.test.ts +38 -0
- package/test/genericMethod.test.ts +65 -0
- package/test/genericWithInvocation.test.ts +71 -0
- package/test/generics.test.ts +68 -0
- package/test/inheritance.test.ts +50 -0
- package/test/interfaceInheritsInterface.test.ts +40 -0
- package/test/interfaceInheritsUndefinedInterface.test.ts +41 -0
- package/test/invocation.test.ts +94 -0
- package/test/invocationWithFunction.test.ts +42 -0
- package/test/invocationWithVariable.test.ts +46 -0
- package/test/invocation_json.test.ts +63 -0
- package/test/invocations.test.ts +131 -0
- package/test/jsDoc.test.ts +31 -0
- package/test/methodWithDecorator.test.ts +44 -0
- package/test/methods.test.ts +42 -0
- package/test/metrics.test.ts +51 -0
- package/test/module.test.ts +71 -0
- package/test/namespaces.test.ts +54 -0
- package/test/namespacesAndClasses.test.ts +66 -0
- package/test/parameterWithDecorators.test.ts +54 -0
- package/test/propertyWithDecorators.test.ts +80 -0
- package/test/sample.test.ts +13 -0
- package/test/simpleFunction.test.ts +32 -0
- package/test/simpleTest.test.ts +18 -0
- package/test/simpleTest2.test.ts +36 -0
- package/test/types.test.ts +58 -0
- package/test_src/sample.ts +103 -0
- package/test_src/sampleForModule.ts +10 -0
- package/test_src/sampleForModule2.ts +7 -0
- package/test_src/sampleForModule3.ts +2 -0
- package/tsconfig.json +70 -0
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"es2021": true
|
|
5
|
+
},
|
|
6
|
+
"extends": [
|
|
7
|
+
"eslint:recommended",
|
|
8
|
+
"plugin:@typescript-eslint/recommended"
|
|
9
|
+
],
|
|
10
|
+
"overrides": [
|
|
11
|
+
],
|
|
12
|
+
"parser": "@typescript-eslint/parser",
|
|
13
|
+
"parserOptions": {
|
|
14
|
+
"ecmaVersion": "latest",
|
|
15
|
+
"sourceType": "module"
|
|
16
|
+
},
|
|
17
|
+
"plugins": [
|
|
18
|
+
"@typescript-eslint"
|
|
19
|
+
],
|
|
20
|
+
"rules": {
|
|
21
|
+
"@typescript-eslint/no-namespace": "off",
|
|
22
|
+
"semi": [1, "always"]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# This workflow will do a clean install of node dependencies, cache/restore them, and run tests across different versions of node
|
|
2
|
+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
+
|
|
4
|
+
name: Node.js CI
|
|
5
|
+
|
|
6
|
+
permissions: write-all
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
branches: [ master ]
|
|
11
|
+
pull_request:
|
|
12
|
+
branches: [ master ]
|
|
13
|
+
|
|
14
|
+
# Allows you to run this workflow manually from the Actions tab
|
|
15
|
+
workflow_dispatch:
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
strategy:
|
|
23
|
+
matrix:
|
|
24
|
+
# node-version: [12.x, 14.x, 16.x]
|
|
25
|
+
node-version: [16.x]
|
|
26
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
27
|
+
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@v3
|
|
30
|
+
- uses: ts-graphviz/setup-graphviz@v1
|
|
31
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
32
|
+
uses: actions/setup-node@v3
|
|
33
|
+
with:
|
|
34
|
+
node-version: ${{ matrix.node-version }}
|
|
35
|
+
cache: 'npm'
|
|
36
|
+
- run: npm ci
|
|
37
|
+
- run: npm test
|
|
38
|
+
- run: npm run uml
|
|
39
|
+
|
|
40
|
+
- name: Init new repo in doc-uml folder and commit generated files
|
|
41
|
+
run: |
|
|
42
|
+
cd doc-uml/
|
|
43
|
+
git init
|
|
44
|
+
git add -A
|
|
45
|
+
git config --local user.email "action@github.com"
|
|
46
|
+
git config --local user.name "GitHub Action"
|
|
47
|
+
git commit -m 'update doc'
|
|
48
|
+
|
|
49
|
+
# Careful, this can kill your project, because it force pushes to the destination branch
|
|
50
|
+
- name: Force push to destination branch
|
|
51
|
+
uses: ad-m/github-push-action@master
|
|
52
|
+
with:
|
|
53
|
+
# Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}
|
|
54
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
55
|
+
force: true
|
|
56
|
+
# Destination branch to push changes
|
|
57
|
+
branch: v1/doc
|
|
58
|
+
# We have to push from the folder where files were generated.
|
|
59
|
+
# Same were the new repo was initialized in the previous step
|
|
60
|
+
directory: ./doc-uml
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Arezoo Nasrollah Zadeh
|
|
4
|
+
Copyright (c) 2021 Christopher Fuhrman
|
|
5
|
+
Copyright (c) 2023 Maël Paul
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# FamixTypeScriptImporter
|
|
2
|
+
|
|
3
|
+
[](https://github.com/maelpaul/FamixTypeScriptImporter/actions/workflows/node.js.yml)
|
|
4
|
+
|
|
5
|
+
Create a [FamixTypeScript](https://github.com/fuhrmanator/FamixTypeScript) model in JSON of TypeScript files.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
Instructions for using the command-line importer :
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
ts-node src/ts2famix-tsconfig.ts --help
|
|
19
|
+
```
|
|
20
|
+
or
|
|
21
|
+
```sh
|
|
22
|
+
ts-node src/ts2famix-cli.ts --help
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run tests :
|
|
26
|
+
```sh
|
|
27
|
+
npm test
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Generate coverage :
|
|
31
|
+
```sh
|
|
32
|
+
npm run coverage
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then, open "```coverage/lcov-report/index.html```" with your favorite browser :
|
|
36
|
+
```sh
|
|
37
|
+
firefox coverage/lcov-report/index.html &
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Generate documentation :
|
|
41
|
+
```sh
|
|
42
|
+
npm run doc
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then, open "```docs/index.html```" with your favorite browser :
|
|
46
|
+
```sh
|
|
47
|
+
firefox docs/index.html &
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Generate plantuml and svg of the metamodel :
|
|
51
|
+
```sh
|
|
52
|
+
npm run uml
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then, open "```doc-uml/metamodel.svg```" with your favorite image viewer :
|
|
56
|
+
```sh
|
|
57
|
+
eog doc-uml/metamodel.svg &
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Parse a full project
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
ts-node src/ts2famix-tsconfig.ts -i ../path/to/project/tsconfig.json -o JSONModels/projectName.json
|
|
64
|
+
```
|
|
65
|
+
or
|
|
66
|
+
```sh
|
|
67
|
+
ts-node src/ts2famix-cli.ts -i "../path/to/project/**/*.ts" -o JSONModels/projectName.json
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Generate an object diagram of the JSON model
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
ts-node src/famix2puml.ts -i JSONModels/projectName.json -o PUMLModels/projectName.puml
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Import the JSON model into Moose 🫎
|
|
77
|
+
|
|
78
|
+
You need to copy the "```JSONModels/projectName.json```" into your "```Pharo/images/[imageName]```" directory.
|
|
79
|
+
|
|
80
|
+
For a Moose Suite 10 (stable) user with the Pharo directory in the root directory, do :
|
|
81
|
+
```sh
|
|
82
|
+
cp JSONModels/projectName.json ~/Pharo/images/Moose\ Suite\ 10\ \(stable\)/.
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Then, in a Moose Playground, do :
|
|
86
|
+
```st
|
|
87
|
+
Metacello new
|
|
88
|
+
githubUser: 'fuhrmanator' project: 'FamixTypeScript' commitish: 'master' path: 'src';
|
|
89
|
+
baseline: 'FamixTypeScript';
|
|
90
|
+
load
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
This command installs the TypeScript metamodel into Moose.
|
|
94
|
+
|
|
95
|
+
Then, generate the metamodel with :
|
|
96
|
+
```Library > Famix > Manage metamodels > Regenerate all metamodels```
|
|
97
|
+
|
|
98
|
+
Then, in a Moose Playground, do :
|
|
99
|
+
```st
|
|
100
|
+
'projectName.json' asFileReference readStreamDo:
|
|
101
|
+
[ :stream | model := FamixTypeScriptModel new
|
|
102
|
+
importFromJSONStream: stream. model install ].
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This command imports the JSON model into Moose.
|
|
106
|
+
|
|
107
|
+
## TypeScript Metamodel API documentation (visualization)
|
|
108
|
+
|
|
109
|
+
The following was generated by CI using [tplant](https://github.com/bafolts/tplant), in a similar fashion described [here](https://modularmoose.org/2021/07/19/automatic-metamodel-documentation-generation.html).
|
|
110
|
+
|
|
111
|
+

|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
+
* https://jestjs.io/docs/configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
// All imported modules in your tests should be mocked automatically
|
|
8
|
+
// automock: false,
|
|
9
|
+
|
|
10
|
+
// Stop running tests after `n` failures
|
|
11
|
+
// bail: 0,
|
|
12
|
+
|
|
13
|
+
// The directory where Jest should store its cached dependency information
|
|
14
|
+
// cacheDirectory: "",
|
|
15
|
+
|
|
16
|
+
// Automatically clear mock calls and instances between every test
|
|
17
|
+
// clearMocks: false,
|
|
18
|
+
|
|
19
|
+
// Indicates whether the coverage information should be collected while executing the test
|
|
20
|
+
collectCoverage: false,
|
|
21
|
+
|
|
22
|
+
// An array of glob patterns indicating a set of files for which coverage information should be collected
|
|
23
|
+
// collectCoverageFrom: undefined,
|
|
24
|
+
|
|
25
|
+
// The directory where Jest should output its coverage files
|
|
26
|
+
coverageDirectory: "coverage",
|
|
27
|
+
|
|
28
|
+
// An array of regexp pattern strings used to skip coverage collection
|
|
29
|
+
// coveragePathIgnorePatterns: [
|
|
30
|
+
// "\\\\node_modules\\\\"
|
|
31
|
+
// ],
|
|
32
|
+
|
|
33
|
+
// Indicates which provider should be used to instrument code for coverage
|
|
34
|
+
coverageProvider: "babel",
|
|
35
|
+
|
|
36
|
+
// A list of reporter names that Jest uses when writing coverage reports
|
|
37
|
+
// coverageReporters: [
|
|
38
|
+
// "json",
|
|
39
|
+
// "text",
|
|
40
|
+
// "lcov",
|
|
41
|
+
// "clover"
|
|
42
|
+
// ],
|
|
43
|
+
|
|
44
|
+
// An object that configures minimum threshold enforcement for coverage results
|
|
45
|
+
// coverageThreshold: undefined,
|
|
46
|
+
|
|
47
|
+
// A path to a custom dependency extractor
|
|
48
|
+
// dependencyExtractor: undefined,
|
|
49
|
+
|
|
50
|
+
// Make calling deprecated APIs throw helpful error messages
|
|
51
|
+
// errorOnDeprecated: false,
|
|
52
|
+
|
|
53
|
+
// Force coverage collection from ignored files using an array of glob patterns
|
|
54
|
+
// forceCoverageMatch: [],
|
|
55
|
+
|
|
56
|
+
// A path to a module which exports an async function that is triggered once before all test suites
|
|
57
|
+
// globalSetup: undefined,
|
|
58
|
+
|
|
59
|
+
// A path to a module which exports an async function that is triggered once after all test suites
|
|
60
|
+
// globalTeardown: undefined,
|
|
61
|
+
|
|
62
|
+
// A set of global variables that need to be available in all test environments
|
|
63
|
+
// globals: {},
|
|
64
|
+
|
|
65
|
+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
|
|
66
|
+
// maxWorkers: 1,
|
|
67
|
+
|
|
68
|
+
// An array of directory names to be searched recursively up from the requiring module's location
|
|
69
|
+
// moduleDirectories: [
|
|
70
|
+
// "node_modules"
|
|
71
|
+
// ],
|
|
72
|
+
|
|
73
|
+
// An array of file extensions your modules use
|
|
74
|
+
// moduleFileExtensions: [
|
|
75
|
+
// "js",
|
|
76
|
+
// "jsx",
|
|
77
|
+
// "ts",
|
|
78
|
+
// "tsx",
|
|
79
|
+
// "json",
|
|
80
|
+
// "node"
|
|
81
|
+
// ],
|
|
82
|
+
|
|
83
|
+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
|
|
84
|
+
// moduleNameMapper: {},
|
|
85
|
+
|
|
86
|
+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
|
|
87
|
+
// modulePathIgnorePatterns: [],
|
|
88
|
+
|
|
89
|
+
// Activates notifications for test results
|
|
90
|
+
// notify: false,
|
|
91
|
+
|
|
92
|
+
// An enum that specifies notification mode. Requires { notify: true }
|
|
93
|
+
// notifyMode: "failure-change",
|
|
94
|
+
|
|
95
|
+
// A preset that is used as a base for Jest's configuration
|
|
96
|
+
// preset: undefined,
|
|
97
|
+
|
|
98
|
+
// Run tests from one or more projects
|
|
99
|
+
// projects: undefined,
|
|
100
|
+
|
|
101
|
+
// Use this configuration option to add custom reporters to Jest
|
|
102
|
+
// reporters: undefined,
|
|
103
|
+
|
|
104
|
+
// Automatically reset mock state between every test
|
|
105
|
+
// resetMocks: false,
|
|
106
|
+
|
|
107
|
+
// Reset the module registry before running each individual test
|
|
108
|
+
// resetModules: false,
|
|
109
|
+
|
|
110
|
+
// A path to a custom resolver
|
|
111
|
+
// resolver: undefined,
|
|
112
|
+
|
|
113
|
+
// Automatically restore mock state between every test
|
|
114
|
+
// restoreMocks: false,
|
|
115
|
+
|
|
116
|
+
// The root directory that Jest should scan for tests and modules within
|
|
117
|
+
// rootDir: undefined,
|
|
118
|
+
|
|
119
|
+
// A list of paths to directories that Jest should use to search for files in
|
|
120
|
+
// roots: [
|
|
121
|
+
// "<rootDir>"
|
|
122
|
+
// ],
|
|
123
|
+
|
|
124
|
+
// Allows you to use a custom runner instead of Jest's default test runner
|
|
125
|
+
// runner: "jest-runner",
|
|
126
|
+
|
|
127
|
+
// The paths to modules that run some code to configure or set up the testing environment before each test
|
|
128
|
+
// setupFiles: [],
|
|
129
|
+
|
|
130
|
+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
|
|
131
|
+
// setupFilesAfterEnv: [],
|
|
132
|
+
|
|
133
|
+
// The number of seconds after which a test is considered as slow and reported as such in the results.
|
|
134
|
+
// slowTestThreshold: 5,
|
|
135
|
+
|
|
136
|
+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
|
|
137
|
+
// snapshotSerializers: [],
|
|
138
|
+
|
|
139
|
+
// The test environment that will be used for testing
|
|
140
|
+
testEnvironment: "jest-environment-node",
|
|
141
|
+
|
|
142
|
+
// Options that will be passed to the testEnvironment
|
|
143
|
+
// testEnvironmentOptions: {},
|
|
144
|
+
|
|
145
|
+
// Adds a location field to test results
|
|
146
|
+
// testLocationInResults: false,
|
|
147
|
+
|
|
148
|
+
// The glob patterns Jest uses to detect test files
|
|
149
|
+
// testMatch: [
|
|
150
|
+
// "**/__tests__/**/*.[jt]s?(x)",
|
|
151
|
+
// "**/?(*.)+(spec|test).[tj]s?(x)"
|
|
152
|
+
// ],
|
|
153
|
+
|
|
154
|
+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
155
|
+
// testPathIgnorePatterns: [
|
|
156
|
+
// "\\\\node_modules\\\\"
|
|
157
|
+
// ],
|
|
158
|
+
|
|
159
|
+
// The regexp pattern or array of patterns that Jest uses to detect test files
|
|
160
|
+
// testRegex: [],
|
|
161
|
+
|
|
162
|
+
// This option allows the use of a custom results processor
|
|
163
|
+
// testResultsProcessor: undefined,
|
|
164
|
+
|
|
165
|
+
// This option allows use of a custom test runner
|
|
166
|
+
// testRunner: "jest-circus/runner",
|
|
167
|
+
|
|
168
|
+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
|
|
169
|
+
// testURL: "http://localhost",
|
|
170
|
+
|
|
171
|
+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
|
|
172
|
+
// timers: "real",
|
|
173
|
+
|
|
174
|
+
// A map from regular expressions to paths to transformers
|
|
175
|
+
// transform: undefined,
|
|
176
|
+
transform: {
|
|
177
|
+
"^.+\\.tsx?$": ["ts-jest", {
|
|
178
|
+
isolatedModules: true
|
|
179
|
+
}]
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
|
|
183
|
+
// transformIgnorePatterns: [
|
|
184
|
+
// "\\\\node_modules\\\\",
|
|
185
|
+
// "\\.pnp\\.[^\\\\]+$"
|
|
186
|
+
// ],
|
|
187
|
+
|
|
188
|
+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
|
|
189
|
+
// unmockedModulePathPatterns: undefined,
|
|
190
|
+
|
|
191
|
+
// Indicates whether each individual test should be reported during the run
|
|
192
|
+
verbose: true,
|
|
193
|
+
|
|
194
|
+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
195
|
+
// watchPathIgnorePatterns: [],
|
|
196
|
+
|
|
197
|
+
// Whether to use watchman for file crawling
|
|
198
|
+
// watchman: true,
|
|
199
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ts2famix",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Examples of the TypeScript compiler API usage",
|
|
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
|
+
"test": "jest --colors --silent",
|
|
11
|
+
"local": "sudo npm i -g && ts2famix",
|
|
12
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && npm install",
|
|
13
|
+
"doc": "typedoc && touch docs/.gitkeep",
|
|
14
|
+
"coverage": "jest --colors --silent --coverage --coverageDirectory=coverage",
|
|
15
|
+
"uml": "./src/generate_uml.sh"
|
|
16
|
+
},
|
|
17
|
+
"bin": {
|
|
18
|
+
"ts2famix": "dist/ts2famix-cli.js"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "",
|
|
22
|
+
"nodemonConfig": {
|
|
23
|
+
"ignore": [
|
|
24
|
+
"dist/*"
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jest": "^29.5.4",
|
|
30
|
+
"@types/node": "^20.6.0",
|
|
31
|
+
"@types/yargs": "^17.0.24",
|
|
32
|
+
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
33
|
+
"@typescript-eslint/parser": "^6.6.0",
|
|
34
|
+
"eslint": "^8.49.0",
|
|
35
|
+
"jest": "^29.6.4",
|
|
36
|
+
"tplant": "^3.1.2",
|
|
37
|
+
"ts-jest": "^29.1.1",
|
|
38
|
+
"ts-morph": "^19.0.0",
|
|
39
|
+
"typedoc": "^0.25.1",
|
|
40
|
+
"typescript": "^5.2.2"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"ts-node": "^10.9.1",
|
|
44
|
+
"tsutils": "^3.21.0",
|
|
45
|
+
"yargs": "^17.7.2"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/analyze.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { Project } from "ts-morph";
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { FamixRepository } from "./lib/famix/src/famix_repository";
|
|
4
|
+
import { FamixFunctions } from "./famix_functions/famix_functions";
|
|
5
|
+
import { ProcessFiles } from "./analyze_functions/processFiles";
|
|
6
|
+
import { ProcessAccesses } from "./analyze_functions/processAccesses";
|
|
7
|
+
import { ProcessInvocations } from "./analyze_functions/processInvocations";
|
|
8
|
+
import { ProcessInheritances } from "./analyze_functions/processInheritances";
|
|
9
|
+
import { ProcessImportClauses } from "./analyze_functions/processImportClauses";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This class is used to build a Famix model from a TypeScript source code
|
|
13
|
+
*/
|
|
14
|
+
export class Importer {
|
|
15
|
+
|
|
16
|
+
private project = new Project(); // The project containing the source files to analyze
|
|
17
|
+
private famixFunctions = new FamixFunctions(); // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
18
|
+
private processFiles = new ProcessFiles(this.famixFunctions); // ProcessFiles object, it contains all the functions needed to process the source files
|
|
19
|
+
private processAccesses = new ProcessAccesses(this.famixFunctions); // ProcessAccesses object, it contains all the functions needed to process the accesses
|
|
20
|
+
private processInvocations = new ProcessInvocations(this.famixFunctions); // ProcessInvocations object, it contains all the functions needed to process the invocations
|
|
21
|
+
private processInheritances = new ProcessInheritances(this.famixFunctions); // ProcessInheritances object, it contains all the functions needed to process the inheritances
|
|
22
|
+
private processImportClauses = new ProcessImportClauses(this.famixFunctions); // ProcessImportClauses object, it contains all the functions needed to process the import clauses
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Main method
|
|
26
|
+
* @param paths An array of paths to the source files to analyze
|
|
27
|
+
* @returns The Famix repository containing the Famix model
|
|
28
|
+
*/
|
|
29
|
+
public famixRepFromPaths(paths: Array<string>): FamixRepository {
|
|
30
|
+
let famixRep: FamixRepository;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
console.info(`famixRepFromPaths: paths: ${paths}`);
|
|
34
|
+
|
|
35
|
+
const sourceFiles = this.project.addSourceFilesAtPaths(paths);
|
|
36
|
+
this.processFiles.processFiles(sourceFiles);
|
|
37
|
+
|
|
38
|
+
const accesses = this.processFiles.getAccesses();
|
|
39
|
+
const methodsAndFunctionsWithId = this.processFiles.getMethodsAndFunctionsWithId();
|
|
40
|
+
const classes = this.processFiles.getClasses();
|
|
41
|
+
const interfaces = this.processFiles.getInterfaces();
|
|
42
|
+
const modules = this.processFiles.getModules();
|
|
43
|
+
const exports = this.processFiles.getExports();
|
|
44
|
+
|
|
45
|
+
this.processImportClauses.processImportClauses(modules, exports);
|
|
46
|
+
this.processAccesses.processAccesses(accesses);
|
|
47
|
+
this.processInvocations.processInvocations(methodsAndFunctionsWithId);
|
|
48
|
+
this.processInheritances.processInheritances(classes, interfaces);
|
|
49
|
+
|
|
50
|
+
famixRep = this.famixFunctions.getFamixRepository();
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
console.error(`> ERROR: got exception ${error}. Exiting...`);
|
|
54
|
+
console.error(error.message);
|
|
55
|
+
console.error(error.stack);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return famixRep;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Main method for tests
|
|
64
|
+
* @param filename The name of the file to analyze
|
|
65
|
+
* @param source A TypeScript source code
|
|
66
|
+
* @returns The Famix repository containing the Famix model
|
|
67
|
+
*/
|
|
68
|
+
public famixRepFromSource(filename: string, source: string): FamixRepository {
|
|
69
|
+
const filePath = `./test_src/${filename}.ts`;
|
|
70
|
+
|
|
71
|
+
fs.writeFileSync(filePath, source, 'utf-8');
|
|
72
|
+
|
|
73
|
+
const famixRep = this.famixRepFromPaths([filePath]);
|
|
74
|
+
|
|
75
|
+
return famixRep;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Main method for a ts-morph project
|
|
80
|
+
* @param project A ts-morph project
|
|
81
|
+
* @returns The Famix repository containing the Famix model
|
|
82
|
+
*/
|
|
83
|
+
public famixRepFromProject(project: Project): FamixRepository {
|
|
84
|
+
const sourceFileNames = project.getSourceFiles().map(f => f.getFilePath()) as Array<string>;
|
|
85
|
+
|
|
86
|
+
const famixRep = this.famixRepFromPaths(sourceFileNames);
|
|
87
|
+
|
|
88
|
+
return famixRep;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Identifier, ParameterDeclaration, VariableDeclaration, PropertyDeclaration, EnumMember } from "ts-morph";
|
|
2
|
+
import { FamixFunctions } from "../famix_functions/famix_functions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This class is used to build a Famix model for the accesses
|
|
6
|
+
*/
|
|
7
|
+
export class ProcessAccesses {
|
|
8
|
+
|
|
9
|
+
private famixFunctions: FamixFunctions; // FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Initializes the ProcessAccesses object
|
|
13
|
+
* @param famixFunctions FamixFunctions object, it contains all the functions needed to create Famix entities
|
|
14
|
+
*/
|
|
15
|
+
constructor(famixFunctions: FamixFunctions) {
|
|
16
|
+
this.famixFunctions = famixFunctions;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Builds a Famix model for the accesses on the parameters, variables, properties and enum members of the source files
|
|
21
|
+
* @param accesses A map of parameters, variables, properties and enum members with their id
|
|
22
|
+
*/
|
|
23
|
+
public processAccesses(accesses: Map<number, ParameterDeclaration | VariableDeclaration | PropertyDeclaration | EnumMember>): void {
|
|
24
|
+
console.info(`processAccesses: Creating accesses:`);
|
|
25
|
+
accesses.forEach((v, id) => {
|
|
26
|
+
console.info(`processAccesses: Accesses to ${v.getName()}`);
|
|
27
|
+
try {
|
|
28
|
+
const temp_nodes = v.findReferencesAsNodes() as Array<Identifier>;
|
|
29
|
+
temp_nodes.forEach(node => this.processNodeForAccesses(node, id));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(`> WARNING: got exception ${error}. Continuing...`);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Builds a Famix model for an access on a parameter, variable, property or enum member
|
|
38
|
+
* @param n A node
|
|
39
|
+
* @param id An id of a parameter, a variable, a property or an enum member
|
|
40
|
+
*/
|
|
41
|
+
private processNodeForAccesses(n: Identifier, id: number): void {
|
|
42
|
+
try {
|
|
43
|
+
this.famixFunctions.createFamixAccess(n, id);
|
|
44
|
+
|
|
45
|
+
console.info(`processNodeForAccesses: node: node, (${n.getType().getText()})`);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(`> WARNING: got exception ${error}. ScopeDeclaration invalid for ${n.getSymbol().getFullyQualifiedName()}. Continuing...`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|