Skip to content

Commit a6605df

Browse files
committed
Enrich Graph for Typescript with multiple projects and packages
1 parent c24a72c commit a6605df

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Set name property on Typescript project nodes
2+
3+
MATCH (project:TS:Project)-[:HAS_ROOT]->(root:Directory)
4+
WITH project
5+
,reverse(split(reverse(root.absoluteFileName), '/')[0]) AS projectName
6+
SET project.name = projectName
7+
RETURN count(*) AS numberOfNamesProjects
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Set name property on Typescript scan nodes
2+
3+
MATCH (typescriptScan:TS:Scan)
4+
WITH typescriptScan
5+
,replace(reverse(split(reverse(typescriptScan.fileName), '/')[0]), '.json', '') AS scanName
6+
SET typescriptScan.name = scanName
7+
RETURN count(*) AS numberOfNamesScans
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Link Typescript projects to npm packages
2+
3+
MATCH (npmPackage:NPM:Package)
4+
WITH npmPackage
5+
// Remove the first ("/npm-package-json/")" and the last part ("/package.json")
6+
// of the file name to get the actual relative path to the directory
7+
// that contains the package.json file
8+
,replace(
9+
replace(npmPackage.fileName, '/' + split(npmPackage.fileName, '/')[1], '')
10+
, '/package.json'
11+
, ''
12+
) AS relativeNpmPackageDirectory
13+
MATCH (project:TS:Project)-[:HAS_ROOT]->(projectRoot:Directory)
14+
WHERE projectRoot.absoluteFileName ENDS WITH relativeNpmPackageDirectory
15+
WITH npmPackage
16+
,relativeNpmPackageDirectory
17+
,collect(DISTINCT project) AS projects
18+
,collect(DISTINCT projectRoot) AS projectRoots
19+
// Assure that the found connection is unique and not ambiguous
20+
WHERE size(projects) = 1
21+
AND size(projectRoots) = 1
22+
UNWIND projects AS project
23+
// Create a HAS_NPM_PACKAGE relationship between the Typescript project and the npm package
24+
MERGE (project)-[:HAS_NPM_PACKAGE]->(npmPackage)
25+
// Set the "relativeFileDirectory" on the npm package to the relative directory
26+
// that contains the package.json file
27+
SET npmPackage.relativeFileDirectory = relativeNpmPackageDirectory
28+
RETURN count(*) AS numberOfCreatedNpmPackageRelationships
29+
// Detailed results for debugging
30+
//RETURN npmPackage.fileName AS npmPackageFileName
31+
// ,projectRoots[0].absoluteFileName AS projectRootDirectory
32+
// ,relativeNpmPackageDirectory

scripts/prepareAnalysis.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ execute_cypher "${CYPHER_DIR}/Create_Typescript_index_for_full_qualified_name.cy
5454
# Preparation - Enrich Graph for Typescript by adding "module" and "name" properties
5555
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_module_properties.cypher"
5656

57+
# Preparation - Enrich Graph for Typescript by adding a name properties
58+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_projects.cypher"
59+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_scan_nodes.cypher"
60+
5761
# Preparation - Enrich Graph for Typescript by adding relationships between Modules with the same globalFqn
5862
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_modules.cypher"
5963
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_declarations.cypher"
6064
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_DEPENDS_ON_relationship_to_resolved_modules.cypher"
6165

66+
# Preparation - Enrich Graph for Typescript by adding relationships between corresponding TS:Project and NPM:Package nodes
67+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Link_projects_to_npm_packages.cypher"
68+
6269
# Preparation - Add weights to Java Package DEPENDS_ON relationships
6370
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_for_Java_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
6471
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_to_Java_Package_DEPENDS_ON_Relationship.cypher"

0 commit comments

Comments
 (0)